Skip to content

Commit 58dfd39

Browse files
authored
feat: auto release snapshot versions now (#521)
1 parent ab2403e commit 58dfd39

5 files changed

Lines changed: 368 additions & 24 deletions

File tree

.github/workflows/maven-ci.yml

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ jobs:
2222
uses: actions/setup-java@v1
2323
with:
2424
java-version: 1.8
25-
server-id: ossrh
26-
server-username: OSSRH_JIRA_USERNAME
27-
server-password: OSSRH_JIRA_PASSWORD
28-
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
29-
gpg-passphrase: GPG_PASSPHRASE
3025

3126
- name: Build with Maven
3227
run: mvn clean test cobertura:cobertura
@@ -36,18 +31,87 @@ jobs:
3631
with:
3732
token: ${{ secrets.CODECOV_TOKEN }}
3833

39-
- name: Set up Node.js
40-
uses: actions/setup-node@v2
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
4147
with:
42-
node-version: 20
48+
fetch-depth: 0
4349

44-
- name: Semantic Release
50+
- name: Compute snapshot version
51+
id: snapshot
4552
run: |
46-
npm install -g @conveyal/maven-semantic-release semantic-release
47-
semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release
48-
env:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50-
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
51-
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
52-
OSSRH_JIRA_USERNAME: ${{ secrets.OSSRH_JIRA_USERNAME }}
53-
OSSRH_JIRA_PASSWORD: ${{ secrets.OSSRH_JIRA_PASSWORD }}
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish Maven
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
maven_version:
7+
required: true
8+
type: string
9+
workflow_dispatch:
10+
inputs:
11+
maven_version:
12+
description: Maven release version to publish, for example 1.2.3-snapshot.1
13+
required: true
14+
type: string
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
publish-maven:
21+
name: Publish Maven
22+
if: ${{ github.repository == 'apache/casbin-jcasbin' }}
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up JDK 1.8
31+
uses: actions/setup-java@v4
32+
with:
33+
distribution: temurin
34+
java-version: 8
35+
server-id: ossrh
36+
server-username: OSSRH_JIRA_USERNAME
37+
server-password: OSSRH_JIRA_PASSWORD
38+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
39+
gpg-passphrase: GPG_PASSPHRASE
40+
41+
- name: Publish Maven
42+
run: |
43+
mvn -B org.codehaus.mojo:versions-maven-plugin:2.16.2:set -DnewVersion="${{ inputs.maven_version }}" -DgenerateBackupPoms=false
44+
mvn -B deploy -DskipTests
45+
env:
46+
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
47+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
48+
OSSRH_JIRA_USERNAME: ${{ secrets.OSSRH_JIRA_USERNAME }}
49+
OSSRH_JIRA_PASSWORD: ${{ secrets.OSSRH_JIRA_PASSWORD }}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Build Source Release Draft
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-source-release-draft:
13+
if: ${{ github.repository == 'apache/casbin-jcasbin' && !contains(github.ref_name, '-') }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Compute release metadata
22+
id: release
23+
run: |
24+
TAG_NAME="${GITHUB_REF_NAME}"
25+
if ! [[ "${TAG_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
26+
echo "Unsupported release tag: ${TAG_NAME}" >&2
27+
exit 1
28+
fi
29+
30+
VERSION="${TAG_NAME#v}"
31+
BASENAME="jcasbin-${VERSION}-src"
32+
PREVIOUS_TAG="$(
33+
git tag --list 'v*' |
34+
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
35+
sort -V |
36+
awk -v current="${TAG_NAME}" '
37+
$0 == current {
38+
print previous
39+
exit
40+
}
41+
{
42+
previous = $0
43+
}
44+
'
45+
)"
46+
47+
echo "tag=${TAG_NAME}" >> "${GITHUB_OUTPUT}"
48+
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
49+
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
50+
echo "previous_tag=${PREVIOUS_TAG}" >> "${GITHUB_OUTPUT}"
51+
52+
- name: Generate release notes
53+
run: |
54+
CURRENT_TAG="${{ steps.release.outputs.tag }}"
55+
CURRENT_VERSION="${{ steps.release.outputs.version }}"
56+
PREVIOUS_TAG="${{ steps.release.outputs.previous_tag }}"
57+
RELEASE_DATE="$(date -u +%F)"
58+
RANGE="${CURRENT_TAG}"
59+
60+
if [ -n "${PREVIOUS_TAG}" ]; then
61+
RANGE="${PREVIOUS_TAG}..${CURRENT_TAG}"
62+
fi
63+
64+
FEATURES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(feat)(\(.+\))?: ' || true)"
65+
FIXES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(fix)(\(.+\))?: ' || true)"
66+
DOCS="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(docs?|doc)(\(.+\))?: ' || true)"
67+
68+
{
69+
if [ -n "${PREVIOUS_TAG}" ]; then
70+
echo "# [${CURRENT_VERSION}](https://github.com/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${CURRENT_TAG}) (${RELEASE_DATE})"
71+
else
72+
echo "# ${CURRENT_VERSION} (${RELEASE_DATE})"
73+
fi
74+
echo
75+
echo "This GitHub release is a draft helper for packaging and release notes."
76+
echo
77+
if [ -n "${PREVIOUS_TAG}" ]; then
78+
echo "Changes since ${PREVIOUS_TAG}."
79+
fi
80+
echo
81+
82+
if [ -n "${FEATURES}" ]; then
83+
echo "## Features"
84+
echo
85+
printf '%s\n' "${FEATURES}" | sed 's/^/- /'
86+
echo
87+
fi
88+
89+
if [ -n "${FIXES}" ]; then
90+
echo "## Fixes"
91+
echo
92+
printf '%s\n' "${FIXES}" | sed 's/^/- /'
93+
echo
94+
fi
95+
96+
if [ -n "${DOCS}" ]; then
97+
echo "## Docs"
98+
echo
99+
printf '%s\n' "${DOCS}" | sed 's/^/- /'
100+
echo
101+
fi
102+
103+
if [ -z "${FEATURES}${FIXES}${DOCS}" ]; then
104+
echo "## Notes"
105+
echo
106+
echo "- No feat/fix/doc commits were found in this release range."
107+
fi
108+
} > RELEASE_NOTES.md
109+
110+
- name: Create source archives
111+
run: |
112+
mkdir -p dist
113+
git archive --format=tar.gz --prefix="${{ steps.release.outputs.basename }}/" -o "dist/${{ steps.release.outputs.basename }}.tar.gz" "${{ steps.release.outputs.tag }}"
114+
git archive --format=zip --prefix="${{ steps.release.outputs.basename }}/" -o "dist/${{ steps.release.outputs.basename }}.zip" "${{ steps.release.outputs.tag }}"
115+
116+
- name: Create draft GitHub release
117+
uses: softprops/action-gh-release@v2
118+
with:
119+
tag_name: ${{ steps.release.outputs.tag }}
120+
name: JCasbin ${{ steps.release.outputs.tag }}
121+
body_path: RELEASE_NOTES.md
122+
draft: true
123+
files: |
124+
dist/${{ steps.release.outputs.basename }}.tar.gz
125+
dist/${{ steps.release.outputs.basename }}.zip

0 commit comments

Comments
 (0)