Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,3 @@ jobs:

- name: Run go test bench
run: make benchmark

semantic-release:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- name: Run semantic-release
if: github.repository == 'casbin/casbin' && github.event_name == 'push'
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117 changes: 117 additions & 0 deletions .github/workflows/source-release-draft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Build Source Release Draft

on:
push:
tags:
- "v*"

permissions:
contents: write

jobs:
build-source-release-draft:
if: ${{ github.repository == 'apache/casbin' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Compute release metadata
id: release
run: |
TAG_NAME="${GITHUB_REF_NAME}"

VERSION="${TAG_NAME#v}"
BASENAME="casbin-${VERSION}-src"

echo "tag=${TAG_NAME}" >> "${GITHUB_OUTPUT}"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"

- name: Generate release notes
run: |
CURRENT_TAG="${{ steps.release.outputs.tag }}"
PREVIOUS_TAG="$(git describe --tags --abbrev=0 "${CURRENT_TAG}^" 2>/dev/null || true)"
RANGE="${CURRENT_TAG}"

if [ -n "${PREVIOUS_TAG}" ]; then
RANGE="${PREVIOUS_TAG}..${CURRENT_TAG}"
fi

FEATURES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(feat)(\(.+\))?: ' || true)"
FIXES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(fix)(\(.+\))?: ' || true)"
DOCS="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(docs?|doc)(\(.+\))?: ' || true)"

{
echo "# Casbin ${CURRENT_TAG}"
echo
echo "This GitHub release is a draft helper for packaging and release notes."
echo
if [ -n "${PREVIOUS_TAG}" ]; then
echo "Changes since ${PREVIOUS_TAG}."
fi
echo

if [ -n "${FEATURES}" ]; then
echo "## Features"
echo
printf '%s\n' "${FEATURES}" | sed 's/^/- /'
echo
fi

if [ -n "${FIXES}" ]; then
echo "## Fixes"
echo
printf '%s\n' "${FIXES}" | sed 's/^/- /'
echo
fi

if [ -n "${DOCS}" ]; then
echo "## Docs"
echo
printf '%s\n' "${DOCS}" | sed 's/^/- /'
echo
fi

if [ -z "${FEATURES}${FIXES}${DOCS}" ]; then
echo "## Notes"
echo
echo "- No feat/fix/doc commits were found in this release range."
fi
} > RELEASE_NOTES.md

- name: Create source archives
run: |
mkdir -p dist
git archive --format=tar.gz --prefix="${{ steps.release.outputs.basename }}/" -o "dist/${{ steps.release.outputs.basename }}.tar.gz" "${{ steps.release.outputs.tag }}"
git archive --format=zip --prefix="${{ steps.release.outputs.basename }}/" -o "dist/${{ steps.release.outputs.basename }}.zip" "${{ steps.release.outputs.tag }}"

- name: Create draft GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.tag }}
name: Casbin ${{ steps.release.outputs.tag }}
body_path: RELEASE_NOTES.md
draft: true
files: |
dist/${{ steps.release.outputs.basename }}.tar.gz
dist/${{ steps.release.outputs.basename }}.zip
162 changes: 162 additions & 0 deletions .github/workflows/source-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Build Source Snapshot

on:
push:
branches:
- master
workflow_dispatch:

permissions:
contents: write

jobs:
build-source-snapshot:
if: ${{ github.repository == 'apache/casbin' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Compute snapshot metadata
id: snapshot
run: |
LATEST_RELEASE_TAG="$(
git ls-remote --tags origin "refs/tags/v*" |
awk -F'/' '
{
tag = $NF
sub(/\^\{\}$/, "", tag)
if (tag ~ /^v[0-9]+\.[0-9]+\.[0-9]+$/) {
version = substr(tag, 2)
split(version, parts, ".")
key = sprintf("%09d%09d%09d", parts[1], parts[2], parts[3])
if (key > max_key) {
max_key = key
max_version = version
}
}
}
END {
if (max_version == "") {
print ""
} else {
printf "v%s\n", max_version
}
}
'
)"

if [ -z "${LATEST_RELEASE_TAG}" ]; then
BASE_VERSION="0.0.1"
else
RELEASE_VERSION="${LATEST_RELEASE_TAG#v}"
split_version_major="${RELEASE_VERSION%%.*}"
remaining="${RELEASE_VERSION#*.}"
split_version_minor="${remaining%%.*}"
split_version_patch="${RELEASE_VERSION##*.}"
BASE_VERSION="${split_version_major}.${split_version_minor}.$((split_version_patch + 1))"
fi

LAST_SNAPSHOT_NUMBER="$(
git ls-remote --tags origin "refs/tags/${BASE_VERSION}-snapshot.*" |
awk -F'/' '
{
tag = $NF
sub(/\^\{\}$/, "", tag)
if (tag ~ /^[0-9]+\.[0-9]+\.[0-9]+-snapshot\.[0-9]+$/) {
split(tag, version_parts, "-snapshot.")
snapshot_number = version_parts[2] + 0
if (snapshot_number > max) {
max = snapshot_number
}
}
}
END {
if (max == "") {
print 0
} else {
print max
}
}
'
)"
NEXT_SNAPSHOT_NUMBER="$((LAST_SNAPSHOT_NUMBER + 1))"
SNAPSHOT_VERSION="v${BASE_VERSION}-snapshot.${NEXT_SNAPSHOT_NUMBER}"

echo "latest_release_tag=${LATEST_RELEASE_TAG}" >> "${GITHUB_OUTPUT}"
echo "base_version=${BASE_VERSION}" >> "${GITHUB_OUTPUT}"
echo "number=${NEXT_SNAPSHOT_NUMBER}" >> "${GITHUB_OUTPUT}"
echo "version=${SNAPSHOT_VERSION}" >> "${GITHUB_OUTPUT}"

- name: Generate snapshot release notes
run: |
PREVIOUS_TAG="${{ steps.snapshot.outputs.latest_release_tag }}"
RANGE="HEAD"

if [ -n "${PREVIOUS_TAG}" ]; then
RANGE="${PREVIOUS_TAG}..HEAD"
fi

FEATURES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(feat)(\(.+\))?: ' || true)"
FIXES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(fix)(\(.+\))?: ' || true)"
DOCS="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(docs?|doc)(\(.+\))?: ' || true)"

{
echo "# Casbin ${{ steps.snapshot.outputs.version }}"
echo
if [ -n "${FEATURES}" ]; then
echo "## Features"
echo
printf '%s\n' "${FEATURES}" | sed 's/^/- /'
echo
fi

if [ -n "${FIXES}" ]; then
echo "## Fixes"
echo
printf '%s\n' "${FIXES}" | sed 's/^/- /'
echo
fi

if [ -n "${DOCS}" ]; then
echo "## Docs"
echo
printf '%s\n' "${DOCS}" | sed 's/^/- /'
echo
fi

if [ -z "${FEATURES}${FIXES}${DOCS}" ]; then
echo "## Notes"
echo
echo "- No feat/fix/doc commits were found in this snapshot range."
fi
} > SNAPSHOT_RELEASE_NOTES.md

- name: Create snapshot GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.snapshot.outputs.version }}
target_commitish: ${{ github.sha }}
name: ${{ steps.snapshot.outputs.version }}
body_path: SNAPSHOT_RELEASE_NOTES.md
draft: false
prerelease: true
16 changes: 0 additions & 16 deletions .releaserc.json

This file was deleted.

3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ benchmark:

lint:
golangci-lint run --verbose

release:
npx semantic-release@v19.0.2