Skip to content

Commit 9434759

Browse files
committed
Add CI
1 parent 0a1bbf0 commit 9434759

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Caches Gradle dependencies and wrappers
14+
uses: actions/cache@v2
15+
with:
16+
path: |
17+
~/.gradle/caches/modules-2
18+
~/.gradle/wrapper/dists
19+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts', '**/gradle.properties', '**/gradle/wrapper/gradle-wrapper.properties') }}
20+
restore-keys: |
21+
${{ runner.os }}-gradle-
22+
23+
- name: Run cibuild script
24+
id: exec
25+
run: ./scripts/cibuild
26+
27+
- name: Cleanup Gradle Cache
28+
run: |
29+
sudo rm -f ~/.gradle/caches/modules-2/modules-2.lock
30+
sudo rm -f ~/.gradle/caches/modules-2/gc.properties
31+
32+
# TODO:
33+
# - name: Upload the built artifact
34+
# uses: actions/upload-artifact@v2
35+
# with:
36+
# name: ${{ steps.exec.outputs.jar }}
37+
# path: build/libs/${{ steps.exec.outputs.jar }}
38+
# if-no-files-found: error

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM eclipse-temurin:17.0.2_8-jdk-focal
2+
3+
# need to install git for paper plugin
4+
RUN apt update -y; \
5+
apt install git -y; \
6+
git config --global user.email "[email protected]"; \
7+
git config --global user.name "Continuous Integration"

docker-compose.ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '2.4'
2+
3+
services:
4+
gradle:
5+
build:
6+
context: .
7+
dockerfile: ./Dockerfile
8+
container_name: jdk-slim-git
9+
environment:
10+
- CI=${CI:-}
11+
volumes:
12+
# gradle caches
13+
- ~/.gradle/caches/modules-2:/root/.gradle/caches/modules-2:z
14+
- ~/.gradle/wrapper/dists:/root/.gradle/wrapper/dists:z
15+
# exclude these from workdir mount
16+
- /opt/build/PaperX-API/
17+
- /opt/build/PaperX-Server/
18+
# only allow reads to the git repo
19+
- .git/:/opt/build/.git/:ro
20+
# paperweight cache contains files that save the absolute path,
21+
# so we create a special volume to cache this directory
22+
- paperweight_cache:/opt/build/.gradle/caches/paperweight/
23+
# mount working directory
24+
- ./:/opt/build:Z
25+
working_dir: /opt/build
26+
# these two gradle tasks must be run independently, otherwise it will fail
27+
command: bash -c 'set -x
28+
&& ./gradlew --no-daemon applyPatches --stacktrace
29+
&& ./gradlew --no-daemon createReobfPaperclipJar --stacktrace'
30+
31+
volumes:
32+
paperweight_cache:

scripts/cibuild

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [[ -n "${DEBUG_MODE}" ]]; then
6+
set -x
7+
fi
8+
9+
function usage() {
10+
echo -n \
11+
"Usage: $(basename "$0")
12+
Build application for staging or a release.
13+
"
14+
}
15+
16+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
17+
if [[ "${1:-}" == "--help" ]]; then
18+
usage
19+
else
20+
# if mounting the hosts cache folder, gradle inside the container will try and
21+
# acquire a file lock that the host machine may already be holding. this will
22+
# result in the container hanging indefinitely. stopping any existing daemons
23+
# on the host is the simplest way to 'solve' this issue
24+
if command -v java &>/dev/null; then
25+
./gradlew --stop
26+
fi
27+
28+
chmod +x ./gradlew
29+
30+
CI="${CI:-}" docker-compose -f docker-compose.ci.yml \
31+
run --rm gradle
32+
fi
33+
fi

0 commit comments

Comments
 (0)