-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (124 loc) · 4.85 KB
/
release.yml
File metadata and controls
138 lines (124 loc) · 4.85 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
name: Build and Deploy
on:
push:
branches:
- develop # For snapshot builds
- main # For release builds
paths-ignore:
- '**.md'
- '.gitignore'
- 'LICENSE'
workflow_dispatch:
inputs:
channel:
description: 'Release Channel'
required: true
default: 'snapshot'
type: choice
options:
- snapshot
- rc
- release
version:
description: 'Version (only for release channel)'
required: false
type: string
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up JDK 21
uses: actions/setup-java@v4.7.0
with:
distribution: 'temurin'
java-version: '21'
cache: 'gradle'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
build-scan-publish: true
build-scan-terms-of-use-url: 'https://gradle.com/help/legal-terms-of-use'
build-scan-terms-of-use-agree: 'yes'
- name: Make Gradle Wrapper Executable
run: chmod +x ./gradlew
- name: Determine Version and Channel
id: version
run: |
# If triggered manually, use workflow input; otherwise, decide based on branch name
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
CHANNEL="${{ github.event.inputs.channel }}"
if [[ "$CHANNEL" == "release" && -n "${{ github.event.inputs.version }}" ]]; then
VERSION="${{ github.event.inputs.version }}"
fi
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
CHANNEL="release"
else
CHANNEL="snapshot"
fi
# Get the commit hash (short version)
COMMIT_HASH=$(git rev-parse --short HEAD)
echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV
# Read the base version from gradle.properties
BASE_VERSION=$(grep '^baseVersion=' gradle.properties | cut -d'=' -f2)
if [ "$CHANNEL" == "release" ]; then
FINAL_VERSION="$BASE_VERSION"
elif [ "$CHANNEL" == "rc" ]; then
FINAL_VERSION="${BASE_VERSION}-rc.${COMMIT_HASH}"
else
FINAL_VERSION="${BASE_VERSION}-SNAPSHOT.${COMMIT_HASH}"
fi
echo "Determined version: $FINAL_VERSION"
# Set outputs for later steps
echo "CHANNEL=$CHANNEL" >> $GITHUB_OUTPUT
echo "VERSION=$FINAL_VERSION" >> $GITHUB_OUTPUT
- name: Build with Gradle
run: |
./gradlew --parallel --build-cache clean build shadowJar \
-PreleaseType=${{ steps.version.outputs.CHANNEL }} \
-Pversion=${{ steps.version.outputs.VERSION }}
env:
COMMIT_HASH: ${{ env.COMMIT_HASH }}
- name: Publish to SimpleCloud Repository
run: |
./gradlew --parallel --build-cache publishMavenJavaPublicationToSimplecloudRepository \
-PreleaseType=${{ steps.version.outputs.CHANNEL }} \
-Pversion=${{ steps.version.outputs.VERSION }}
env:
COMMIT_HASH: ${{ env.COMMIT_HASH }}
SIMPLECLOUD_USERNAME: ${{ secrets.SIMPLECLOUD_USERNAME }}
SIMPLECLOUD_PASSWORD: ${{ secrets.SIMPLECLOUD_PASSWORD }}
- name: Prepare Artifacts
run: |
mkdir -p release-artifacts
find . -type f -name "*.jar" -path "*/build/libs/*.jar" -not -path "./build/libs/*" \
-not -name "*${{ steps.version.outputs.VERSION }}*" \
-exec cp {} release-artifacts/ \;
- name: Update Channel Tag
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
# Delete any existing channel tag locally and remotely
git tag -d ${{ steps.version.outputs.CHANNEL }} || true
git push origin :refs/tags/${{ steps.version.outputs.CHANNEL }} || true
# Create a new tag at the current commit
git tag -a ${{ steps.version.outputs.CHANNEL }} -m "Latest ${{ steps.version.outputs.CHANNEL }} build (v${{ steps.version.outputs.VERSION }})"
git push origin ${{ steps.version.outputs.CHANNEL }} --force
- name: Create Channel Release
uses: softprops/action-gh-release@v2
with:
name: "${{ steps.version.outputs.CHANNEL }} channel"
tag_name: ${{ steps.version.outputs.CHANNEL }}
body: |
Latest build in the ${{ steps.version.outputs.CHANNEL }} channel.
Version: ${{ steps.version.outputs.VERSION }}
Commit: ${{ github.sha }}
prerelease: ${{ steps.version.outputs.CHANNEL != 'release' }}
files: release-artifacts/*.jar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}