Skip to content

Commit

Permalink
Add workflow for auto-updating mache (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker authored Apr 8, 2024
1 parent 587470c commit e8b0fda
Showing 4 changed files with 216 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/actions/update-mache-helper/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
12 changes: 12 additions & 0 deletions .github/actions/update-mache-helper/create_issue.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .github/actions/update-mache-helper/run_cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set +e
eval $1
exitcode="$?"
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
exit "$exitcode"
145 changes: 145 additions & 0 deletions .github/workflows/update-mache.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e8b0fda

Please sign in to comment.