-
-
Notifications
You must be signed in to change notification settings - Fork 93
108 lines (95 loc) · 4.61 KB
/
build_scheduled.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
name: 'build scheduled'
on:
workflow_dispatch:
schedule:
- cron: "0 */12 * * *" # every 12 hours
jobs:
get_all_versions:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.get_versions.outputs.versions }}
latest: ${{ steps.find_latest.outputs.latest }}
steps:
- name: get available versions
id: get_versions
run: |
curl -s -o versions.json "https://api.papermc.io/v2/projects/paper"
VERSIONS=$(jq -c '[.versions | nth(-3, -2, -1)]' versions.json)
echo "versions=$VERSIONS" >> "$GITHUB_OUTPUT"
- name: find latest
id: find_latest
run: |
for VERSION in $(echo '${{ steps.get_versions.outputs.versions }}' | jq -r '.[]');
do
echo "check for ${VERSION}"
curl -s -o "${VERSION}.json" "https://api.papermc.io/v2/projects/paper/versions/${VERSION}/builds"
HAS_STABLE=$(jq 'last(.builds[] | select(.channel=="default")).build' "${VERSION}.json")
if [[ "$HAS_STABLE" =~ ^[0-9]+$ ]]; then
LATEST="${VERSION}"
fi
done
echo "latest=$LATEST" >> "$GITHUB_OUTPUT"
- name: show output
run: |
echo "versions: ${{ steps.get_versions.outputs.versions }}"
echo "latest: ${{ steps.find_latest.outputs.latest }}"
build_for_version:
runs-on: ubuntu-latest
needs: get_all_versions
permissions: write-all
strategy:
matrix:
versions: ${{ fromJson(needs.get_all_versions.outputs.versions) }}
steps:
- name: get latest build
id: latest_build
run: |
BUILDS=$(curl -s -o builds.json https://api.papermc.io/v2/projects/paper/versions/${{ matrix.versions }}/builds)
BUILD_STABLE=$(jq 'last(.builds[] | select(.channel=="default")).build' builds.json)
BUILD_EXPERIMENTAL=$(jq 'last(.builds[] | select(.channel=="experimental")).build' builds.json)
echo "build_stable=$BUILD_STABLE" >> $GITHUB_OUTPUT
echo "build_experimental=$BUILD_EXPERIMENTAL" >> $GITHUB_OUTPUT
if [[ "$BUILD_STABLE" =~ ^[0-9]+$ ]]; then
BUILD_NUMBER=$BUILD_STABLE
BUILD_TYPE=stable
else
BUILD_NUMBER=$BUILD_EXPERIMENTAL
BUILD_TYPE=experimental
fi
echo build_number="${BUILD_NUMBER}" >> $GITHUB_OUTPUT
echo build_type="${BUILD_TYPE}" >> $GITHUB_OUTPUT
if [[ $BUILD_TYPE == "stable" && "${{ needs.get_all_versions.outputs.latest }}" == "${{ matrix.versions }}" ]]; then
echo is_latest="yes" >> $GITHUB_OUTPUT
else
echo is_latest="no" >> $GITHUB_OUTPUT
fi
if [[ $BUILD_TYPE == "experimental" && "${{ needs.get_all_versions.outputs.latest }}" -lt "${{ matrix.versions }}" ]]; then
echo is_experimental="yes" >> $GITHUB_OUTPUT
else
echo is_experimental="no" >> $GITHUB_OUTPUT
fi
- name: get self build
id: self_build
run: |
# DOCKER_IMAGE="ghcr.io/${{ github.repository_owner }}/docker-minecraft-papermc-server:${{ matrix.versions }}"
DOCKER_IMAGE="docker.io/marctv/minecraft-papermc-server:${{ matrix.versions }}"
docker pull $DOCKER_IMAGE || true
echo self_build=$(docker inspect $DOCKER_IMAGE --format '{{ index .Config.Labels "org.mojang.minecraft.papermc.build"}}' || true) >> $GITHUB_OUTPUT
- name: show output
if: always()
run: |
echo "latest: ${{ needs.get_all_versions.outputs.latest }}"
echo "version: ${{ matrix.versions }}"
echo "build_stable: ${{ steps.latest_build.outputs.build_stable }}"
echo "build_experimental: ${{ steps.latest_build.outputs.build_experimental }}"
echo "build_number: ${{ steps.latest_build.outputs.build_number }}"
echo "build_type: ${{ steps.latest_build.outputs.build_type }}"
echo "is_latest: ${{ steps.latest_build.outputs.is_latest }}"
echo "is_experimental: ${{ steps.latest_build.outputs.is_experimental }}"
echo "self_build: ${{ steps.self_build.outputs.self_build }}"
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
if: github.event_name == 'workflow_dispatch' || steps.latest_build.outputs.build_number != steps.self_build.outputs.self_build
with:
event-type: build_version
client-payload: '{"download_version": "${{ matrix.versions }}", "is_latest": "${{ steps.latest_build.outputs.is_latest }}", "is_experimental": "${{ steps.latest_build.outputs.is_experimental }}"}'