blob: cadf1dd3c7875ccc938f13b02ecee9723a671479 [file]
name: Release
# Releases are cut by hand: nothing here runs on a merge, only on a pushed tag.
#
# v1.10.0-rc1 -> GitHub pre-release (the candidate put up for the Apache vote)
# v1.10.0 -> GitHub release + push the Docker image
#
# Either way the release carries an Apache-style source tarball as its only
# asset. The release manager downloads that tarball and signs / checksums it
# locally before starting the vote; nothing is signed or uploaded here.
on:
push:
tags:
- "v*"
permissions:
contents: write
env:
# Base name of the source release artifact, per Apache naming conventions.
ARTIFACT_BASENAME: apache-casbin-server
jobs:
release:
name: Release ${{ github.ref_name }}
if: github.repository == 'apache/casbin-server'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.base_version }}
prerelease: ${{ steps.version.outputs.prerelease }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Resolve version from tag
id: version
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME#v}"
# v1.10.0-rc1 -> 1.10.0. The tarball the PPMC votes on is the exact tarball
# that ships, so the candidate counter is never part of its name.
BASE_VERSION="${VERSION%%-rc*}"
if [ "$VERSION" = "$BASE_VERSION" ]; then
PRERELEASE=false
else
PRERELEASE=true
fi
# Anything that is neither vX.Y.Z nor vX.Y.Z-rcN is a typo, and a typo
# must not reach Docker Hub.
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$'; then
echo "::error::Tag $GITHUB_REF_NAME is not vX.Y.Z or vX.Y.Z-rcN."
exit 1
fi
{
echo "base_version=$BASE_VERSION"
echo "prerelease=$PRERELEASE"
} >> "$GITHUB_OUTPUT"
echo "Tag $GITHUB_REF_NAME -> version $BASE_VERSION (pre-release: $PRERELEASE)"
- name: Verify go.mod matches the tag
run: |
set -euo pipefail
# Go resolves vN.x.y tags (N >= 2) only for a module whose path ends in
# /vN, and v0 / v1 tags only for a module without such a suffix.
MODULE="$(awk '/^module /{print $2; exit}' go.mod)"
MAJOR="${GITHUB_REF_NAME#v}"
MAJOR="${MAJOR%%.*}"
if [[ "${MODULE##*/}" =~ ^v([0-9]+)$ ]]; then
OK=$([ "$MAJOR" = "${BASH_REMATCH[1]}" ] && echo true || echo false)
else
OK=$([ "$MAJOR" -le 1 ] && echo true || echo false)
fi
if [ "$OK" != true ]; then
echo "::error::go.mod declares $MODULE but the tag is $GITHUB_REF_NAME."
exit 1
fi
- name: Build source release tarball
id: package
run: |
set -euo pipefail
NAME="${ARTIFACT_BASENAME}-${{ steps.version.outputs.base_version }}-incubating-src"
ASSET="${RUNNER_TEMP}/${NAME}.tar.gz"
# git archive gives us exactly the tracked sources at this tag, unpacking
# into a single top-level directory named after the release.
git archive --format=tar.gz --prefix="$NAME/" -o "$ASSET" HEAD
echo "asset=$ASSET" >> "$GITHUB_OUTPUT"
ls -l "$ASSET"
- name: Publish GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
ASSET: ${{ steps.package.outputs.asset }}
run: |
set -euo pipefail
FLAGS=(--title "$TAG" --generate-notes)
if [ "${{ steps.version.outputs.prerelease }}" = "true" ]; then
FLAGS+=(--prerelease)
fi
gh release create "$TAG" "$ASSET" "${FLAGS[@]}"
docker:
name: Build and Push Docker Image
needs: release
# Release candidates exist only for the vote; they never reach a registry.
if: needs.release.outputs.prerelease == 'false'
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.release.outputs.version }}
steps:
- name: Check the Docker Hub credentials are configured
id: gate
env:
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
if [ -n "${DOCKERHUB_PASSWORD}" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
echo "::warning::DOCKERHUB_PASSWORD is not set, so no Docker image was pushed for ${VERSION}."
fi
- name: Checkout Repository
if: steps.gate.outputs.enabled == 'true'
uses: actions/checkout@v4
- name: Set up QEMU
if: steps.gate.outputs.enabled == 'true'
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
- name: Set up Docker Buildx
if: steps.gate.outputs.enabled == 'true'
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Log in to Docker Hub
if: steps.gate.outputs.enabled == 'true'
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
if: steps.gate.outputs.enabled == 'true'
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
target: STANDARD
push: true
tags: |
casbin/casbin-server:latest
casbin/casbin-server:${{ env.VERSION }}
platforms: linux/amd64,linux/arm64