-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (170 loc) · 6.49 KB
/
release.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Release Workflow
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag for the release (format: v{x}.{y}.{z})'
required: true
default: ''
release_name:
description: 'Release name/title'
required: true
default: ''
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v3
# Set up Java environment
- name: Set up Java 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '21'
# Extract version from the provided tag
- name: Extract version from input tag
id: extract_version
run: |
TAG="${{ github.event.inputs.tag }}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Tag format must be v{x}.{y}.{z}"
exit 1
fi
VERSION="${TAG#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
echo "RELEASE_VERSION=${MAJOR}.${MINOR}.${PATCH}-1.21.3" >> $GITHUB_ENV
echo "NEXT_SNAPSHOT_VERSION=${MAJOR}.${MINOR}.$((PATCH + 1))-1.21.3-SNAPSHOT" >> $GITHUB_ENV
# Update paper-plugin.yml to release version
- name: Update version in paper-plugin.yml for release
run: |
FILE_PATH="${{ github.workspace }}/src/main/resources/paper-plugin.yml"
VERSION="${{ env.RELEASE_VERSION }}"
if [[ -f "$FILE_PATH" ]]; then
yq eval ".version = \"${VERSION}\"" -i "$FILE_PATH"
echo "Updated version in $FILE_PATH to $VERSION"
else
echo "Error: $FILE_PATH not found!"
exit 1
fi
env:
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
shell: bash
# Update pom.xml to release version
- name: Update version in pom.xml for release
run: |
mvn versions:set -DnewVersion="${{ env.RELEASE_VERSION }}"
mvn versions:commit
# Commit the updated pom.xml for release version
- name: Commit updated pom.xml
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "Set version to ${{ env.RELEASE_VERSION }}"
# Build the project
- name: Build with Maven
run: |
mvn install
mvn package
# Create a new tag for the release version
- name: Create tag for release
run: |
git tag "v${{ env.RELEASE_VERSION }}"
# Update paper-plugin.yml to next SNAPSHOT version
- name: Update version in paper-plugin.yml for snapshot
run: |
FILE_PATH="${{ github.workspace }}/src/main/resources/paper-plugin.yml"
VERSION="${{ env.NEXT_SNAPSHOT_VERSION }}"
if [[ -f "$FILE_PATH" ]]; then
yq eval ".version = \"${VERSION}\"" -i "$FILE_PATH"
echo "Updated version in $FILE_PATH to $VERSION"
else
echo "Error: $FILE_PATH not found!"
exit 1
fi
env:
NEXT_SNAPSHOT_VERSION: ${{ env.NEXT_SNAPSHOT_VERSION }}
shell: bash
# Update pom.xml to next SNAPSHOT version
- name: Update version in pom.xml to next SNAPSHOT
run: |
mvn versions:set -DnewVersion="${{ env.NEXT_SNAPSHOT_VERSION }}"
mvn versions:commit
# Commit updated pom.xml for next SNAPSHOT version
- name: Commit next SNAPSHOT version
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "Set version to ${{ env.NEXT_SNAPSHOT_VERSION }}"
# Create draft release
- name: Create draft release
id: create_draft
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const tagName = context.payload.inputs.tag;
const releaseDescription = context.payload.inputs.release_name;
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: tagName, // Title as {tag}
body: releaseDescription, // Description as {release_name}
draft: true
});
return release.data.id;
# Upload JAR files to the draft release
- name: Upload JAR files to draft release
uses: actions/github-script@v6
env:
RELEASE_ID: ${{ steps.create_draft.outputs.result }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const path = require('path');
const releaseId = process.env.RELEASE_ID;
// Directory containing JAR files
const targetDir = path.join(process.env.GITHUB_WORKSPACE, 'target');
// Upload each JAR file in the target directory
fs.readdirSync(targetDir).forEach(async file => {
if (file.endsWith('.jar')) {
const filePath = path.join(targetDir, file);
const stat = fs.statSync(filePath);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: file,
data: fs.readFileSync(filePath),
headers: {
'content-type': 'application/java-archive',
'content-length': stat.size
}
});
}
});
# Push changes back to the repository
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tags: true
# Publish the draft release
- name: Publish draft release
uses: actions/github-script@v6
env:
RELEASE_ID: ${{ steps.create_draft.outputs.result }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const releaseId = process.env.RELEASE_ID;
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
draft: false
});