Skip to content

Commit 15c1a45

Browse files
authored
feat: auto release snapshot versions now (#1726)
1 parent 74322db commit 15c1a45

5 files changed

Lines changed: 287 additions & 38 deletions

File tree

.github/workflows/default.yml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,3 @@ jobs:
3838

3939
- name: Run go test bench
4040
run: make benchmark
41-
42-
semantic-release:
43-
needs: test
44-
runs-on: ubuntu-latest
45-
steps:
46-
- name: Checkout
47-
uses: actions/checkout@v3
48-
with:
49-
fetch-depth: 0
50-
- name: Setup Node.js
51-
uses: actions/setup-node@v3
52-
with:
53-
node-version: 20
54-
55-
- name: Run semantic-release
56-
if: github.repository == 'casbin/casbin' && github.event_name == 'push'
57-
run: make release
58-
env:
59-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Build Source Release Draft
19+
20+
on:
21+
push:
22+
tags:
23+
- "v*"
24+
25+
permissions:
26+
contents: write
27+
28+
jobs:
29+
build-source-release-draft:
30+
if: ${{ github.repository == 'apache/casbin' && !contains(github.ref_name, '-') }}
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Compute release metadata
39+
id: release
40+
run: |
41+
TAG_NAME="${GITHUB_REF_NAME}"
42+
if ! [[ "${TAG_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
43+
echo "Unsupported release tag: ${TAG_NAME}" >&2
44+
exit 1
45+
fi
46+
47+
VERSION="${TAG_NAME#v}"
48+
BASENAME="casbin-${VERSION}-src"
49+
PREVIOUS_TAG="$(
50+
git tag --list 'v*' |
51+
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
52+
sort -V |
53+
awk -v current="${TAG_NAME}" '
54+
$0 == current {
55+
print previous
56+
exit
57+
}
58+
{
59+
previous = $0
60+
}
61+
'
62+
)"
63+
64+
echo "tag=${TAG_NAME}" >> "${GITHUB_OUTPUT}"
65+
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
66+
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
67+
echo "previous_tag=${PREVIOUS_TAG}" >> "${GITHUB_OUTPUT}"
68+
69+
- name: Generate release notes
70+
run: |
71+
CURRENT_TAG="${{ steps.release.outputs.tag }}"
72+
CURRENT_VERSION="${CURRENT_TAG#v}"
73+
PREVIOUS_TAG="${{ steps.release.outputs.previous_tag }}"
74+
RELEASE_DATE="$(date -u +%F)"
75+
RANGE="${CURRENT_TAG}"
76+
77+
if [ -n "${PREVIOUS_TAG}" ]; then
78+
RANGE="${PREVIOUS_TAG}..${CURRENT_TAG}"
79+
fi
80+
81+
FEATURES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(feat)(\(.+\))?: ' || true)"
82+
FIXES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(fix)(\(.+\))?: ' || true)"
83+
DOCS="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(docs?|doc)(\(.+\))?: ' || true)"
84+
85+
{
86+
if [ -n "${PREVIOUS_TAG}" ]; then
87+
echo "# [${CURRENT_VERSION}](https://github.com/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${CURRENT_TAG}) (${RELEASE_DATE})"
88+
else
89+
echo "# ${CURRENT_VERSION} (${RELEASE_DATE})"
90+
fi
91+
echo
92+
echo "This GitHub release is a draft helper for packaging and release notes."
93+
echo
94+
if [ -n "${FEATURES}" ]; then
95+
echo "## Features"
96+
echo
97+
printf '%s\n' "${FEATURES}" | sed 's/^/- /'
98+
echo
99+
fi
100+
101+
if [ -n "${FIXES}" ]; then
102+
echo "## Fixes"
103+
echo
104+
printf '%s\n' "${FIXES}" | sed 's/^/- /'
105+
echo
106+
fi
107+
108+
if [ -n "${DOCS}" ]; then
109+
echo "## Docs"
110+
echo
111+
printf '%s\n' "${DOCS}" | sed 's/^/- /'
112+
echo
113+
fi
114+
115+
if [ -z "${FEATURES}${FIXES}${DOCS}" ]; then
116+
echo "## Notes"
117+
echo
118+
echo "- No feat/fix/doc commits were found in this release range."
119+
fi
120+
} > RELEASE_NOTES.md
121+
122+
- name: Create source archives
123+
run: |
124+
mkdir -p dist
125+
git archive --format=tar.gz --prefix="${{ steps.release.outputs.basename }}/" -o "dist/${{ steps.release.outputs.basename }}.tar.gz" "${{ steps.release.outputs.tag }}"
126+
git archive --format=zip --prefix="${{ steps.release.outputs.basename }}/" -o "dist/${{ steps.release.outputs.basename }}.zip" "${{ steps.release.outputs.tag }}"
127+
128+
- name: Create draft GitHub release
129+
uses: softprops/action-gh-release@v2
130+
with:
131+
tag_name: ${{ steps.release.outputs.tag }}
132+
name: Casbin ${{ steps.release.outputs.tag }}
133+
body_path: RELEASE_NOTES.md
134+
draft: true
135+
files: |
136+
dist/${{ steps.release.outputs.basename }}.tar.gz
137+
dist/${{ steps.release.outputs.basename }}.zip
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Build Source Snapshot
19+
20+
on:
21+
push:
22+
branches:
23+
- master
24+
workflow_dispatch:
25+
26+
permissions:
27+
contents: write
28+
29+
jobs:
30+
build-source-snapshot:
31+
if: ${{ github.repository == 'apache/casbin' }}
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0
38+
39+
- name: Compute snapshot metadata
40+
id: snapshot
41+
run: |
42+
LATEST_RELEASE_TAG="$(
43+
git tag --list 'v*' |
44+
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
45+
sort -V |
46+
tail -n 1
47+
)"
48+
49+
if [ -z "${LATEST_RELEASE_TAG}" ]; then
50+
BASE_VERSION="0.1.0"
51+
else
52+
RELEASE_VERSION="${LATEST_RELEASE_TAG#v}"
53+
IFS='.' read -r MAJOR MINOR PATCH <<< "${RELEASE_VERSION}"
54+
BASE_VERSION="${MAJOR}.$((MINOR + 1)).0"
55+
fi
56+
57+
ESCAPED_BASE_VERSION="${BASE_VERSION//./\\.}"
58+
LAST_SNAPSHOT_NUMBER="$(
59+
git tag --list "v${BASE_VERSION}-snapshot.*" |
60+
sed -nE "s/^v${ESCAPED_BASE_VERSION}-snapshot\\.([0-9]+)$/\\1/p" |
61+
sort -n |
62+
tail -n 1
63+
)"
64+
LAST_SNAPSHOT_NUMBER="${LAST_SNAPSHOT_NUMBER:-0}"
65+
NEXT_SNAPSHOT_NUMBER="$((LAST_SNAPSHOT_NUMBER + 1))"
66+
SNAPSHOT_VERSION="v${BASE_VERSION}-snapshot.${NEXT_SNAPSHOT_NUMBER}"
67+
BASENAME="casbin-${SNAPSHOT_VERSION#v}-src"
68+
69+
if [ "${LAST_SNAPSHOT_NUMBER}" -gt 0 ]; then
70+
CHANGELOG_START_TAG="v${BASE_VERSION}-snapshot.${LAST_SNAPSHOT_NUMBER}"
71+
else
72+
CHANGELOG_START_TAG="${LATEST_RELEASE_TAG}"
73+
fi
74+
75+
echo "latest_release_tag=${LATEST_RELEASE_TAG}" >> "${GITHUB_OUTPUT}"
76+
echo "changelog_start_tag=${CHANGELOG_START_TAG}" >> "${GITHUB_OUTPUT}"
77+
echo "base_version=${BASE_VERSION}" >> "${GITHUB_OUTPUT}"
78+
echo "number=${NEXT_SNAPSHOT_NUMBER}" >> "${GITHUB_OUTPUT}"
79+
echo "version=${SNAPSHOT_VERSION}" >> "${GITHUB_OUTPUT}"
80+
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
81+
82+
- name: Generate snapshot release notes
83+
run: |
84+
PREVIOUS_TAG="${{ steps.snapshot.outputs.changelog_start_tag }}"
85+
CURRENT_TAG="${{ steps.snapshot.outputs.version }}"
86+
CURRENT_VERSION="${CURRENT_TAG#v}"
87+
RELEASE_DATE="$(date -u +%F)"
88+
RANGE="HEAD"
89+
90+
if [ -n "${PREVIOUS_TAG}" ]; then
91+
RANGE="${PREVIOUS_TAG}..HEAD"
92+
fi
93+
94+
FEATURES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(feat)(\(.+\))?: ' || true)"
95+
FIXES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(fix)(\(.+\))?: ' || true)"
96+
DOCS="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(docs?|doc)(\(.+\))?: ' || true)"
97+
98+
{
99+
if [ -n "${PREVIOUS_TAG}" ]; then
100+
echo "# [${CURRENT_VERSION}](https://github.com/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${CURRENT_TAG}) (${RELEASE_DATE})"
101+
else
102+
echo "# ${CURRENT_VERSION} (${RELEASE_DATE})"
103+
fi
104+
echo
105+
if [ -n "${FEATURES}" ]; then
106+
echo "## Features"
107+
echo
108+
printf '%s\n' "${FEATURES}" | sed 's/^/- /'
109+
echo
110+
fi
111+
112+
if [ -n "${FIXES}" ]; then
113+
echo "## Fixes"
114+
echo
115+
printf '%s\n' "${FIXES}" | sed 's/^/- /'
116+
echo
117+
fi
118+
119+
if [ -n "${DOCS}" ]; then
120+
echo "## Docs"
121+
echo
122+
printf '%s\n' "${DOCS}" | sed 's/^/- /'
123+
echo
124+
fi
125+
126+
if [ -z "${FEATURES}${FIXES}${DOCS}" ]; then
127+
echo "## Notes"
128+
echo
129+
echo "- No feat/fix/doc commits were found in this snapshot range."
130+
fi
131+
} > SNAPSHOT_RELEASE_NOTES.md
132+
133+
- name: Create source archives
134+
run: |
135+
mkdir -p dist
136+
git archive --format=tar.gz --prefix="${{ steps.snapshot.outputs.basename }}/" -o "dist/${{ steps.snapshot.outputs.basename }}.tar.gz" HEAD
137+
git archive --format=zip --prefix="${{ steps.snapshot.outputs.basename }}/" -o "dist/${{ steps.snapshot.outputs.basename }}.zip" HEAD
138+
139+
- name: Create snapshot GitHub release
140+
uses: softprops/action-gh-release@v2
141+
with:
142+
tag_name: ${{ steps.snapshot.outputs.version }}
143+
target_commitish: ${{ github.sha }}
144+
name: ${{ steps.snapshot.outputs.version }}
145+
body_path: SNAPSHOT_RELEASE_NOTES.md
146+
draft: false
147+
prerelease: false
148+
files: |
149+
dist/${{ steps.snapshot.outputs.basename }}.tar.gz
150+
dist/${{ steps.snapshot.outputs.basename }}.zip

.releaserc.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ benchmark:
1111

1212
lint:
1313
golangci-lint run --verbose
14-
15-
release:
16-
npx semantic-release@v19.0.2

0 commit comments

Comments
 (0)