Skip to content

Commit 3e2ee33

Browse files
committed
actions workflow updated
1 parent b9f37e2 commit 3e2ee33

File tree

1 file changed

+83
-4
lines changed

1 file changed

+83
-4
lines changed

.github/workflows/main.yml

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,94 @@ on:
33
push:
44
branches:
55
- main
6+
pull_request:
7+
branches:
8+
- main
9+
release:
10+
types:
11+
- released
612
jobs:
7-
jar:
13+
build:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
name: ${{ steps.build.outputs.name }}
17+
version: ${{ steps.build.outputs.version }}
18+
steps:
19+
- uses: actions/checkout@v2
20+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
21+
- uses: actions/setup-java@v1
22+
with:
23+
java-version: '1.8'
24+
- name: build jar
25+
id: build
26+
run: |
27+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
28+
[ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/}
29+
[ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=-beta && VERSION+=.$(($(git tag -l "v$VERSION.*" | sort -nt. -k4 2>/dev/null | tail -1 | cut -d. -f4)+1))
30+
[ $GITHUB_EVENT_NAME == 'pull_request' ] && VERSION+=-dev.${{ github.event.pull_request.number }}
31+
mvn versions:set -DnewVersion=$VERSION
32+
mvn --batch-mode package
33+
NAME=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$VERSION
34+
echo ::set-output name=name::$NAME
35+
echo ::set-output name=version::$VERSION
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
- uses: actions/upload-artifact@v2
39+
with:
40+
name: ${{ steps.build.outputs.name }}.jar
41+
path: target/${{ steps.build.outputs.name }}.jar
42+
release:
843
runs-on: ubuntu-latest
44+
needs:
45+
- build
946
steps:
10-
- uses: actions/checkout@master
47+
- uses: actions/download-artifact@v2
48+
with:
49+
name: ${{ needs.build.outputs.name }}.jar
50+
- name: Create Release
51+
id: create_release
52+
uses: actions/create-release@v1
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
with:
56+
tag_name: v${{ needs.build.outputs.version }}
57+
release_name: v${{ needs.build.outputs.version }}
58+
prerelease: ${{ github.event_name != 'release' }}
59+
- name: Upload Release Asset
60+
id: upload-release-asset
61+
uses: actions/upload-release-asset@v1
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
with:
65+
upload_url: ${{ steps.create_release.outputs.upload_url }}
66+
asset_path: ${{ needs.build.outputs.name }}.jar
67+
asset_name: ${{ needs.build.outputs.name }}.jar
68+
asset_content_type: application/zip
69+
deploy:
70+
runs-on: ubuntu-latest
71+
if: (github.event_name == 'release')
72+
needs:
73+
- build
74+
steps:
75+
- uses: actions/checkout@v2
76+
with:
77+
ref: main
1178
- uses: actions/setup-java@v1
1279
with:
1380
java-version: '1.8'
14-
- name: build and deploy jar
15-
run: mvn --batch-mode deploy
81+
- name: build jar
82+
id: build
1683
env:
84+
VERSION: ${{ steps.build.outputs.version }}
1785
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
run: |
87+
mvn versions:set -DnewVersion=$VERSION
88+
mvn --batch-mode deploy
89+
VERSION=`echo $VERSION | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.`
90+
mvn versions:set -DnewVersion=$VERSION
91+
mvn versions:commit
92+
git config --global user.name 'ProjectBot'
93+
git config --global user.email '[email protected]'
94+
git add pom.xml
95+
git commit -m 'auto bump version with release'
96+

0 commit comments

Comments
 (0)