-
-
Notifications
You must be signed in to change notification settings - Fork 14
93 lines (85 loc) · 3.59 KB
/
check-for-updates.yml
File metadata and controls
93 lines (85 loc) · 3.59 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
name: Check For New Minecraft Version
on:
# This is triggered by n8n after a new Minecraft version has been detected
workflow_dispatch:
inputs:
publish:
description: 'Auto Publish'
required: false
default: true
type: boolean
concurrency:
group: check-for-updates
permissions:
actions: write # Needed to trigger the update workflow
jobs:
# This job will run a Gradle task to check for a new version
check:
name: Check for new versions
runs-on: ubuntu-latest
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@v5
# This job will create outputs:
# - release_type ('special' for anything that's not mainline)
# - latest_version
# - current_version
- id: check_for_update
name: Check for Minecraft Updates
run: ./gradlew :checkForMinecraftUpdate
- id: postprocess
name: Post-Process Update Variables
uses: actions/github-script@v8
env:
LATEST_VERSION: ${{ steps.check_for_update.outputs.latest_version }}
CURRENT_VERSION: ${{ steps.check_for_update.outputs.current_version }}
RELEASE_TYPE: ${{ steps.check_for_update.outputs.release_type }}
with:
script: |
const fs = require('fs');
const currentVersion = process.env.CURRENT_VERSION;
const latestVersion = process.env.LATEST_VERSION;
const releaseType = process.env.RELEASE_TYPE;
if (currentVersion === latestVersion) {
console.log('No new version has been released.');
return;
}
fs.appendFileSync(process.env.GITHUB_OUTPUT, `new_version=${latestVersion}\n`, 'utf8');
// if we're on the default branch, create a new branch for special releases
// otherwise just stay on the same branch.
const defaultRef = 'refs/heads/' + context.payload.repository.default_branch;
const currentRef = context.ref;
console.log('Default ref: %s. Current ref: %s', defaultRef, currentRef);
const isDefaultRef = currentRef === defaultRef;
if (isDefaultRef && releaseType === 'special') {
console.log('Using new branch for special release found on default branch: %s', releaseType);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `new_branch=${releaseType}/${latestVersion}\n`, 'utf8');
}
- name: Trigger Update Workflow
if: ${{ steps.postprocess.outputs.new_version }}
uses: actions/github-script@v8
# We need to use environment variables here to avoid untrusted input injection into the javascript code below.
env:
COMMIT_REF: ${{ github.ref }}
NEW_VERSION: ${{ steps.postprocess.outputs.new_version }}
NEW_BRANCH: ${{ steps.postprocess.outputs.new_branch }}
PUBLISH: ${{ inputs.publish }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'update.yml',
ref: process.env.COMMIT_REF,
inputs: {
'new_version': process.env.NEW_VERSION,
'new_branch': process.env.NEW_BRANCH,
'publish': process.env.PUBLISH,
}
});