-
Notifications
You must be signed in to change notification settings - Fork 21
97 lines (85 loc) · 3.23 KB
/
main.yml
File metadata and controls
97 lines (85 loc) · 3.23 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
# .github/workflows/main.yml (Java)
name: Release Java SDK
on:
push:
branches: [master]
paths:
- '.changelog/v*.md'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
server-id: central
server-username: MAVEN_CENTRAL_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE
- name: Extract Version
id: version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
- name: Build and Test
run: mvn clean verify -B
- name: Create Tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a ${{ steps.version.outputs.tag }} -m "Release ${{ steps.version.outputs.tag }}"
git push origin ${{ steps.version.outputs.tag }}
- name: Read Changelog
id: changelog
run: |
CHANGELOG_FILE=".changelog/${{ steps.version.outputs.tag }}.md"
if [ -f "$CHANGELOG_FILE" ]; then
delimiter="$(openssl rand -hex 8)"
echo "content<<$delimiter" >> $GITHUB_OUTPUT
cat "$CHANGELOG_FILE" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "$delimiter" >> $GITHUB_OUTPUT
else
echo "content=Release ${{ steps.version.outputs.tag }}" >> $GITHUB_OUTPUT
fi
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.tag }}
body: ${{ steps.changelog.outputs.content }}
- name: Check Maven Central Version
id: maven_check
run: |
VERSION="${{ steps.version.outputs.version }}"
GROUP_PATH="com/volcengine"
ARTIFACT_ID="volcengine-java-sdk"
POM_URL="https://repo.maven.apache.org/maven2/${GROUP_PATH}/${ARTIFACT_ID}/${VERSION}/${ARTIFACT_ID}-${VERSION}.pom"
CODE=$(curl -sS -o /dev/null -w "%{http_code}" "$POM_URL")
if [ "$CODE" = "200" ]; then
echo "publish_needed=false" >> $GITHUB_OUTPUT
echo "maven_version_exists=true" >> $GITHUB_OUTPUT
else
echo "publish_needed=true" >> $GITHUB_OUTPUT
echo "maven_version_exists=false" >> $GITHUB_OUTPUT
fi
- name: Publish to Maven Central
if: steps.maven_check.outputs.publish_needed == 'true'
run: |
mvn clean deploy -B -Ppublic -DskipTests \
-Dmaven.javadoc.failOnError=false \
-Dmaven.javadoc.quiet=true
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}