-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (120 loc) · 4.31 KB
/
build-and-release.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Generate and Publish Documentation
on:
push:
branches:
- dev
jobs:
build-application:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set Up JDK
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'
- name: Generate version tag and build
id: version_info
run: |
git fetch --tags
MAJOR_MINOR=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed -E 's/([0-9]+\.[0-9]+).*/\1/')
echo "Extracted [major.minor] version: $MAJOR_MINOR"
LATEST_TAG=$(git tag -l "v*" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -rV | head -n 1)
echo "Latest tag: $LATEST_TAG"
if [ -z "$LATEST_TAG" ]; then
PATCH=0
else
TAG_MAJOR_MINOR=$(echo $LATEST_TAG | sed -E 's/v([0-9]+\.[0-9]+)\.[0-9]+/\1/')
TAG_PATCH=$(echo $LATEST_TAG | sed -E 's/v[0-9]+\.[0-9]+\.([0-9]+)/\1/')
if [ "$(printf '%s\n' "$TAG_MAJOR_MINOR" "$MAJOR_MINOR" | sort -rV | head -n 1)" != "$MAJOR_MINOR" ]; then
echo "Current version is less than the last tag. Aborting."
exit 1
elif [ "$MAJOR_MINOR" = "$TAG_MAJOR_MINOR" ]; then
PATCH=$(($TAG_PATCH + 1))
echo "Incremented patch version: $PATCH"
else
PATCH=0
echo "Patch version reset to 0"
fi
fi
PROJECT_VERSION="$MAJOR_MINOR.$PATCH"
echo "New application version: $PROJECT_VERSION"
echo "-----> Packaging"
mvn --quiet package -Drevision=$PATCH -DskipTests=true -Dmaven.javadoc.skip=true
echo "Packaging completed"
VERSION_TAG=v$PROJECT_VERSION
git tag "$VERSION_TAG"
git push origin "$VERSION_TAG"
echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
- name: Upload JAR file
uses: actions/upload-artifact@v2
with:
name: app-jar
path: target/*.jar
publish-docs:
needs: build-application
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'
- name: Generate Javadoc
run: mvn dokka:javadoc -Ddokka.goal=javadoc -Ddokka.dir=./target/site/apidocs/javadoc
- name: Generate KDoc
run: mvn dokka:dokka -Ddokka.goal=dokka -Ddokka.dir=./target/site/apidocs/kdoc
- name: Prepare gh-pages content
run: |
cp -r ./src/main/resources/site/* .
mkdir -p ./apidocs
cp -r ./target/site/apidocs/* ./apidocs/
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./
keep_files: false
allow_empty_commit: false
force_orphan: true
create-release:
needs: [build-application]
runs-on: ubuntu-latest
steps:
- name: Download JAR file
uses: actions/download-artifact@v2
with:
name: app-jar
- name: Debug Output
run: |
echo "Version Tag from build-application job: ${{ env.VERSION_TAG }}"
echo "Project version from build-application job: ${{ env.PROJECT_VERSION }}"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION_TAG }}
release_name: Release ${{ env.PROJECT_VERSION }}
body: |
Test release
draft: false
prerelease: true
- name: Upload Release Asset
id: upload_release_asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./app-jar/*.jar
asset_name: '*.jar'
asset_content_type: application/java-archive