-
Notifications
You must be signed in to change notification settings - Fork 31
66 lines (51 loc) · 2.68 KB
/
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
name: Build jar-file of latest version containing all dependencies
on:
workflow_dispatch:
pull_request:
branches:
- master
paths: # only build new jar file if pom.xml or java sources have changed
- pom.xml
- src/main/**
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'adopt' # You can choose other distributions like 'zulu' or 'temurin'
java-version: '11'
- name: Pull branch
run: |
git checkout -b ${{ github.event.pull_request.head.ref }}
git pull origin ${{ github.event.pull_request.head.ref }} --rebase || echo "No changes to pull"
- name: Build and package JAR with dependencies
run: mvn clean package
- name: commit changes of jar file
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p latest-version
if ! cmp -s target/*-jar-with-dependencies.jar latest-version/mongodb-performance-test.jar; then
mv target/*-jar-with-dependencies.jar latest-version/mongodb-performance-test.jar
ls -al latest-version/
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
git config --local user.email "[email protected]"
git config --local user.name "github-actions[bot]"
git add latest-version/mongodb-performance-test.jar
git commit -m "Add latest version ($VERSION) of mongodb-performance-test.jar"
git push origin ${{ github.event.pull_request.head.ref }}
# Delete the local tag if it exists
git tag -d "v$VERSION" || true # Ignore if the tag doesn't exist
git tag -a "v$VERSION" -m "Tagging version $VERSION"
git push origin :refs/tags/v$VERSION || true # delete remote tag, if exists
git push origin "v$VERSION" # create remote tag
echo "### Version updated to $VERSION" >> $GITHUB_STEP_SUMMARY
echo "The [latest-version/mongodb-performance-test.jar](https://github.com/idealo/mongodb-performance-test/tree/master/latest-version/mongodb-performance-test.jar) is now $VERSION" >> $GITHUB_STEP_SUMMARY
else
echo "### Build unchanged" >> $GITHUB_STEP_SUMMARY
echo "The [latest-version/mongodb-performance-test.jar](https://github.com/idealo/mongodb-performance-test/tree/master/latest-version/mongodb-performance-test.jar) is unchanged" >> $GITHUB_STEP_SUMMARY
fi