release-1.0.0 #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created | |
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path | |
name: Maven Release | |
on: | |
pull_request: | |
types: [closed] | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
name: release | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Setup Go Environment (includes jq) | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.20' # 使用 Go 1.20 或者您需要的版本 | |
- name: Read Pull Request Title | |
id: pr-title | |
run: | | |
title=$(jq -r '.pull_request.title' $GITHUB_EVENT_PATH) | |
echo "Pull Request Title: $title" | |
echo "pr_title=$title" >> $GITHUB_OUTPUT | |
- name: Extract Version from POM | |
id: extract-version | |
run: | # 从 pom.xml 文件中提取版本号 | |
version=$(grep -oP '(?<=<version>)[^<]+' pom.xml | head -n 1) | |
echo "Version from POM: $version" | |
echo "pom_version=$version" >> $GITHUB_OUTPUT | |
- name: Validate Pull Request Title | |
run: | # 读取 Pull Request 标题和版本号 | |
title="${{ steps.pr-title.outputs.pr_title }}" | |
version="${{ steps.extract-version.outputs.pom_version }}" | |
# 验证 Pull Request 标题 | |
if [[ "$title" =~ ^release-$version$ ]]; then | |
echo "Pull Request title is valid." | |
else | |
echo "Pull Request title must be in the format 'release-$version'." | |
exit 1 | |
fi | |
- name: Set up Maven Central Repository | |
uses: actions/setup-java@v4 | |
with: # running setup-java again overwrites the settings.xml | |
java-version: '8' | |
distribution: 'temurin' | |
server-id: central # Value of the distributionManagement/repository/id field of the pom.xml | |
server-username: MAVEN_USERNAME # env variable for username in deploy | |
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy | |
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} # Value of the GPG private key to import | |
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase | |
- name: Publish to Apache Maven Central | |
run: mvn -B deploy -Pno-it-tests | |
env: | |
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |