Check for new daily release #3479
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check for new daily release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| daily: | |
| description: the daily build to use (fetches latest if not provided) | |
| type: number | |
| required: false | |
| schedule: | |
| - cron: '51 * * * *' # every hour at 51 minutes | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| check: | |
| runs-on: [self-hosted, linux] | |
| outputs: | |
| gtnh_version: ${{ steps.fetch-version.outputs.vers }} | |
| daily_version: ${{ steps.fetch-daily.outputs.vers }} | |
| should_build_daily: ${{ steps.should-build-daily.outputs.build_daily }} | |
| steps: | |
| - name: check if latest daily build failed | |
| if: ${{ github.event.inputs.daily == '' }} | |
| run: | | |
| curl -Lf -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/GTNewHorizons/DreamAssemblerXXL/actions/workflows/daily-modpack-build.yml/runs?per_page=1 \ | |
| | jq -r ".workflow_runs[0] | .conclusion" \ | |
| | [[ $(cat -) != "success" ]] \ | |
| && echo "latest daily build didn't succeed, exiting..." \ | |
| && exit 1 \ | |
| || echo "latest daily build succeeded" | |
| - id: fetch-version | |
| name: get latest gtnh version | |
| run: | | |
| curl -Lf -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/GTNewHorizons/GT-New-Horizons-Modpack/tags?per_page=100 \ | |
| | jq -r ".[] | .name" \ | |
| | grep -oP "^(\d+\.\d+\.\d+)" \ | |
| | head -n 1 \ | |
| | xargs -I{} \ | |
| echo "vers={}" >> "$GITHUB_OUTPUT" | |
| - id: fetch-daily | |
| name: get latest daily version number | |
| run: | | |
| [[ "${{ github.event.inputs.daily }}" != "" ]] \ | |
| && echo "vers=${{ github.event.inputs.daily }}" >> "$GITHUB_OUTPUT" \ | |
| || curl -Lf -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/GTNewHorizons/DreamAssemblerXXL/actions/workflows/daily-modpack-build.yml/runs?per_page=1 \ | |
| | jq -r ".workflow_runs[0] | .run_number" \ | |
| | xargs -I{} \ | |
| echo "vers={}" >> "$GITHUB_OUTPUT" | |
| - name: lowercase github.repository | |
| run: | | |
| echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | |
| - id: should-build-daily | |
| name: ensure that newest daily version isn't already built | |
| run: | | |
| if [[ "${{ github.event.inputs.daily }}" != "" ]]; then \ | |
| echo "build_daily=yes" >> "$GITHUB_OUTPUT" \ | |
| ; else \ | |
| curl -Lf -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/Ableytner/GTNH-server/actions/workflows/run-daily.yml/runs?per_page=100 \ | |
| | jq -r "first(.workflow_runs[] | select(.conclusion==\"failure\")) | .logs_url" \ | |
| | xargs -I{} \ | |
| curl -Lf -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" {} -o logs.zip \ | |
| && rm -rf /tmp/w-logs \ | |
| && unzip logs.zip -d /tmp/w-logs \ | |
| && find /tmp/w-logs/ -regex ".*[0-9]+_check.txt" \ | |
| | xargs -I {} cat "{}" \ | |
| | grep -oP "Found\ latest\ daily\ version\ (\d+)$" \ | |
| | tac -s' ' \ | |
| | head -1 \ | |
| | [[ "$(cat -)" == "${{ steps.fetch-daily.outputs.vers }}" ]] \ | |
| && echo "build_daily=no" >> "$GITHUB_OUTPUT" \ | |
| || docker manifest inspect "ghcr.io/${{ env.IMAGE_NAME }}:daily-${{ steps.fetch-daily.outputs.vers }}" > /dev/null 2>&1 \ | |
| && echo "build_daily=no" >> "$GITHUB_OUTPUT" \ | |
| || echo "build_daily=yes" >> "$GITHUB_OUTPUT" \ | |
| ; fi | |
| - name: print check summary | |
| run: | | |
| [[ ${{ steps.fetch-version.outputs.vers }} == "" ]] \ | |
| && echo "modpack version number is empty, exiting..." \ | |
| && exit 1 \ | |
| || echo "Found modpack version ${{ steps.fetch-version.outputs.vers }}" | |
| [[ ${{ steps.fetch-daily.outputs.vers }} == "" ]] \ | |
| && echo "daily version number is empty, exiting..." \ | |
| && exit 1 \ | |
| || echo "Found latest daily version ${{ steps.fetch-daily.outputs.vers }}" | |
| echo "should daily version be built: ${{ steps.should-build-daily.outputs.build_daily }}" | |
| build: | |
| needs: [check] | |
| if: ${{ needs.check.outputs.should_build_daily == 'yes' }} | |
| runs-on: [self-hosted, linux] | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: lowercase github.repository | |
| run: | | |
| echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | |
| - name: Docker meta | |
| uses: docker/metadata-action@v5 | |
| id: meta | |
| with: | |
| images: | | |
| ghcr.io/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=daily-${{ needs.check.outputs.daily_version }} | |
| labels: | | |
| org.opencontainers.image.authors=Ableytner | |
| - name: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: linux/amd64 | |
| pull: true | |
| load: true | |
| push: false | |
| tags: ${{ env.IMAGE_NAME }}:latest | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| GTNH_VERSION=${{ needs.check.outputs.gtnh_version }} | |
| GTNH_DAILY_BUILD=${{ needs.check.outputs.daily_version }} | |
| secrets: | | |
| github_token=${{ secrets.GITHUB_TOKEN }} | |
| - name: Export | |
| run: | | |
| docker save -o /tmp/image.tar ${{ env.IMAGE_NAME }}:latest | |
| - name: Cache docker image | |
| run: | | |
| curl -f -X POST -F "file=@/tmp/image.tar" -F "project_id=gtnh-server-daily-${{ needs.check.outputs.daily_version }}" -F "issue_id=1" http://192.168.0.11:25000/dump | |
| - name: Remove local image | |
| run: | | |
| docker image rm ${{ env.IMAGE_NAME }} | |
| test: | |
| needs: [check, build] | |
| runs-on: [self-hosted, linux] | |
| steps: | |
| - name: Set up Python | |
| uses: actions/setup-python@v3 | |
| with: | |
| python-version: "3.12" | |
| - name: Set up pipx | |
| # see https://stackoverflow.com/a/63153978/15436169 for more info | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get -y install pipx | |
| - name: install mcstatus | |
| run: | | |
| pipx install mcstatus==11.1.1 | |
| - name: lowercase github.repository | |
| run: | | |
| echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | |
| - name: Download cached docker image | |
| run: | | |
| curl -f -X GET http://192.168.0.11:25000/attachments/gtnh-server-daily-${{ needs.check.outputs.daily_version }}/1/image.tar -o /tmp/image.tar | |
| - name: Load image | |
| run: | | |
| docker load --input /tmp/image.tar | |
| - name: Create server container | |
| run: | | |
| docker create --name minecraft-gtnh3 -p 25565:25565 -p 8123:8123 -e MOTD='GT New Horizons MODPACK_VERSION-dailyDAILY_BUILD' -e EULA=TRUE -e WEBMAP=TRUE ${{ env.IMAGE_NAME }}:latest \ | |
| | xargs -I{} \ | |
| echo "CONTAINER_ID={}" >>${GITHUB_ENV} | |
| - name: Start server container | |
| run: | | |
| docker start ${{ env.CONTAINER_ID }} | |
| - name: Wait for server to start | |
| run: | | |
| declare -i c=0 | |
| while (( c < 30 )); do | |
| pipx run mcstatus==11.1.1 127.0.0.1 status > /dev/null 2>&1 && { | |
| break | |
| } || { | |
| echo "attempt $((${c} + 1)): couldn't connect" | |
| } | |
| (( c += 1 )) | |
| sleep 10 | |
| done | |
| if (( c >= 30 )); then | |
| echo "server wasn't reachable after $((${c} * 10)) seconds" | |
| exit 1 | |
| fi | |
| - name: Read MOTD | |
| run: | | |
| pipx run mcstatus==11.1.1 127.0.0.1 status \ | |
| | grep -oP "(?<=raw\=\').+(?=\', bedrock=False)" \ | |
| | xargs -I{} \ | |
| echo "MOTD=\"{}\"" >>${GITHUB_ENV} | |
| - name: Check MOTD GTNH version | |
| run: | | |
| echo ${{ env.MOTD }} \ | |
| | grep -oP "(?<=GT New Horizons ).+(?=-)" \ | |
| | [[ $(cat -) == ${{ needs.check.outputs.gtnh_version }} ]] | |
| - name: Check MOTD daily version | |
| run: | | |
| echo ${{ env.MOTD }} \ | |
| | grep -oP "(?<=-daily).+$" \ | |
| | [[ $(cat -) == ${{ needs.check.outputs.daily_version }} ]] | |
| - name: Ensure that webmap is reachable | |
| run: | | |
| curl -Lf --retry 3 --retry-delay 5 --retry-all-errors 127.0.0.1:8123 \ | |
| || exit 1 | |
| - name: Print out server container logs | |
| if: failure() | |
| run: | | |
| docker logs ${{ env.CONTAINER_ID }} | |
| - name: Stop and delete server container | |
| if: always() | |
| run: | | |
| docker rm -f ${{ env.CONTAINER_ID }} | |
| - name: Remove cached docker image on failure | |
| if: failure() | |
| run: | | |
| curl -f -X DELETE http://192.168.0.11:25000/attachments/gtnh-server-daily-${{ needs.check.outputs.daily_version }}/1/image.tar | |
| push: | |
| needs: [check, test] | |
| runs-on: [self-hosted, linux] | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: lowercase github.repository | |
| run: | | |
| echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | |
| - name: Download cached docker image | |
| run: | | |
| curl -f -X GET http://192.168.0.11:25000/attachments/gtnh-server-daily-${{ needs.check.outputs.daily_version }}/1/image.tar -o /tmp/image.tar | |
| - name: Load image | |
| run: | | |
| docker load --input /tmp/image.tar | |
| - name: Push daily | |
| run: | | |
| docker tag ${{ env.IMAGE_NAME }}:latest ghcr.io/${{ env.IMAGE_NAME }}:daily-${{ needs.check.outputs.daily_version }} | |
| docker push ghcr.io/${{ env.IMAGE_NAME }}:daily-${{ needs.check.outputs.daily_version }} | |
| docker tag ghcr.io/${{ env.IMAGE_NAME }}:daily-${{ needs.check.outputs.daily_version }} ghcr.io/${{ env.IMAGE_NAME }}:daily | |
| - name: Push daily to daily tag only if version was autodetected | |
| if: ${{ github.event.inputs.daily == '' }} | |
| run: | | |
| docker push ghcr.io/${{ env.IMAGE_NAME }}:daily | |
| - name: Remove local image | |
| if: always() | |
| run: | | |
| docker image rm ${{ env.IMAGE_NAME }} | |
| - name: Remove cached docker image | |
| if: always() | |
| run: | | |
| curl -f -X DELETE http://192.168.0.11:25000/attachments/gtnh-server-daily-${{ needs.check.outputs.daily_version }}/1/image.tar |