@@ -28,15 +28,104 @@ jobs:
2828 flags : node-${{ matrix.node-version }}
2929 fail_ci_if_error : false
3030
31- semantic-release :
31+ prepare_snapshot_version :
32+ name : Prepare Snapshot Version
3233 needs : [test]
34+ if : >-
35+ ${{
36+ github.repository == 'apache/casbin-node-casbin' &&
37+ github.event_name == 'push' &&
38+ github.ref == 'refs/heads/master'
39+ }}
3340 runs-on : ubuntu-latest
41+ outputs :
42+ version : ${{ steps.snapshot.outputs.version }}
43+ npm_version : ${{ steps.snapshot.outputs.npm_version }}
44+ basename : ${{ steps.snapshot.outputs.basename }}
45+ previous_tag : ${{ steps.snapshot.outputs.previous_tag }}
3446 steps :
3547 - uses : actions/checkout@v4
48+ with :
49+ fetch-depth : 0
50+ ref : ${{ github.sha }}
51+
52+ - name : Compute snapshot version
53+ id : snapshot
54+ run : |
55+ LATEST_RELEASE_TAG="$(
56+ git tag --list 'v*' |
57+ grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
58+ sort -V |
59+ tail -n 1
60+ )"
61+
62+ if [ -z "${LATEST_RELEASE_TAG}" ]; then
63+ BASE_VERSION="0.1.0"
64+ else
65+ RELEASE_VERSION="${LATEST_RELEASE_TAG#v}"
66+ MAJOR="${RELEASE_VERSION%%.*}"
67+ REST="${RELEASE_VERSION#*.}"
68+ MINOR="${REST%%.*}"
69+ NEXT_MINOR="$((MINOR + 1))"
70+ BASE_VERSION="${MAJOR}.${NEXT_MINOR}.0"
71+ fi
72+
73+ ESCAPED_BASE_VERSION="${BASE_VERSION//./\\.}"
74+ LAST_SNAPSHOT_NUMBER="$(
75+ git tag --list "v${BASE_VERSION}-snapshot.*" |
76+ sed -nE "s/^v${ESCAPED_BASE_VERSION}-snapshot\.([0-9]+)$/\1/p" |
77+ sort -n |
78+ tail -n 1
79+ )"
80+ LAST_SNAPSHOT_NUMBER="${LAST_SNAPSHOT_NUMBER:-0}"
81+ NEXT_SNAPSHOT_NUMBER="$((LAST_SNAPSHOT_NUMBER + 1))"
82+ SNAPSHOT_VERSION="v${BASE_VERSION}-snapshot.${NEXT_SNAPSHOT_NUMBER}"
83+ NPM_VERSION="${SNAPSHOT_VERSION#v}"
84+ BASENAME="casbin-${NPM_VERSION}-src"
85+
86+ echo "version=${SNAPSHOT_VERSION}" >> "${GITHUB_OUTPUT}"
87+ echo "npm_version=${NPM_VERSION}" >> "${GITHUB_OUTPUT}"
88+ echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
89+ if [ "${LAST_SNAPSHOT_NUMBER}" -gt 0 ]; then
90+ echo "previous_tag=v${BASE_VERSION}-snapshot.${LAST_SNAPSHOT_NUMBER}" >> "${GITHUB_OUTPUT}"
91+ else
92+ echo "previous_tag=${LATEST_RELEASE_TAG}" >> "${GITHUB_OUTPUT}"
93+ fi
94+
95+ echo "Computed snapshot version: ${SNAPSHOT_VERSION}"
96+ echo "Computed npm version: ${NPM_VERSION}"
97+
98+ publish-npm :
99+ name : Publish NPM
100+ needs : prepare_snapshot_version
101+ if : >-
102+ ${{
103+ github.repository == 'apache/casbin-node-casbin' &&
104+ github.event_name == 'push' &&
105+ github.ref == 'refs/heads/master'
106+ }}
107+ uses : ./.github/workflows/npm-snapshot.yml
108+ with :
109+ npm_version : ${{ needs.prepare_snapshot_version.outputs.npm_version }}
110+ ref : ${{ github.sha }}
111+ secrets : inherit
36112
37- - name : Run semantic-release
38- if : github.repository == 'apache/casbin-node-casbin' && github.event_name == 'push'
39- run : yarn install && yarn semantic-release
40- env :
41- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
42- NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
113+ semantic-relese :
114+ name : semantic-relese
115+ needs :
116+ - prepare_snapshot_version
117+ - publish-npm
118+ if : >-
119+ ${{
120+ github.repository == 'apache/casbin-node-casbin' &&
121+ github.event_name == 'push' &&
122+ github.ref == 'refs/heads/master'
123+ }}
124+ permissions :
125+ contents : write
126+ uses : ./.github/workflows/semantic-relese.yml
127+ with :
128+ version : ${{ needs.prepare_snapshot_version.outputs.version }}
129+ basename : ${{ needs.prepare_snapshot_version.outputs.basename }}
130+ previous_tag : ${{ needs.prepare_snapshot_version.outputs.previous_tag }}
131+ ref : ${{ github.sha }}
0 commit comments