Skip to content

Commit

Permalink
release-1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
liuziyuan committed Sep 12, 2024
1 parent a2d52c3 commit cb3c028
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 120 deletions.
29 changes: 16 additions & 13 deletions .github/workflows/maven-build.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# separate terms of service, privacy policy, and support
# documentation.

name: Maven Build
name: Build

on:
push:
Expand All @@ -29,19 +29,22 @@ on:
- '*.adoc'
- '*.txt'
- '.all-contributorsrc'

jobs:
build:

runs-on: ubuntu-latest
release-name-check:
uses: ./.github/workflows/pre-release.yml

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B clean package --file pom.xml
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B clean package
105 changes: 0 additions & 105 deletions .github/workflows/maven-publish.yml

This file was deleted.

109 changes: 109 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Check PR Name Enable Release

on:
workflow_call:
outputs:
release_name_check:
value: ${{ jobs.pre-release-check.outputs.release_name_check }}


jobs:
pre-release-check:
runs-on: ubuntu-latest
name: check pull request is release
outputs:
release_name_check: ${{ steps.check.outputs.release_name_check }}
steps:
- id: check-release-name
name: Check Release Name
run: |
pr_title=$(cat $GITHUB_EVENT_PATH | jq -r '.pull_request.title')
echo "PR Title: $pr_title"
# 转换为小写
pr_title_lower=$(echo "$pr_title" | tr '[:upper:]' '[:lower:]')
echo "PR Title (Lowercase): $pr_title_lower"
# 判断是否以 'release-' 开头
if [[ $pr_title_lower == release-* ]]; then
echo "Title starts with 'release-' (case-insensitive)"
need_release=true
else
echo "Title does not start with 'release-' (case-insensitive)"
need_release=false
fi
echo "need_release=$need_release" >> $GITHUB_OUTPUT
- name: Checkout Repository
uses: actions/checkout@v4

- name: Read Pull Request Info
id: pr-info
if: ${{ steps.check-release-name.outputs.need_release == 'true' }}
run: |
title=$(cat $GITHUB_EVENT_PATH | jq -r '.pull_request.title')
echo "Pull Request Title: $title"
echo "title=$title" >> $GITHUB_OUTPUT
body=$(cat $GITHUB_EVENT_PATH | jq -r '.pull_request.body')
echo "PR Body: $body"
echo "body<<EOF"$'\n'"$body"$'\n'EOF >> "$GITHUB_OUTPUT"
- name: Extract info from pom.xml
id: extract-info
if: ${{ steps.check-release-name.outputs.need_release == 'true' }}
run: |
groupId=$(mvn help:evaluate -Dexpression=project.groupId -q -DforceStdout)
artifactId=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "Pom GroupId: $groupId"
echo "Pom ArtifactId: $artifactId"
echo "Pom Version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
echo "artifactId=$artifactId" >> $GITHUB_OUTPUT
echo "groupId=$groupId" >> $GITHUB_OUTPUT
- name: Check Maven Central Repository & Validate Pull Request Title
id: check
if: ${{ steps.check-release-name.outputs.need_release == 'true' }}
run: |
version="${{ steps.extract-info.outputs.version }}"
groupId="${{ steps.extract-info.outputs.groupId }}"
artifactId="${{ steps.extract-info.outputs.artifactId }}"
URL=https://repo1.maven.org/maven2/$(echo $groupId | tr . /)/${artifactId}/maven-metadata.xml
echo $URL
# 检查 URL 是否存在
RESPONSE_CODE=$(curl -sSL -o /dev/null -w "%{http_code}" "$URL")
echo $RESPONSE_CODE
if [ "$RESPONSE_CODE" == "200" ]; then
# 文件存在,继续检查版本
RESPONSE=$(curl -sSL "$URL")
if echo "$RESPONSE" | grep "<version>$version</version>" > /dev/null; then
echo "Version $version exists in Maven Central."
echo "release_name_check=false" >> $GITHUB_OUTPUT
else
echo "Version $version does not exist in Maven Central."
echo "release_name_check=true" >> $GITHUB_OUTPUT
fi
elif [ "$RESPONSE_CODE" == "404" ]; then
echo "The metadata file for $groupId:$artifactId does not exist in Maven Central."
echo "release_name_check=true" >> $GITHUB_OUTPUT
else
echo "An unexpected error occurred while checking the metadata file for $groupId:$artifactId."
echo "release_name_check=true" >> $GITHUB_OUTPUT
fi
# 检查 PR 标题
title="${{ steps.pr-info.outputs.title }}"
version="${{ steps.extract-info.outputs.version }}"
echo "Pull Request Title: $title"
echo "Version: $version"
# 转换为小写并进行条件判断
if [[ "${title,,}" =~ ^release-$version$ ]]; then
echo "Pull Request title is valid."
echo "release_name_check=true" >> $GITHUB_OUTPUT
else
echo "Pull Request title must be in the format 'release-$version'."
echo "release_name_check=false" >> $GITHUB_OUTPUT
fi
83 changes: 83 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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: Release

on:
pull_request:
types: [closed]

jobs:

release-name-check:
uses: ./.github/workflows/pre-release.yml

publish:
needs: [release-name-check]
runs-on: ubuntu-latest
if: ${{ needs.release-name-check.outputs.release_name_check == 'true' }}
name: publish project
permissions:
contents: write
packages: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Get Release Parameters
id: extract-info
run: |
groupId=$(mvn help:evaluate -Dexpression=project.groupId -q -DforceStdout)
artifactId=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
body=$(cat $GITHUB_EVENT_PATH | jq -r '.pull_request.body')
echo "PR Body: $body"
echo "body<<EOF"$'\n'"$body"$'\n'EOF >> "$GITHUB_OUTPUT"
echo "Pom GroupId: $groupId"
echo "Pom ArtifactId: $artifactId"
echo "Pom Version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
echo "artifactId=$artifactId" >> $GITHUB_OUTPUT
echo "groupId=$groupId" >> $GITHUB_OUTPUT
- 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
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

- name: Create Github Tag
uses: negz/create-tag@v1
with:
version: v${{ steps.extract-info.outputs.version }}
message: ${{ steps.extract-info.outputs.body }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Create Github Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: v${{ steps.extract-info.outputs.version }}
release_name: v${{ steps.extract-info.outputs.version }}
body: ${{ steps.extract-info.outputs.body }}
draft: false
prerelease: false




4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<parent>
<groupId>io.github.easyretrofit</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<description>The function of core is to generate retrofit instances based on the DI framework and manage retrofit resource context</description>
<artifactId>core</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<url>https://github.com/easyretrofit/${project.artifactId}</url>
Expand Down

0 comments on commit cb3c028

Please sign in to comment.