Auto Update #4551
This file contains 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: 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: | |
- name: Get latest version | |
shell: bash | |
id: latest | |
run: | | |
versions=`curl -s https://piston-meta.mojang.com/mc/game/version_manifest_v2.json | jq -r '.versions[:-472][] | {type, id} | join("/")' | tr '\n' ' '` | |
branches=`gh api --paginate "/repos/$GITHUB_REPOSITORY_OWNER/mache/branches" --jq '.[].name' | grep -e 'release/' -e 'snapshot/'` | |
new_version="" | |
latest_version="" | |
for v in $versions; do | |
type=`echo $v | cut -d'/' -f1` | |
name=`echo $v | cut -d'/' -f2-` | |
set +e | |
echo $branches | tr ' ' '\n' | grep -qx "$type/$name" | |
if [[ "$?" -eq "0" ]]; then | |
set -e | |
latest_version=$v | |
break | |
else | |
set -e | |
new_version=$v | |
fi | |
done | |
if [[ -z $new_version ]]; then | |
echo "::notice::Latest version already exists as a branch" | |
else | |
echo "latest_version=$latest_version" >> $GITHUB_OUTPUT | |
echo "::notice::Will try to update from $latest_version to $new_version" | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/checkout@v4 | |
if: steps.latest.outputs.latest_version | |
with: | |
repository: "${{ github.repository_owner }}/mache" | |
ref: ${{ steps.latest.outputs.latest_version }} | |
- name: Version Name | |
if: steps.latest.outputs.latest_version | |
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 | |
if: steps.latest.outputs.latest_version | |
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 "::notice::Will not update as an issue for the current version is still open!" | |
echo "will_try_update=false" >> $GITHUB_OUTPUT | |
else | |
set -e | |
echo "will_try_update=true" >> $GITHUB_OUTPUT | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
outputs: | |
latest_version: ${{ steps.latest.outputs.latest_version }} | |
folder_name: ${{ steps.version.outputs.folder_name }} | |
project_name: ${{ steps.version.outputs.project_name }} | |
will_try_update: ${{ steps.test.outputs.will_try_update }} | |
update: | |
name: Auto Update | |
if: ${{ needs.verify.outputs.will_try_update == 'true' }} | |
runs-on: ubuntu-latest | |
needs: verify | |
steps: | |
- uses: actions/create-github-app-token@v1 | |
name: Generate Token | |
id: app-token | |
with: | |
app-id: ${{ secrets.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
owner: ${{ github.repository_owner }} | |
repositories: "mache" | |
- uses: actions/checkout@v4 | |
with: | |
repository: "${{ github.repository_owner }}/mache" | |
token: ${{ steps.app-token.outputs.token }} | |
ref: ${{ needs.verify.outputs.latest_version }} | |
- uses: actions/setup-java@v4 | |
name: Setup Java | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
- uses: gradle/actions/wrapper-validation@v3 | |
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) | |
echo "new_branch_name=${branch_name}" >> $GITHUB_OUTPUT | |
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: ${{ steps.app-token.outputs.token }} | |
outputs: | |
new_folder_name: ${{ steps.update.outputs.new_folder_name }} | |
new_project_name: ${{ steps.update.outputs.new_project_name }} | |
new_branch_name: ${{ steps.update.outputs.new_branch_name }} | |
applyPatches: | |
name: Apply Patches | |
if: ${{ needs.verify.outputs.will_try_update == 'true' }} | |
runs-on: ubuntu-latest | |
needs: update | |
steps: | |
- uses: actions/create-github-app-token@v1 | |
name: Generate Token | |
id: app-token | |
with: | |
app-id: ${{ secrets.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
owner: ${{ github.repository_owner }} | |
repositories: "sculptor,mache" | |
- uses: actions/checkout@v4 | |
name: Checkout mache | |
with: | |
path: mache | |
repository: "${{ github.repository_owner }}/mache" | |
ref: ${{ needs.update.outputs.new_branch_name }} | |
- 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: ${{ steps.app-token.outputs.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 | |
if: ${{ needs.verify.outputs.will_try_update == 'true' }} | |
runs-on: ubuntu-latest | |
needs: [ verify, update, applyPatches ] | |
steps: | |
- uses: actions/create-github-app-token@v1 | |
name: Generate Token | |
id: app-token | |
with: | |
app-id: ${{ secrets.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
owner: ${{ github.repository_owner }} | |
repositories: "sculptor,mache" | |
- uses: actions/checkout@v4 | |
name: Checkout mache | |
with: | |
path: mache | |
repository: "${{ github.repository_owner }}/mache" | |
ref: ${{ needs.update.outputs.new_branch_name }} | |
- 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: ${{ steps.app-token.outputs.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 |