-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (95 loc) · 3.83 KB
/
auto_build_jar.yml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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 }}