diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f6e7eee --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +name: Release + +permissions: + contents: read + +on: + push: + branches: [main] + +concurrency: + group: release + cancel-in-progress: false + +jobs: + tag: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + # Full history and tags, to compute the next version. + fetch-depth: 0 + + - name: Create the next semver tag and release + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + last=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -1) + if [ -z "$last" ]; then + next="v1.0.0" + else + if [ "$(git rev-parse "${last}^{commit}")" = "$GITHUB_SHA" ]; then + echo "HEAD is already released as $last" + exit 0 + fi + IFS=. read -r maj min pat <<<"${last#v}" + git log --format=%s "${last}..HEAD" >/tmp/subjects.txt + git log --format=%b "${last}..HEAD" >/tmp/bodies.txt + if grep -qE '^[a-z]+(\([^)]*\))?!:' /tmp/subjects.txt || grep -q '^BREAKING CHANGE:' /tmp/bodies.txt; then + next="v$((maj + 1)).0.0" + elif grep -qE '^feat(\([^)]*\))?:' /tmp/subjects.txt; then + next="v${maj}.$((min + 1)).0" + else + next="v${maj}.${min}.$((pat + 1))" + fi + fi + gh release create "$next" --target "$GITHUB_SHA" --generate-notes diff --git a/README.md b/README.md index e7361a6..86b21e6 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,11 @@ jobs: ## Versioning -- All workflow references use **SHA pinning** (no `@v1` tags) -- SHA pins are auto-updated by **Renovate** (Dependabot is not used) +- Every push to `main` is tagged and released automatically + ([release.yml](.github/workflows/release.yml)); the semver bump is derived + from the conventional commit types since the last tag +- Consumers reference workflows/actions as `@ # vX.Y.Z`; Renovate bumps + the pins against the tags (Dependabot is not used) ## Composite Actions