perf(config): optimizes the configuration file save logic #132
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
name: Build and Publish | |
on: | |
push: | |
branches: | |
- '*' | |
jobs: | |
clear-old-pre-release-and-create-new-pre-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete Release with Tag 'newest-build' | |
run: | | |
GITHUB_REPOSITORY="${{ github.repository }}" | |
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1) | |
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2) | |
# 删除预发布版本 | |
LATEST_RELEASE_WITH_TAG=$(curl -s -H "Authorization: token ${{ secrets.GH_TOKEN }}" https://api.github.com/repos/$OWNER/$REPO/releases/tags/newest-build) | |
if [ ! -z "$LATEST_RELEASE_WITH_TAG" ]; then | |
RELEASE_ID=$(echo $LATEST_RELEASE_WITH_TAG | jq -r '.id') | |
curl -X DELETE -H "Authorization: token ${{ secrets.GH_TOKEN }}" https://api.github.com/repos/$OWNER/$REPO/releases/$RELEASE_ID | |
echo "Deleted the release with tag 'newest-build'" | |
fi | |
# 删除标签 | |
TAG_DELETE_URL="https://api.github.com/repos/$OWNER/$REPO/git/refs/tags/newest-build" | |
curl -X DELETE -H "Authorization: token ${{ secrets.GH_TOKEN }}" $TAG_DELETE_URL | |
echo "Deleted the tag 'newest-build'" | |
continue-on-error: true | |
- name: Set Release Version | |
id: set_version | |
run: echo ::set-output name=VERSION::newest-build | |
- name: Create Pre-Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
with: | |
tag_name: newest-build | |
release_name: 最新开发构建版本(自动创建的版本) | |
body: | | |
此预发布版本由Github Action自动构建。 | |
请注意,此版本为测试版,并不代表最终版本。 | |
### 最后一次提交信息 | |
#### 提交SHA: | |
${{ github.sha }} | |
#### 提交消息: | |
${{ github.event.head_commit.message }} | |
draft: false | |
prerelease: true | |
continue-on-error: true | |
build-and-publish: | |
needs: clear-old-pre-release-and-create-new-pre-release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'zulu' | |
- name: Make gradlew executable | |
run: chmod +x ./gradlew | |
- name: Get current date | |
id: get_date | |
run: echo "DATE=$(date +'%y%m%d')" >> $GITHUB_ENV | |
- name: Get Git SHA | |
id: get_sha | |
run: echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
- name: Set VERSION environment variable | |
run: | | |
ORIGINAL_VERSION=$(grep "version:" src/main/resources/plugin.yml | cut -d ' ' -f2 | sed 's/[^0-9.]//g') | |
echo "Setting VERSION to ${ORIGINAL_VERSION}-${{ env.DATE }}-${{ env.SHA }}" | |
echo "VERSION=${ORIGINAL_VERSION}-${{ env.DATE }}-${{ env.SHA }}" >> $GITHUB_ENV | |
- name: Update version in plugin.yml | |
run: | | |
sed -i "s/\(version: \).*/\1'${{ env.VERSION }}'/" src/main/resources/plugin.yml | |
- name: Build with Gradle | |
run: ./gradlew shadowJar | |
- name: Rename JAR file | |
id: rename_file | |
run: | | |
TARGET_JAR="BasePlugin-${{ env.VERSION }}" | |
SOURCE_JAR=$(find run/plugins -name "*.jar" -print -quit) | |
echo "FINAL_JAR_NAME=${TARGET_JAR}" >> $GITHUB_ENV | |
mv "${SOURCE_JAR}" "${TARGET_JAR}.jar" | |
- name: Archive Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.FINAL_JAR_NAME }} | |
path: ${{ env.FINAL_JAR_NAME }}.jar | |
- name: Upload JAR file | |
id: upload_file | |
run: | | |
gh release upload newest-build ${{ env.FINAL_JAR_NAME }}.jar | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |