-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (93 loc) · 3.5 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
name: Build and Publish
on:
push:
branches:
- '*'
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Zulu 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: Check if tag exists
id: check_tag
run: |
OWNER=$(echo "${{ github.repository }}" | cut -d'/' -f1)
REPO=$(echo "${{ github.repository }}" | cut -d'/' -f2)
TAG_EXISTS=$(gh api -H "api.github.com" /repos/$OWNER/$REPO/git/refs/tags/${{ env.VERSION }} --jq '.ref' | wc -l)
if [ "$TAG_EXISTS" -eq 1 ]; then
echo "Tag exists"
echo "SKIP_BUILD=true" >> $GITHUB_ENV
else
echo "Tag does not exist"
echo "SKIP_BUILD=false" >> $GITHUB_ENV
fi
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Check if commit message contains [skip]
id: check_skip
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MESSAGE" == "[skip]"* ]]; then
echo "SKIP_UPLOAD=true" >> $GITHUB_ENV
else
echo "SKIP_UPLOAD=false" >> $GITHUB_ENV
fi
- name: Update version in plugin.yml
if: env.SKIP_BUILD == 'false'
run: |
sed -i "s/\(version: \).*/\1'${{ env.VERSION }}'/" src/main/resources/plugin.yml
- name: Build with Gradle
if: env.SKIP_BUILD == 'false'
run: ./gradlew shadowJar
- name: Rename JAR file
if: env.SKIP_BUILD == 'false'
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: Upload Artifact
uses: "actions/upload-artifact@v4"
with:
name: ${{ env.FINAL_JAR_NAME }}
path: ${{ env.FINAL_JAR_NAME }}.jar
- name: Create Pre-Release and Upload JAR file
if: env.SKIP_UPLOAD == 'false' && env.SKIP_BUILD == 'false'
uses: ncipollo/[email protected]
with:
tag: ${{ env.VERSION }}
name: "版本 ${{ env.VERSION }} (自动创建的版本)"
body: |
此预发布版本由Github Action自动构建。
请注意,此版本为测试版,并不代表最终版本。
### 最后一次提交信息
#### 提交SHA:
> ${{ github.sha }}
#### 提交消息:
> ${{ github.event.head_commit.message }}
draft: false
prerelease: true
makeLatest: true
generateReleaseNotes: true
artifacts: ${{ env.FINAL_JAR_NAME }}.jar
token: ${{ secrets.GH_TOKEN }}