-
Notifications
You must be signed in to change notification settings - Fork 231
131 lines (122 loc) · 4.06 KB
/
Copy pathmain.yml
File metadata and controls
131 lines (122 loc) · 4.06 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: main
on:
push:
branches:
- master
pull_request:
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [^20, ^22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn lint
- run: yarn test
- run: yarn coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: node-${{ matrix.node-version }}
fail_ci_if_error: false
prepare_snapshot_version:
name: Prepare Snapshot Version
needs: [test]
if: >-
${{
github.repository == 'apache/casbin-node-casbin' &&
github.event_name == 'push' &&
github.ref == 'refs/heads/master'
}}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.snapshot.outputs.version }}
npm_version: ${{ steps.snapshot.outputs.npm_version }}
basename: ${{ steps.snapshot.outputs.basename }}
previous_tag: ${{ steps.snapshot.outputs.previous_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.sha }}
- 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}"
NPM_VERSION="${SNAPSHOT_VERSION#v}"
BASENAME="casbin-${NPM_VERSION}-src"
echo "version=${SNAPSHOT_VERSION}" >> "${GITHUB_OUTPUT}"
echo "npm_version=${NPM_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 npm version: ${NPM_VERSION}"
publish-npm:
name: Publish NPM
needs: prepare_snapshot_version
if: >-
${{
github.repository == 'apache/casbin-node-casbin' &&
github.event_name == 'push' &&
github.ref == 'refs/heads/master'
}}
uses: ./.github/workflows/npm-snapshot.yml
with:
npm_version: ${{ needs.prepare_snapshot_version.outputs.npm_version }}
ref: ${{ github.sha }}
secrets: inherit
semantic-relese:
name: semantic-relese
needs:
- prepare_snapshot_version
- publish-npm
if: >-
${{
github.repository == 'apache/casbin-node-casbin' &&
github.event_name == 'push' &&
github.ref == 'refs/heads/master'
}}
permissions:
contents: write
uses: ./.github/workflows/semantic-relese.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 }}
ref: ${{ github.sha }}