-
-
Notifications
You must be signed in to change notification settings - Fork 14
114 lines (109 loc) · 3.8 KB
/
update.yml
File metadata and controls
114 lines (109 loc) · 3.8 KB
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
109
110
111
112
113
114
# This is a basic workflow that is manually triggered
name: Update
run-name: ${{ inputs.new_version && format('Update to {0}', inputs.new_version) || (inputs.update_tools && 'Update Tools' || 'Update') }}
permissions:
contents: write
actions: write # Needed to trigger publish workflow
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_call:
inputs:
new_branch:
description: 'New Branch'
required: false
type: string
new_version:
description: 'New Minecraft Version'
required: false
type: string
update_tools:
default: true
type: boolean
publish:
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
new_branch:
description: 'New Branch'
required: false
new_version:
description: 'New Minecraft Version'
required: false
update_tools:
description: 'Update Tools to Latest Versions'
required: false
default: true
type: boolean
publish:
description: 'Publish'
required: false
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
update:
name: Update
runs-on: ubuntu-latest
# We are using environment variables here since that lets the shell take care of escaping them as CLI params.
env:
NEW_BRANCH: ${{ inputs.new_branch }}
NEW_VERSION: ${{ inputs.new_version }}
steps:
- uses: actions/checkout@v4
- name: Setup Java 21
uses: neoforged/actions/setup-java@main
with:
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Create new Branch
if: ${{ inputs.new_branch }}
run: git checkout -b "$NEW_BRANCH" || git checkout -B ${{ inputs.new_branch }} HEAD
- name: Update Tools
if: ${{ inputs.update_tools }}
run: ./gradlew updateTools
- name: Update Minecraft Version
if: ${{ inputs.new_version }}
run: ./gradlew -- updateMinecraft "--version=$NEW_VERSION"
- name: Update Patches
run: ./gradlew createPatchWorkspaceForUpdate && ./gradlew createPatches
- name: Commit Changes
# See https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token
id: commit-changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "$COMMIT_MESSAGE"
echo "changed=true" >> $GITHUB_OUTPUT
fi
env:
COMMIT_MESSAGE: ${{ inputs.new_version && format('Update to {0}', inputs.new_version) || (inputs.update_tools && 'Update Tools' || 'Update') }}
- name: Push Changes
if: steps.commit-changes.outputs.changed
run: git push -u origin HEAD
- name: Trigger Publish Workflow
if: inputs.publish && steps.commit-changes.outputs.changed
uses: actions/github-script@v8
# We need to use environment variables here to avoid untrusted input injection into the javascript code below.
env:
BRANCH_REF: ${{ inputs.new_branch || github.ref_name }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'publish.yml',
ref: process.env.BRANCH_REF,
inputs: {
release: 'true'
}
});