-
Notifications
You must be signed in to change notification settings - Fork 6
89 lines (77 loc) · 3.32 KB
/
publish-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
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Publish Release
on:
push:
branches: [ "master" ]
workflow_dispatch:
permissions:
contents: write
jobs:
release:
name: Setup Environment, Build JAR and Release Project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Upload JAR as artifact
uses: actions/upload-artifact@v3
with:
name: QSFindItemAddOn
path: target/QSFindItemAddOn-*.jar
- name: Automatic Release
uses: Fulminazzo/java-automatic-release@v2
with:
java-version: '17'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY_NAME: ${{ github.event.repository.name }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
- name: Get Release Info and Rename
id: get_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
release_info=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/latest")
release_id=$(echo "$release_info" | jq -r .id)
upload_url=$(echo "$release_info" | jq -r .upload_url)
version=$(echo "$release_info" | jq -r .tag_name)
# Extract full version from the release name (including RELEASE or SNAPSHOT)
full_version=$(echo "$release_info" | jq -r .name | sed 's/.*[[:space:]]//')
# Determine if it's a RELEASE or SNAPSHOT
if [[ $full_version == *-SNAPSHOT ]]; then
jar_suffix="-SNAPSHOT"
else
jar_suffix="-RELEASE"
fi
# Construct the full JAR name
jar_name="QSFindItemAddOn-${full_version}${jar_suffix}.jar"
# Update the release name to include RELEASE or SNAPSHOT
curl -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id" \
-d "{\"name\":\"$full_version\"}"
echo "upload_url=$upload_url" >> $GITHUB_OUTPUT
echo "version=$full_version" >> $GITHUB_OUTPUT
echo "jar_name=$jar_name" >> $GITHUB_OUTPUT
- name: Upload JAR to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./target/${{ steps.get_release.outputs.jar_name }}
asset_name: ${{ steps.get_release.outputs.jar_name }}
asset_content_type: application/java-archive