-
Notifications
You must be signed in to change notification settings - Fork 492
117 lines (103 loc) · 3.95 KB
/
Copy pathmaven-ci.yml
File metadata and controls
117 lines (103 loc) · 3.95 KB
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
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: build
on:
push:
branches:
- master
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn clean test cobertura:cobertura
- name: Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
prepare_snapshot_version:
name: Prepare Snapshot Version
needs: build
if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.snapshot.outputs.version }}
maven_version: ${{ steps.snapshot.outputs.maven_version }}
basename: ${{ steps.snapshot.outputs.basename }}
previous_tag: ${{ steps.snapshot.outputs.previous_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute snapshot version
id: snapshot
run: |
LATEST_RELEASE_TAG="$(
git tag --list 'v*' |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
sort -V |
tail -n 1
)"
if [ -z "${LATEST_RELEASE_TAG}" ]; then
BASE_VERSION="0.1.0"
else
RELEASE_VERSION="${LATEST_RELEASE_TAG#v}"
MAJOR="${RELEASE_VERSION%%.*}"
REST="${RELEASE_VERSION#*.}"
MINOR="${REST%%.*}"
NEXT_MINOR="$((MINOR + 1))"
BASE_VERSION="${MAJOR}.${NEXT_MINOR}.0"
fi
ESCAPED_BASE_VERSION="${BASE_VERSION//./\\.}"
LAST_SNAPSHOT_NUMBER="$(
git tag --list "v${BASE_VERSION}-snapshot.*" |
sed -nE "s/^v${ESCAPED_BASE_VERSION}-snapshot\\.([0-9]+)$/\\1/p" |
sort -n |
tail -n 1
)"
LAST_SNAPSHOT_NUMBER="${LAST_SNAPSHOT_NUMBER:-0}"
NEXT_SNAPSHOT_NUMBER="$((LAST_SNAPSHOT_NUMBER + 1))"
SNAPSHOT_VERSION="v${BASE_VERSION}-snapshot.${NEXT_SNAPSHOT_NUMBER}"
MAVEN_VERSION="${SNAPSHOT_VERSION#v}"
BASENAME="jcasbin-${MAVEN_VERSION}-src"
echo "version=${SNAPSHOT_VERSION}" >> "${GITHUB_OUTPUT}"
echo "maven_version=${MAVEN_VERSION}" >> "${GITHUB_OUTPUT}"
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
if [ "${LAST_SNAPSHOT_NUMBER}" -gt 0 ]; then
echo "previous_tag=v${BASE_VERSION}-snapshot.${LAST_SNAPSHOT_NUMBER}" >> "${GITHUB_OUTPUT}"
else
echo "previous_tag=${LATEST_RELEASE_TAG}" >> "${GITHUB_OUTPUT}"
fi
echo "Computed snapshot version: ${SNAPSHOT_VERSION}"
echo "Computed Maven version: ${MAVEN_VERSION}"
publish-maven:
name: Publish Maven
needs: prepare_snapshot_version
if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: ./.github/workflows/maven-snapshot.yml
with:
maven_version: ${{ needs.prepare_snapshot_version.outputs.maven_version }}
secrets: inherit
semantic-release:
name: Semantic Release
needs:
- prepare_snapshot_version
- publish-maven
if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
permissions:
contents: write
uses: ./.github/workflows/source-snapshot.yml
with:
version: ${{ needs.prepare_snapshot_version.outputs.version }}
basename: ${{ needs.prepare_snapshot_version.outputs.basename }}
previous_tag: ${{ needs.prepare_snapshot_version.outputs.previous_tag }}