Skip to content

Commit 0ab8750

Browse files
committed
feat: replace auto release with manual tag-driven release
1 parent 3258a4e commit 0ab8750

5 files changed

Lines changed: 190 additions & 324 deletions

File tree

.github/workflows/maven-ci.yml

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -30,88 +30,3 @@ jobs:
3030
uses: codecov/codecov-action@v1
3131
with:
3232
token: ${{ secrets.CODECOV_TOKEN }}
33-
34-
prepare_snapshot_version:
35-
name: Prepare Snapshot Version
36-
needs: build
37-
if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
38-
runs-on: ubuntu-latest
39-
outputs:
40-
version: ${{ steps.snapshot.outputs.version }}
41-
maven_version: ${{ steps.snapshot.outputs.maven_version }}
42-
basename: ${{ steps.snapshot.outputs.basename }}
43-
previous_tag: ${{ steps.snapshot.outputs.previous_tag }}
44-
steps:
45-
- name: Checkout
46-
uses: actions/checkout@v4
47-
with:
48-
fetch-depth: 0
49-
50-
- name: Compute snapshot version
51-
id: snapshot
52-
run: |
53-
LATEST_RELEASE_TAG="$(
54-
git tag --list 'v*' |
55-
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
56-
sort -V |
57-
tail -n 1
58-
)"
59-
60-
if [ -z "${LATEST_RELEASE_TAG}" ]; then
61-
BASE_VERSION="0.1.0"
62-
else
63-
RELEASE_VERSION="${LATEST_RELEASE_TAG#v}"
64-
MAJOR="${RELEASE_VERSION%%.*}"
65-
REST="${RELEASE_VERSION#*.}"
66-
MINOR="${REST%%.*}"
67-
NEXT_MINOR="$((MINOR + 1))"
68-
BASE_VERSION="${MAJOR}.${NEXT_MINOR}.0"
69-
fi
70-
71-
ESCAPED_BASE_VERSION="${BASE_VERSION//./\\.}"
72-
LAST_SNAPSHOT_NUMBER="$(
73-
git tag --list "v${BASE_VERSION}-snapshot.*" |
74-
sed -nE "s/^v${ESCAPED_BASE_VERSION}-snapshot\\.([0-9]+)$/\\1/p" |
75-
sort -n |
76-
tail -n 1
77-
)"
78-
LAST_SNAPSHOT_NUMBER="${LAST_SNAPSHOT_NUMBER:-0}"
79-
NEXT_SNAPSHOT_NUMBER="$((LAST_SNAPSHOT_NUMBER + 1))"
80-
SNAPSHOT_VERSION="v${BASE_VERSION}-snapshot.${NEXT_SNAPSHOT_NUMBER}"
81-
MAVEN_VERSION="${SNAPSHOT_VERSION#v}"
82-
BASENAME="jcasbin-${MAVEN_VERSION}-src"
83-
84-
echo "version=${SNAPSHOT_VERSION}" >> "${GITHUB_OUTPUT}"
85-
echo "maven_version=${MAVEN_VERSION}" >> "${GITHUB_OUTPUT}"
86-
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
87-
if [ "${LAST_SNAPSHOT_NUMBER}" -gt 0 ]; then
88-
echo "previous_tag=v${BASE_VERSION}-snapshot.${LAST_SNAPSHOT_NUMBER}" >> "${GITHUB_OUTPUT}"
89-
else
90-
echo "previous_tag=${LATEST_RELEASE_TAG}" >> "${GITHUB_OUTPUT}"
91-
fi
92-
93-
echo "Computed snapshot version: ${SNAPSHOT_VERSION}"
94-
echo "Computed Maven version: ${MAVEN_VERSION}"
95-
96-
publish-maven:
97-
name: Publish Maven
98-
needs: prepare_snapshot_version
99-
if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
100-
uses: ./.github/workflows/maven-snapshot.yml
101-
with:
102-
maven_version: ${{ needs.prepare_snapshot_version.outputs.maven_version }}
103-
secrets: inherit
104-
105-
semantic-release:
106-
name: Semantic Release
107-
needs:
108-
- prepare_snapshot_version
109-
- publish-maven
110-
if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
111-
permissions:
112-
contents: write
113-
uses: ./.github/workflows/source-snapshot.yml
114-
with:
115-
version: ${{ needs.prepare_snapshot_version.outputs.version }}
116-
basename: ${{ needs.prepare_snapshot_version.outputs.basename }}
117-
previous_tag: ${{ needs.prepare_snapshot_version.outputs.previous_tag }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
workflow_dispatch:
1010
inputs:
1111
maven_version:
12-
description: Maven release version to publish, for example 1.2.3-snapshot.1
12+
description: Maven release version to publish, for example 1.2.3
1313
required: true
1414
type: string
1515

.github/workflows/release.yml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: Release
2+
3+
# Releases are cut manually by pushing a git tag:
4+
# v1.4.0-rc1 -> GitHub pre-release only (source package for the Apache vote)
5+
# v1.4.0 -> GitHub release + publish to Maven Central
6+
#
7+
# The release manager downloads the source package from the release, signs it
8+
# locally, and uses it for voting. This workflow does not sign anything.
9+
10+
on:
11+
push:
12+
tags:
13+
- "v*"
14+
15+
permissions:
16+
contents: write
17+
18+
jobs:
19+
prepare:
20+
name: Prepare Release
21+
if: ${{ github.repository == 'apache/casbin-jcasbin' }}
22+
runs-on: ubuntu-latest
23+
outputs:
24+
tag: ${{ steps.meta.outputs.tag }}
25+
version: ${{ steps.meta.outputs.version }}
26+
maven_version: ${{ steps.meta.outputs.maven_version }}
27+
basename: ${{ steps.meta.outputs.basename }}
28+
prerelease: ${{ steps.meta.outputs.prerelease }}
29+
previous_tag: ${{ steps.meta.outputs.previous_tag }}
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
- name: Compute release metadata
37+
id: meta
38+
run: |
39+
TAG_NAME="${GITHUB_REF_NAME}"
40+
41+
if [[ "${TAG_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
42+
PRERELEASE=false
43+
elif [[ "${TAG_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$ ]]; then
44+
PRERELEASE=true
45+
else
46+
echo "Unsupported release tag: ${TAG_NAME}. Use v1.2.3 or v1.2.3-rc1." >&2
47+
exit 1
48+
fi
49+
50+
VERSION="${TAG_NAME#v}"
51+
BASE_VERSION="${VERSION%%-rc*}"
52+
BASENAME="apache-casbin-jcasbin-${VERSION}-incubating-src"
53+
PREVIOUS_TAG="$(
54+
{
55+
git tag --list 'v*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$'
56+
echo "v${BASE_VERSION}"
57+
} |
58+
sort -V -u |
59+
awk -v current="v${BASE_VERSION}" '
60+
$0 == current {
61+
print previous
62+
exit
63+
}
64+
{
65+
previous = $0
66+
}
67+
'
68+
)"
69+
70+
echo "tag=${TAG_NAME}" >> "${GITHUB_OUTPUT}"
71+
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
72+
echo "maven_version=${BASE_VERSION}" >> "${GITHUB_OUTPUT}"
73+
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
74+
echo "prerelease=${PRERELEASE}" >> "${GITHUB_OUTPUT}"
75+
echo "previous_tag=${PREVIOUS_TAG}" >> "${GITHUB_OUTPUT}"
76+
77+
echo "Tag: ${TAG_NAME} (pre-release: ${PRERELEASE})"
78+
echo "Source package: ${BASENAME}.tar.gz"
79+
80+
github-release:
81+
name: GitHub Release
82+
needs: prepare
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v4
87+
with:
88+
fetch-depth: 0
89+
90+
- name: Generate release notes
91+
env:
92+
CURRENT_TAG: ${{ needs.prepare.outputs.tag }}
93+
CURRENT_VERSION: ${{ needs.prepare.outputs.version }}
94+
PREVIOUS_TAG: ${{ needs.prepare.outputs.previous_tag }}
95+
PRERELEASE: ${{ needs.prepare.outputs.prerelease }}
96+
run: |
97+
RELEASE_DATE="$(date -u +%F)"
98+
RANGE="${CURRENT_TAG}"
99+
100+
if [ -n "${PREVIOUS_TAG}" ]; then
101+
RANGE="${PREVIOUS_TAG}..${CURRENT_TAG}"
102+
fi
103+
104+
FEATURES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(feat)(\(.+\))?: ' || true)"
105+
FIXES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(fix)(\(.+\))?: ' || true)"
106+
DOCS="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(docs?|doc)(\(.+\))?: ' || true)"
107+
108+
{
109+
if [ -n "${PREVIOUS_TAG}" ]; then
110+
echo "# [${CURRENT_VERSION}](https://github.com/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${CURRENT_TAG}) (${RELEASE_DATE})"
111+
else
112+
echo "# ${CURRENT_VERSION} (${RELEASE_DATE})"
113+
fi
114+
echo
115+
116+
if [ "${PRERELEASE}" = "true" ]; then
117+
echo "Release candidate for the Apache voting process. This is not a released version."
118+
echo
119+
fi
120+
121+
if [ -n "${PREVIOUS_TAG}" ]; then
122+
echo "Changes since ${PREVIOUS_TAG}."
123+
echo
124+
fi
125+
126+
if [ -n "${FEATURES}" ]; then
127+
echo "## Features"
128+
echo
129+
printf '%s\n' "${FEATURES}" | sed 's/^/- /'
130+
echo
131+
fi
132+
133+
if [ -n "${FIXES}" ]; then
134+
echo "## Fixes"
135+
echo
136+
printf '%s\n' "${FIXES}" | sed 's/^/- /'
137+
echo
138+
fi
139+
140+
if [ -n "${DOCS}" ]; then
141+
echo "## Docs"
142+
echo
143+
printf '%s\n' "${DOCS}" | sed 's/^/- /'
144+
echo
145+
fi
146+
147+
if [ -z "${FEATURES}${FIXES}${DOCS}" ]; then
148+
echo "## Notes"
149+
echo
150+
echo "- No feat/fix/doc commits were found in this release range."
151+
fi
152+
} > RELEASE_NOTES.md
153+
154+
- name: Create source packages
155+
env:
156+
TAG: ${{ needs.prepare.outputs.tag }}
157+
BASENAME: ${{ needs.prepare.outputs.basename }}
158+
run: |
159+
mkdir -p dist
160+
git archive --format=tar.gz --prefix="${BASENAME}/" -o "dist/${BASENAME}.tar.gz" "${TAG}"
161+
git archive --format=zip --prefix="${BASENAME}/" -o "dist/${BASENAME}.zip" "${TAG}"
162+
cd dist
163+
sha512sum "${BASENAME}.tar.gz" > "${BASENAME}.tar.gz.sha512"
164+
sha512sum "${BASENAME}.zip" > "${BASENAME}.zip.sha512"
165+
166+
- name: Create GitHub release
167+
uses: softprops/action-gh-release@v2
168+
with:
169+
tag_name: ${{ needs.prepare.outputs.tag }}
170+
name: JCasbin ${{ needs.prepare.outputs.tag }}
171+
body_path: RELEASE_NOTES.md
172+
draft: false
173+
prerelease: ${{ needs.prepare.outputs.prerelease == 'true' }}
174+
files: |
175+
dist/${{ needs.prepare.outputs.basename }}.tar.gz
176+
dist/${{ needs.prepare.outputs.basename }}.tar.gz.sha512
177+
dist/${{ needs.prepare.outputs.basename }}.zip
178+
dist/${{ needs.prepare.outputs.basename }}.zip.sha512
179+
180+
publish-maven:
181+
name: Publish Maven
182+
needs:
183+
- prepare
184+
- github-release
185+
if: ${{ needs.prepare.outputs.prerelease == 'false' }}
186+
uses: ./.github/workflows/maven-publish.yml
187+
with:
188+
maven_version: ${{ needs.prepare.outputs.maven_version }}
189+
secrets: inherit

0 commit comments

Comments
 (0)