From e8b0fda147ca51b8e32e55c5c08e265b67e3ee1f Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Mon, 8 Apr 2024 11:57:15 -0700 Subject: [PATCH] Add workflow for auto-updating mache (#9) --- .../actions/update-mache-helper/action.yml | 54 +++++++ .../update-mache-helper/create_issue.sh | 12 ++ .../actions/update-mache-helper/run_cmd.sh | 5 + .github/workflows/update-mache.yml | 145 ++++++++++++++++++ 4 files changed, 216 insertions(+) create mode 100644 .github/actions/update-mache-helper/action.yml create mode 100755 .github/actions/update-mache-helper/create_issue.sh create mode 100755 .github/actions/update-mache-helper/run_cmd.sh create mode 100644 .github/workflows/update-mache.yml diff --git a/.github/actions/update-mache-helper/action.yml b/.github/actions/update-mache-helper/action.yml new file mode 100644 index 0000000..59dac7b --- /dev/null +++ b/.github/actions/update-mache-helper/action.yml @@ -0,0 +1,54 @@ +name: update-mache-helper +description: Internal action for auto-updating mache +inputs: + cmd: + description: The command to run. Captures the exitcode to determine success + required: true + version: + description: The version of Minecraft + required: true + job-name: + description: The name of the job to link in the failure issue + required: true + action: + description: The action to take + required: true + github-token: + description: Elevated github token + required: true + working-directory: + description: The working directory to run commands in + required: true + step: + description: The step hash to include in the link + required: true +runs: + using: composite + steps: + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + - uses: gradle/wrapper-validation-action@v2 + name: Validate Gradle Wrapper + - uses: gradle/actions/setup-gradle@v3 + name: Setup Gradle + - name: Run Command and Capture Exit Code + shell: bash + id: run-cmd + working-directory: ${{ inputs.working-directory }} + run: ${{ github.action_path }}/run_cmd.sh "${{ inputs.cmd }}" + - name: Get Job URL + uses: Tiryoh/gha-jobid-action@v1 + id: jobs + if: failure() && steps.run-cmd.outputs.exitcode != 0 + with: + github_token: ${{ inputs.github-token }} + job_name: ${{ inputs.job-name }} + - name: Create Failure Issue + if: failure() && steps.run-cmd.outputs.exitcode != 0 + shell: bash + working-directory: ${{ inputs.working-directory }} + run: ${{ github.action_path }}/create_issue.sh "${{ inputs.version }}" "${{ inputs.action }}" "${{ steps.jobs.outputs.html_url }}${{ inputs.step }}" + env: + GH_TOKEN: ${{ inputs.github-token }} diff --git a/.github/actions/update-mache-helper/create_issue.sh b/.github/actions/update-mache-helper/create_issue.sh new file mode 100755 index 0000000..73697a2 --- /dev/null +++ b/.github/actions/update-mache-helper/create_issue.sh @@ -0,0 +1,12 @@ +set +e +# $1 is version +# $2 is the "action" +# $3 is the job url +gh issue list --state open --label update --json title | jq '.[].title' | cut -c2- | rev | cut -c2- | cut -d' ' -f1 | rev | grep "$1" +if [[ "$?" -ne "0" ]]; then + set -e + gh issue create \ + --title "Failed to $2 for $1" \ + --body "Failed to $2 for $1. Please check the [logs]($3) for more information. The automatic updating will be paused until this is closed" \ + --label update +fi diff --git a/.github/actions/update-mache-helper/run_cmd.sh b/.github/actions/update-mache-helper/run_cmd.sh new file mode 100755 index 0000000..6a6c3ef --- /dev/null +++ b/.github/actions/update-mache-helper/run_cmd.sh @@ -0,0 +1,5 @@ +set +e +eval $1 +exitcode="$?" +echo "exitcode=$exitcode" >> $GITHUB_OUTPUT +exit "$exitcode" diff --git a/.github/workflows/update-mache.yml b/.github/workflows/update-mache.yml new file mode 100644 index 0000000..a35199f --- /dev/null +++ b/.github/workflows/update-mache.yml @@ -0,0 +1,145 @@ +name: Auto Update +on: + schedule: + - cron: '10 * * * *' + workflow_dispatch: + +concurrency: + group: ${{ github.repository_owner }}/mache-auto-update + +jobs: + verify: + name: Verify + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + repository: "${{ github.repository_owner }}/mache" + - name: Version Name + id: version + shell: bash + run: | + branch_name=$(git rev-parse --abbrev-ref HEAD) + version="${branch_name##*/}" + echo "folder_name=${version}" >> $GITHUB_OUTPUT + - name: Check Open Issue + id: test + shell: bash + run: | + set +e + gh issue list --state open --label update --json title | jq '.[].title' | cut -c2- | rev | cut -c2- | cut -d' ' -f1 | rev | grep "${{ steps.version.outputs.folder_name }}" + if [[ "$?" -eq "0" ]]; then + set -e + echo "::error::Will not update as an issue for the current version is still open!" && exit 1 + fi + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + outputs: + folder_name: ${{ steps.version.outputs.folder_name }} + project_name: ${{ steps.version.outputs.project_name }} + update: + name: Auto Update + runs-on: ubuntu-latest + needs: verify + steps: + - uses: actions/checkout@v4 + with: + repository: "${{ github.repository_owner }}/mache" + token: ${{ secrets.GH_TOKEN }} + - uses: actions/setup-java@v4 + name: Setup Java + with: + distribution: 'temurin' + java-version: 17 + - uses: gradle/wrapper-validation-action@v2 + name: Validate Gradle Wrapper + - uses: gradle/actions/setup-gradle@v3 + name: Setup Gradle + - name: Update Version + id: update + run: | + ./gradlew update --ci --no-daemon + branch_name=$(git rev-parse --abbrev-ref HEAD) + version="${branch_name##*/}" + formatted_version=$(echo "v${version}" | sed 's/\./_/g') + echo "new_folder_name=${version}" >> $GITHUB_OUTPUT + echo "new_project_name=${formatted_version}" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + outputs: + new_folder_name: ${{ steps.update.outputs.new_folder_name }} + new_project_name: ${{ steps.update.outputs.new_project_name }} + applyPatches: + name: Apply Patches + runs-on: ubuntu-latest + needs: update + steps: + - uses: actions/checkout@v4 + name: Checkout mache + with: + path: mache + repository: "${{ github.repository_owner }}/mache" + - uses: actions/checkout@v4 + name: Checkout sculptor + with: + path: sculptor + - name: Apply Patches + uses: ./sculptor/.github/actions/update-mache-helper + with: + cmd: ./gradlew ':versions:${{ needs.update.outputs.new_project_name }}:applyPatches' --no-daemon + version: ${{ needs.update.outputs.new_folder_name }} + job-name: "Apply Patches" + action: "apply patches" + github-token: ${{ secrets.GH_TOKEN }} + working-directory: mache + step: "#step:4:1" + - name: Tar sources + working-directory: mache + run: tar --exclude '*/.git*' -cf sources.tar versions/${{ needs.update.outputs.new_folder_name }}/src/ + - uses: actions/upload-artifact@v4 + name: Archive patched sources + with: + name: patched-sources + path: mache/sources.tar + if-no-files-found: error + retention-days: 1 + build: + name: Build + runs-on: ubuntu-latest + needs: [ verify, update, applyPatches ] + steps: + - uses: actions/checkout@v4 + name: Checkout mache + with: + path: mache + repository: "${{ github.repository_owner }}/mache" + - uses: actions/checkout@v4 + name: Checkout sculptor + with: + path: sculptor + - uses: actions/download-artifact@v4 + with: + name: patched-sources + path: mache/sources + - name: Extract sources + working-directory: mache + run: tar -xf sources/sources.tar versions/${{ needs.update.outputs.new_folder_name }}/src/ && rm -r sources/ + - name: Build + uses: ./sculptor/.github/actions/update-mache-helper + with: + cmd: ./gradlew ':versions:${{ needs.update.outputs.new_project_name }}:build' --no-daemon + version: ${{ needs.update.outputs.new_folder_name }} + job-name: Build + action: "build" + github-token: ${{ secrets.GH_TOKEN }} + working-directory: mache + step: "#step:6:1" + cleanup: + name: Cleanup + runs-on: ubuntu-latest + needs: [ verify, update, applyPatches, build ] + if: always() + steps: + - uses: geekyeggo/delete-artifact@v5 + with: + name: patched-sources