-
-
Notifications
You must be signed in to change notification settings - Fork 152
141 lines (122 loc) · 5.5 KB
/
snapshot.yml
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Publish Snapshot
env:
NEXT_BUILD_NUMBER: ${{ vars.NEXT_BUILD_NUMBER }}
BUILD_INITIAL_VALUE: 1
on:
push:
branches:
- dev
workflow_dispatch:
inputs:
logLevel:
description: 'Log Level'
required: false
default: 'warning'
jobs:
publish:
runs-on: ubuntu-latest
if: "!contains(github.event.commits[0].message, '[ci-skip]')"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
# https://github.com/granny/Pl3xMap/blob/1df593e5706444de28fc61855df5a7552afcd3c7/.github/workflows/build.yml#L26
- uses: actions/github-script@v6
name: Prepare build number if it doesn't exist
with:
debug: true
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo } = context.repo;
if (process.env.NEXT_BUILD_NUMBER === undefined || process.env.NEXT_BUILD_NUMBER === "") {
core.info(`Could not find a NEXT_BUILD_NUMBER env variable. Creating a new one with value ${process.env.BUILD_INITIAL_VALUE}.`);
const { status, data } = await github.request('POST /repos/{owner}/{repo}/actions/variables', {
owner: owner,
repo: repo,
name: "NEXT_BUILD_NUMBER",
value: process.env.BUILD_INITIAL_VALUE,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
}).catch(err => err.response);
//const { status, data } = await github.rest.actions.createRepoVariable(owner, repo, "NEXT_BUILD_NUMBER", process.env.BUILD_INITIAL_VALUE);
core.debug(JSON.stringify(data, null, 2));
if (data?.message != undefined) {
return core.setFailed(`Failed to update configuration variable NEXT_BUILD_NUMBER with new value of '${process.env.BUILD_INITIAL_VALUE}' for reason ${data.message}`);
}
return core.exportVariable("NEXT_BUILD_NUMBER", process.env.BUILD_INITIAL_VALUE);
} else if (process.env.NEXT_BUILD_NUMBER.split('.').length > 1 || Number.isNaN(Number.parseInt(process.env.NEXT_BUILD_NUMBER))) {
return core.setFailed(`NEXT_BUILD_NUMBER variable has invalid value "${process.env.NEXT_BUILD_NUMBER}", failing build.`);
}
return core.exportVariable("NEXT_BUILD_NUMBER", process.env.NEXT_BUILD_NUMBER);
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
check-latest: true
- name: Gradle Properties Import.
id: properties
shell: bash
run: cat gradle.properties >> $GITHUB_ENV
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Assemble
run:
./gradlew assemble --stacktrace
- name: Publish
env:
HANGAR_KEY: ${{ secrets.HANGAR_KEY }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
COMMIT_MESSAGE: ${{ join(github.event.commits.*.message, '<br>* ') }}
run: ./gradlew modrinth publishAllPublicationsToHangar --stacktrace
- name: Build Succeeded
uses: sarisia/actions-status-discord@v1
if: success()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
noprefix: true
nodetail: true
title: A new version of CrazyCrates is ready.
color: 0xE91E63
description: |
* <:hangar:1139326635313733652> https://hangar.papermc.io/CrazyCrew/CrazyCrates/versions/2.1-${{env.NEXT_BUILD_NUMBER}}
* <:modrinth:1115307870473420800> https://modrinth.com/plugin/crazycrates/version/2.1-${{env.NEXT_BUILD_NUMBER}}
- name: Build Failed
uses: sarisia/actions-status-discord@v1
if: ${{ failure() }}
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
noprefix: true
nodetail: true
title: The build didn't survive.
color: 0xff0000
description: |
Version 2.1 build ${{env.NEXT_BUILD_NUMBER}} has died.
Click [here](${{github.server_url}}/${{github.repository}}/actions/runs/${{ github.run_id }}) to view the run.
# https://github.com/granny/Pl3xMap/blob/1df593e5706444de28fc61855df5a7552afcd3c7/.github/workflows/build.yml#L95
- uses: actions/github-script@v6
name: Increment Build Number
if: success()
with:
debug: true
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo } = context.repo;
const value = '' + (${{ env.NEXT_BUILD_NUMBER }} + 1);
core.info(`attempting to update variable 'NEXT_BUILD_NUMBER' to '${value}'.`);
const { status, data } = await github.request('PATCH /repos/{owner}/{repo}/actions/variables/{name}', {
owner: owner,
repo: repo,
name: "NEXT_BUILD_NUMBER",
value: value,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
}).catch(err => err.response);
//const { data } = await github.rest.actions.updateRepoVariable(owner, repo, "NEXT_BUILD_NUMBER", value)
core.debug(JSON.stringify(data, null, 2));
if (data?.message != undefined) {
return core.setFailed(`Failed to update configuration variable NEXT_BUILD_NUMBER with new value of '${value}'`);
}