-
Notifications
You must be signed in to change notification settings - Fork 0
237 lines (199 loc) · 7.05 KB
/
publish.yml
File metadata and controls
237 lines (199 loc) · 7.05 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
name: Release and Publish
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to publish (leave empty to use pom.xml version)'
required: false
type: string
publish_maven:
description: 'Publish to Maven Central'
required: false
type: boolean
default: false
jobs:
build:
name: Build Artifacts
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Extract version from tag or pom.xml
id: version
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
elif [[ -n "${{ inputs.version }}" ]]; then
VERSION="${{ inputs.version }}"
else
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Update pom.xml version
run: mvn versions:set "-DnewVersion=${{ steps.version.outputs.version }}" -DgenerateBackupPoms=false
- name: Run tests
run: mvn -B test
- name: Build JAR
run: mvn -B package -DskipTests
- name: Rename shaded JAR
run: |
mv target/cfsolver-${{ steps.version.outputs.version }}.jar target/cfsolver-${{ steps.version.outputs.version }}-all.jar
- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: jar-artifacts
path: |
target/cfsolver-*-all.jar
retention-days: 7
build-exe:
name: Build Windows EXE
runs-on: windows-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 21 (GraalVM)
uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Update pom.xml version
run: mvn versions:set "-DnewVersion=${{ needs.build.outputs.version }}" -DgenerateBackupPoms=false
- name: Build JAR
run: mvn -B package -DskipTests
- name: Build native executable
run: |
native-image -jar target/cfsolver-${{ needs.build.outputs.version }}.jar `
--no-fallback `
--enable-url-protocols=http,https `
-H:+ReportExceptionStackTraces `
-o cfsolver
shell: pwsh
- name: Upload EXE artifact
uses: actions/upload-artifact@v4
with:
name: exe-artifacts
path: cfsolver.exe
retention-days: 7
if-no-files-found: error
release:
name: Create Release Draft
runs-on: ubuntu-latest
needs: [build, build-exe]
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
run: |
# Get the previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
echo "Getting changes since $PREV_TAG"
CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD)
else
echo "Getting all commits"
CHANGELOG=$(git log --pretty=format:"- %s (%h)")
fi
# Output for use in release
{
echo 'body<<EOF'
echo "## What's Changed"
echo ""
echo "$CHANGELOG"
echo EOF
} >> $GITHUB_OUTPUT
- name: Download JAR artifacts
uses: actions/download-artifact@v4
with:
name: jar-artifacts
path: artifacts
- name: Download EXE artifacts
uses: actions/download-artifact@v4
with:
name: exe-artifacts
path: artifacts
- name: List artifacts
run: ls -la artifacts/
- name: Create Release Draft
uses: softprops/action-gh-release@v2
with:
draft: true
name: CFSolver v${{ needs.build.outputs.version }}
body: ${{ steps.changelog.outputs.body }}
files: |
artifacts/cfsolver-*-all.jar
artifacts/cfsolver.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish to Maven Central
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.publish_maven == true)
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
cache: maven
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Generate GPG key
run: |
# Create GPG key configuration
cat > gpg-key-config <<EOF
%echo Generating GPG key
Key-Type: RSA
Key-Length: 4096
Subkey-Type: RSA
Subkey-Length: 4096
Name-Real: CloudFlyer CI
Name-Email: ci@cloudflyer.zetx.site
Expire-Date: 0
%no-protection
%commit
%echo Done
EOF
# Generate the key
gpg --batch --generate-key gpg-key-config
# Get the key ID
GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format=long | grep sec | head -1 | awk '{print $2}' | cut -d'/' -f2)
echo "GPG_KEY_ID=$GPG_KEY_ID" >> $GITHUB_ENV
# Upload public key to keyserver
gpg --keyserver keyserver.ubuntu.com --send-keys $GPG_KEY_ID || true
gpg --keyserver keys.openpgp.org --send-keys $GPG_KEY_ID || true
# Configure GPG for Maven
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent
- name: Update pom.xml version
run: mvn versions:set -DnewVersion=${{ needs.build.outputs.version }} -DgenerateBackupPoms=false
- name: Build and verify
run: mvn -B clean verify -DskipTests -Dgpg.keyname=${{ env.GPG_KEY_ID }}
- name: Publish to Maven Central
run: mvn -B deploy -DskipTests -Dgpg.keyname=${{ env.GPG_KEY_ID }}
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}