1- name : Trigger Jenkins Job
1+ name : Maven Deploy and Release
22
33on :
44 push :
55 branches :
6+ - master
67 - latest
78 paths :
89 - superstream-clients/pom.xml
910
1011jobs :
11- trigger-jenkins :
12- runs-on : self-hosted
12+ deploy :
13+ runs-on : ubuntu-latest
14+
15+ env :
16+ HOME : /home/runner
1317
1418 steps :
15- - name : Checkout code
16- uses : actions/checkout@v3
19+ - name : Determine deployment type
20+ id : deployment
21+ run : |
22+ # Automatic deployment based on branch
23+ if [ "${{ github.ref }}" == "refs/heads/latest" ]; then
24+ echo "type=production" >> $GITHUB_OUTPUT
25+ echo "branch=latest" >> $GITHUB_OUTPUT
26+ else
27+ echo "type=beta" >> $GITHUB_OUTPUT
28+ echo "branch=master" >> $GITHUB_OUTPUT
29+ fi
30+
31+ - name : Checkout
32+ uses : actions/checkout@v4
33+ with :
34+ fetch-depth : 0
35+
36+ - name : Set up JDK 17
37+ uses : actions/setup-java@v4
38+ with :
39+ java-version : ' 17'
40+ distribution : ' temurin'
41+ cache : ' maven'
1742
18- - name : Trigger Jenkins Job
43+ - name : Import GPG key
1944 env :
20- JENKINS_TOKEN : ${{ secrets.JENKINS_TOKEN }}
45+ GPG_PRIVATE_KEY : ${{ secrets.GPG_PRIVATE_KEY }}
46+ GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
2147 run : |
22- HTTP_STATUS=$(curl -w "%{http_code}" -o /tmp/jenkins_response.txt -f -X POST \
23- "https://jenkins.superstream.ai/job/DevOps/job/Superstream/job/SDK/job/superstream-clients-java/buildWithParameters?DEPLOYMENT_TYPE=production" \
24- --user "[email protected] :$JENKINS_TOKEN") 25-
26- if [ $? -ne 0 ] || [ "$HTTP_STATUS" -ne 201 ] && [ "$HTTP_STATUS" -ne 200 ]; then
27- echo "Jenkins trigger failed with HTTP status: $HTTP_STATUS"
28- cat /tmp/jenkins_response.txt
29- exit 1
30- fi
31-
32- echo "Successfully triggered Jenkins build (HTTP $HTTP_STATUS)"
48+ echo "$GPG_PRIVATE_KEY" | gpg --batch --yes --passphrase "$GPG_PASSPHRASE" --import
49+ echo "allow-loopback-pinentry" > ~/.gnupg/gpg-agent.conf
50+ gpg --list-secret-keys --keyid-format LONG
51+ echo "D64C041FB68170463BE78AD7C4E3F1A8A5F0A659:6:" | gpg --import-ownertrust
52+
53+ - name : Read Version from pom.xml
54+ id : version
55+ working-directory : superstream-clients
56+ run : |
57+ POM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
58+ echo "Original version from pom.xml: $POM_VERSION"
59+ echo "base=$POM_VERSION" >> $GITHUB_OUTPUT
60+
61+ - name : Create Maven Settings
62+ run : |
63+ mkdir -p ~/.m2
64+ echo "${{ secrets.MAVEN_SETTINGS }}" > ~/.m2/settings.xml
65+
66+ - name : Build and Deploy Beta
67+ if : steps.deployment.outputs.type == 'beta'
68+ working-directory : superstream-clients
69+ env :
70+ GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
71+ run : |
72+ mvn -B package --file pom.xml
73+ BETA_VERSION="${{ steps.version.outputs.base }}-beta"
74+ echo "Setting beta version: $BETA_VERSION"
75+ mvn versions:set -DnewVersion=$BETA_VERSION
76+ mvn -s ~/.m2/settings.xml deploy -DautoPublish=true -Dgpg.passphrase="$GPG_PASSPHRASE"
77+
78+ - name : Build and Deploy Production
79+ if : steps.deployment.outputs.type == 'production'
80+ working-directory : superstream-clients
81+ env :
82+ GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
83+ run : |
84+ mvn -B package --file pom.xml
85+ mvn -s ~/.m2/settings.xml deploy -DautoPublish=true -Dgpg.passphrase="$GPG_PASSPHRASE"
86+
87+ - name : Create GitHub Release
88+ if : steps.deployment.outputs.type == 'production'
89+ env :
90+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
91+ run : |
92+ VERSION="${{ steps.version.outputs.base }}"
93+ git config user.name "github-actions[bot]"
94+ git config user.email "github-actions[bot]@users.noreply.github.com"
95+ git checkout -b $VERSION
96+ git push origin $VERSION
97+ cd superstream-clients
98+ gh release create $VERSION target/superstream-clients-${VERSION}.jar --generate-notes
99+
100+ - name : Send Slack Notification - Success
101+ if : success() && steps.deployment.outputs.type == 'production'
102+ uses : slackapi/slack-github-action@v1
103+ with :
104+ payload : |
105+ {
106+ "text": "superstream-clients-java v${{ steps.version.outputs.base }} Production Release SUCCESSFUL"
107+ }
108+ env :
109+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
110+ SLACK_WEBHOOK_TYPE : INCOMING_WEBHOOK
111+
112+ - name : Send Slack Notification - Failure
113+ if : failure() && steps.deployment.outputs.type == 'production'
114+ uses : slackapi/slack-github-action@v1
115+ with :
116+ payload : |
117+ {
118+ "text": "superstream-clients-java v${{ steps.version.outputs.base }} Production Release FAILED"
119+ }
120+ env :
121+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
122+ SLACK_WEBHOOK_TYPE : INCOMING_WEBHOOK
123+
124+ - name : Send Slack Notification - Cancelled
125+ if : cancelled() && steps.deployment.outputs.type == 'production'
126+ uses : slackapi/slack-github-action@v1
127+ with :
128+ payload : |
129+ {
130+ "text": "superstream-clients-java v${{ steps.version.outputs.base }} Production Release CANCELLED"
131+ }
132+ env :
133+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
134+ SLACK_WEBHOOK_TYPE : INCOMING_WEBHOOK
135+
0 commit comments