1+ name : Build and Deploy
2+
3+ on :
4+ push :
5+ branches :
6+ - develop # For snapshot builds
7+ - main # For release builds
8+ paths-ignore :
9+ - ' **.md'
10+ - ' .gitignore'
11+ - ' LICENSE'
12+ workflow_dispatch :
13+ inputs :
14+ channel :
15+ description : ' Release Channel'
16+ required : true
17+ default : ' snapshot'
18+ type : choice
19+ options :
20+ - snapshot
21+ - rc
22+ - release
23+ version :
24+ description : ' Version (only for release channel)'
25+ required : false
26+ type : string
27+
28+ jobs :
29+ build :
30+ runs-on : ubuntu-latest
31+ permissions :
32+ contents : write
33+ steps :
34+ - name : Checkout Code
35+ uses : actions/checkout@v4
36+ with :
37+ fetch-depth : 1
38+
39+ - name : Set up JDK 21
40+ uses : actions/setup-java@v4.7.0
41+ with :
42+ distribution : ' temurin'
43+ java-version : ' 21'
44+ cache : ' gradle'
45+
46+ - name : Set up Gradle
47+ uses : gradle/actions/setup-gradle@v4
48+ with :
49+ build-scan-publish : true
50+ build-scan-terms-of-use-url : ' https://gradle.com/help/legal-terms-of-use'
51+ build-scan-terms-of-use-agree : ' yes'
52+
53+ - name : Make Gradle Wrapper Executable
54+ run : chmod +x ./gradlew
55+
56+ - name : Determine Version and Channel
57+ id : version
58+ run : |
59+ # If triggered manually, use workflow input; otherwise, decide based on branch name
60+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
61+ CHANNEL="${{ github.event.inputs.channel }}"
62+ if [[ "$CHANNEL" == "release" && -n "${{ github.event.inputs.version }}" ]]; then
63+ VERSION="${{ github.event.inputs.version }}"
64+ fi
65+ elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
66+ CHANNEL="release"
67+ else
68+ CHANNEL="snapshot"
69+ fi
70+
71+ # Get the commit hash (short version)
72+ COMMIT_HASH=$(git rev-parse --short HEAD)
73+ echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV
74+
75+ # Read the base version from gradle.properties
76+ BASE_VERSION=$(grep '^baseVersion=' gradle.properties | cut -d'=' -f2)
77+ if [ "$CHANNEL" == "release" ]; then
78+ FINAL_VERSION="$BASE_VERSION"
79+ elif [ "$CHANNEL" == "rc" ]; then
80+ FINAL_VERSION="${BASE_VERSION}-rc.${COMMIT_HASH}"
81+ else
82+ FINAL_VERSION="${BASE_VERSION}-SNAPSHOT.${COMMIT_HASH}"
83+ fi
84+ echo "Determined version: $FINAL_VERSION"
85+
86+ # Set outputs for later steps
87+ echo "CHANNEL=$CHANNEL" >> $GITHUB_OUTPUT
88+ echo "VERSION=$FINAL_VERSION" >> $GITHUB_OUTPUT
89+
90+ - name : Build with Gradle
91+ run : |
92+ ./gradlew --parallel --build-cache clean build shadowJar \
93+ -PreleaseType=${{ steps.version.outputs.CHANNEL }} \
94+ -Pversion=${{ steps.version.outputs.VERSION }}
95+ env :
96+ COMMIT_HASH : ${{ env.COMMIT_HASH }}
97+
98+ - name : Publish to SimpleCloud Repository
99+ run : |
100+ if [[ "${{ steps.version.outputs.CHANNEL }}" == "release" ]]; then
101+ export GPG_TTY=$(tty)
102+ export GRADLE_OPTS="-Dorg.gradle.daemon=false"
103+ ./gradlew --no-daemon --parallel --build-cache publishMavenJavaPublicationToSimplecloudRepository \
104+ -PreleaseType=${{ steps.version.outputs.CHANNEL }} \
105+ -Pversion=${{ steps.version.outputs.VERSION }} \
106+ -Psigning.gnupg.keyName="${{ secrets.GPG_PRIVATE_KEY }}" \
107+ -Psigning.gnupg.passphrase="${{ secrets.GPG_PASSPHRASE }}"
108+ else
109+ ./gradlew --parallel --build-cache publishMavenJavaPublicationToSimplecloudRepository \
110+ -PreleaseType=${{ steps.version.outputs.CHANNEL }} \
111+ -Pversion=${{ steps.version.outputs.VERSION }}
112+ fi
113+ env :
114+ COMMIT_HASH : ${{ env.COMMIT_HASH }}
115+ SIMPLECLOUD_USERNAME : ${{ secrets.SIMPLECLOUD_USERNAME }}
116+ SIMPLECLOUD_PASSWORD : ${{ secrets.SIMPLECLOUD_PASSWORD }}
117+ ORG_GRADLE_PROJECT_signingKey : ${{ secrets.GPG_PRIVATE_KEY }}
118+ ORG_GRADLE_PROJECT_signingPassphrase : ${{ secrets.GPG_PASSPHRASE }}
119+
120+ - name : Prepare Artifacts
121+ run : |
122+ mkdir -p release-artifacts
123+ find . -type f -name "*.jar" -path "*/build/libs/*.jar" -not -path "./build/libs/*" \
124+ -not -name "*${{ steps.version.outputs.VERSION }}*" \
125+ -exec cp {} release-artifacts/ \;
126+
127+ - name : Update Channel Tag
128+ run : |
129+ git config user.name "GitHub Actions"
130+ git config user.email "actions@github.com"
131+ # Delete any existing channel tag locally and remotely
132+ git tag -d ${{ steps.version.outputs.CHANNEL }} || true
133+ git push origin :refs/tags/${{ steps.version.outputs.CHANNEL }} || true
134+ # Create a new tag at the current commit
135+ git tag -a ${{ steps.version.outputs.CHANNEL }} -m "Latest ${{ steps.version.outputs.CHANNEL }} build (v${{ steps.version.outputs.VERSION }})"
136+ git push origin ${{ steps.version.outputs.CHANNEL }} --force
137+
138+ - name : Create Channel Release
139+ uses : softprops/action-gh-release@v2
140+ with :
141+ name : " ${{ steps.version.outputs.CHANNEL }} channel"
142+ tag_name : ${{ steps.version.outputs.CHANNEL }}
143+ body : |
144+ Latest build in the ${{ steps.version.outputs.CHANNEL }} channel.
145+ Version: ${{ steps.version.outputs.VERSION }}
146+ Commit: ${{ github.sha }}
147+ prerelease : ${{ steps.version.outputs.CHANNEL != 'release' }}
148+ files : release-artifacts/*.jar
149+ env :
150+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments