-
-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (108 loc) · 5.24 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Automatically build, run unit and integration tests to detect errors early (CI provided by GitHub)
# including making pull requests review easier
# Human-readable name in the actions tab
name: Java CI
# Build on every push
# Wiki: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
# Allow manual dispatches
workflow_dispatch:
push:
branches:
- main
env:
# temurin is the successor of adoptjdk
JDK_DISTRIBUTION: 'temurin'
JAVA_VERSION: 17
JIB_VERSION: '0.10.0'
JIB_CLI_DOWNLOAD: "https://github.com/GoogleContainerTools/jib/releases/download/v${{ env.JIB_VERSION }}-cli/jib-jre-${{ env.JIB_VERSION }}.zip"
JIB_CHECKSUM: '1b48fd04e73573bbf902c85dc1019c38ea4968dc0dbac4eb0658a2650ca5a18e'
BASE_IMAGE: 'gcr.io/distroless/java17-debian11:nonroot'
# https://paper.readthedocs.io/en/latest/server/aikar-flags.html
AIKAR_FLAGS: '-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions
-XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M
-XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4
-XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90
-XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem
-XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs
-Daikars.new.flags=true'
JVM_FLAGS: '${{ env.AIKAR_FLAGS }} -server -XX:+ExitOnOutOfMemoryError'
jobs:
# job id
build_and_test:
# Environment image - always use the newest OS
runs-on: ubuntu-latest
# Run steps
steps:
- name: Checkout PaperBox
uses: actions/checkout@v3
# Pull changes
- name: Checkout Paper
uses: actions/checkout@v3
with:
repository: PaperMC/Paper
path: Paper
ref: master
# Cache only if the action is not run locally using act
# https://github.com/nektos/act/issues/285#issuecomment-987550101
- name: Set up JDK
uses: actions/setup-java@v3
if: ${{ !env.ACT }}
with:
distribution: ${{ env.JDK_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'
# Setup Java
- name: Set up JDK
uses: actions/setup-java@v3
if: ${{ env.ACT }}
with:
distribution: ${{ env.JDK_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Download JIB
run: |
echo "Downloading JIB-Tool from ""$JIB_CLI_DOWNLOAD"
wget --timestamping "$JIB_CLI_DOWNLOAD"
# Security: verify the checksum with a pre-downloaded value to detect arbitary artifact replacement
# or in transport modifications (MITM)
echo "$JIB_CHECKSUM" "jib-jre-$JIB_VERSION.zip" | sha256sum --check -
unzip -f "jib-jre-$JIB_VERSION.zip"
- name: Patch and build
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Actions"
# Change to the submodule folder
cd Paper
./gradlew applyPatches --exclude-task test --exclude-task check --stacktrace
# Create a full paperclip build
./gradlew createReobfPaperclipJar --exclude-task test --exclude-task check --stacktrace
# stop daemon if both tasks are finished
./gradlew --stop
- name: Extract vars
run: |
echo "Extracting versions"
# Extract the Minecraft version
echo "MC_VERSION=$(grep --perl-regexp --only-matching '(?<=mcVersion=)[0-9]\.[0-9]{2}(\.[0-9]{1,2})?' Paper/gradle.properties)" >> "$GITHUB_ENV"
# Extract the Paper source code revision
echo "REVISION=$(git -C Paper/ rev-parse --short HEAD | grep --extended-regexp "[0-9a-z]{4,56}")" >> "$GITHUB_ENV"
# Extract the latest digest to include it in the metadata for reproducibility
# Skopeo enables us to extract the data without pulling the image and having the correct
# platform/architecture select. JIB will later download the image and uses it's own caching system
echo "DIGEST=$(skopeo inspect docker://""$BASE_IMAGE"" | jq --raw-output '.Digest' | grep --extended-regexp "sha256:[a-z0-9]{64}")" >> "$GITHUB_ENV"
#echo "DIGEST=sha256:ec587f786019d4e5226f6f8c7485ca1ef5df6fd7f029ed1cffa8466c91d84fc4" >> $GITHUB_ENV
- name: Extract jar
run: |
# Create dummy directory for the permission bug in JIB
mkdir -p Paper/build/libs/temp/dummy
unzip Paper/build/libs/paper-paperclip*.jar -d Paper/build/libs/temp/clip
unzip Paper/build/libs/paper-bundler*.jar -d Paper/build/libs/temp/bundler
- name: Build Container
run: |
apt update && apt install gettext-base
export CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
# Create build file from an allow list of variables
# Note the variables are not expanded here - see ' instead of "
envsubst '$BASE_IMAGE:$DIGEST:$CREATED:$JVM_FLAGS:$REVISION:$MC_VERSION' < abstract-jib.yaml > jib.yaml
./jib-"$JIB_VERSION"/bin/jib build \
--additional-tags="$MC_VERSION" \
--target docker://ghcr.io/games647/paperclip