-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (133 loc) · 4.41 KB
/
release.yml
File metadata and controls
146 lines (133 loc) · 4.41 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
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
142
143
144
145
146
name: Build and Release Addon
on:
push:
branches:
- main
paths:
- '**/*.java'
- 'webui/**'
- 'src/main/resources/**'
- 'build.gradle.kts'
- 'gradle.properties'
- 'gradle/libs.versions.toml'
- '.github/workflows/release.yml'
pull_request:
paths:
- '**/*.java'
- 'webui/**'
- 'src/main/resources/**'
- 'build.gradle.kts'
- 'gradle.properties'
- 'gradle/libs.versions.toml'
- '.github/workflows/release.yml'
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g. 1.2.3)'
required: true
type: string
release_name:
description: 'Optional release title override'
required: false
type: string
prerelease:
description: 'Mark the manual release as a prerelease'
required: true
default: false
type: boolean
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Determine release metadata
id: meta
if: github.event_name != 'pull_request'
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="v${{ github.event.inputs.version }}"
RELEASE_NAME="${{ github.event.inputs.release_name }}"
if [ -z "$RELEASE_NAME" ]; then
RELEASE_NAME="$TAG"
fi
if [ "${{ github.event.inputs.prerelease }}" = "true" ]; then
PRERELEASE="true"
else
PRERELEASE="false"
fi
else
TAG="snapshot"
RELEASE_NAME="Dev Build"
PRERELEASE="true"
fi
{
echo "tag_name=$TAG"
echo "release_name=$RELEASE_NAME"
echo "prerelease=$PRERELEASE"
} >> "$GITHUB_OUTPUT"
- name: Move snapshot tag to current commit
if: github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -f snapshot "$GITHUB_SHA"
git push --force "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" refs/tags/snapshot
- name: Make Gradle wrapper executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build --no-configuration-cache
- name: Remove old jar assets from target release
if: github.event_name != 'pull_request'
uses: actions/github-script@v7
with:
script: |
const tag = '${{ steps.meta.outputs.tag_name }}';
let release;
try {
release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag
});
} catch (error) {
if (error.status === 404) {
core.info(`Release for tag ${tag} does not exist yet; skipping cleanup.`);
return;
}
throw error;
}
const jarAssets = release.data.assets.filter(asset => asset.name.endsWith('.jar'));
for (const asset of jarAssets) {
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: asset.id
});
core.info(`Deleted old asset: ${asset.name}`);
}
- name: Publish Release
if: github.event_name != 'pull_request'
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.meta.outputs.tag_name }}
target_commitish: ${{ github.sha }}
name: ${{ steps.meta.outputs.release_name }}
prerelease: ${{ steps.meta.outputs.prerelease }}
files: build/libs/*.jar
fail_on_unmatched_files: true