From cefbcc1a0dc819e01ea274bfb024468f1db1b4a2 Mon Sep 17 00:00:00 2001 From: Aaron <7063649+ahcodedev@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:15:22 -0800 Subject: [PATCH] Add Release Drafter and release workflow Publish template releases as vX.Y.Z tags so Copier projects pin a version instead of a commit. Release Drafter drafts notes from PR release labels, and the manual Release workflow publishes the draft. --- .github/pull_request_template.md | 1 + .github/release-drafter.yml | 45 ++++++++++++++++++++++++ .github/workflows/release-drafter.yml | 50 +++++++++++++++++++++++++++ .github/workflows/release.yml | 34 ++++++++++++++++++ README.md | 22 ++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/release-drafter.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 074064e..98dc891 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,3 +7,4 @@ - [ ] `just lint` passes - [ ] `just test-template` passes - [ ] Docs updated if needed (`README.md`, `template/README.md.jinja`, `template/CLAUDE.md`) +- [ ] Release label added diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..cad9702 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,45 @@ +# Release Drafter configuration. +# See https://github.com/release-drafter/release-drafter for more information. +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +category-template: '### $TITLE' +change-template: '- $TITLE (#$NUMBER) @$AUTHOR' +change-title-escapes: '\<*_&@' +exclude-labels: + - 'skip-changelog' +categories: + - title: 'Breaking Changes' + labels: ['breaking'] + - title: 'Features' + labels: ['feature', 'enhancement'] + - title: 'Bug Fixes' + labels: ['bug', 'fix'] + - title: 'Maintenance' + labels: ['chore', 'ci', 'dependencies', 'documentation', 'refactor'] +version-resolver: + major: + labels: ['breaking'] + minor: + labels: ['feature', 'enhancement'] + patch: + labels: ['bug', 'fix', 'chore', 'ci', 'dependencies', 'documentation', 'refactor'] + default: patch +autolabeler: + - label: 'feature' + branch: ['/^feat(ure)?\/.+/'] + - label: 'bug' + branch: ['/^(bug)?fix\/.+/'] + - label: 'chore' + branch: ['/^chore\/.+/'] + - label: 'ci' + branch: ['/^ci\/.+/'] + files: ['.github/workflows/*'] + - label: 'documentation' + branch: ['/^docs?\/.+/'] + files: ['*.md'] + - label: 'refactor' + branch: ['/^refactor\/.+/'] + - label: 'dependencies' + branch: ['/^dependabot\/.+/'] +template: | + $CHANGES diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..4be9bae --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,50 @@ +name: Release Drafter + +on: + push: + branches: ["main"] + pull_request: + types: [opened, reopened, synchronize, labeled, unlabeled] + +permissions: + contents: read + +jobs: + update-draft: + if: github.event_name == 'push' + runs-on: ubuntu-slim + permissions: + contents: write + steps: + - uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + autolabel: + if: github.event_name == 'pull_request' && github.event.action != 'labeled' && github.event.action != 'unlabeled' + runs-on: ubuntu-slim + permissions: + pull-requests: write + steps: + - uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0 + with: + disable-releaser: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + require-label: + needs: [autolabel] + # Run even when autolabel is skipped (labeled/unlabeled events) + if: ${{ always() && github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + permissions: + pull-requests: read + steps: + - uses: mheap/github-action-required-labels@23e10fde7e062233401931a0eece796cd9bf3177 # v5.6.0 + with: + mode: minimum + count: 1 + labels: >- + breaking, feature, enhancement, bug, fix, chore, ci, dependencies, documentation, refactor, + skip-changelog + use_api: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..370258f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release + +# Publishes a template release. Copier reads the resulting vX.Y.Z tags as template versions. + +on: + workflow_dispatch: + +concurrency: + group: release + cancel-in-progress: false + +permissions: + contents: read + +jobs: + release: + runs-on: ubuntu-slim + permissions: + contents: write + steps: + - name: Refresh draft release + id: drafter + uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Publishing the draft creates the vX.Y.Z tag at the commit this workflow ran on + - name: Publish release + env: + GH_TOKEN: ${{ github.token }} + RELEASE_ID: ${{ steps.drafter.outputs.id }} + run: | + gh api -X PATCH "repos/${{ github.repository }}/releases/$RELEASE_ID" \ + -F draft=false -f target_commitish="$GITHUB_SHA" diff --git a/README.md b/README.md index dd2f3bc..d4ad9d1 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Rust project template for [Copier](https://copier.readthedocs.io/). - Create a new project - `copier copy gh:ahcodedev/rust-template path/to/new-project` - Pull in template updates from inside a generated project - `just update-template` (runs `copier update`) +- New projects and updates use the latest template release (`vX.Y.Z` tag); changes merged to `main` reach projects only after a release ## Development @@ -37,6 +38,26 @@ CI runs `just lint` and `just test-template`, scans the Git history for secrets - zizmor-action reports findings as code scanning alerts in the repository's Security tab rather than failing CI - Code scanning needs a public repo, or GitHub Advanced Security on a private one +## Releases + +Releases are managed with [Release Drafter](https://github.com/release-drafter/release-drafter), which reads the +**release labels** on merged pull requests. Commit messages and PR titles aren't parsed. + +| Release label | Version bump | Release notes section | +| ---------------------------------------------------------- | ------------ | --------------------- | +| `breaking` | major | Breaking Changes | +| `feature`, `enhancement` | minor | Features | +| `bug`, `fix` | patch | Bug Fixes | +| `chore`, `ci`, `dependencies`, `documentation`, `refactor` | patch | Maintenance | +| `skip-changelog` | none | Excluded | + +- Every PR needs at least one release label, or the `Release Drafter / require-label` check fails + - Labels are added automatically from the branch name prefix (`feat/`, `fix/`, `chore/`, `ci/`, `docs/`, + `refactor/`, `dependabot/`) and from the files a PR changes +- Merging to `main` updates a draft GitHub Release with the next version and notes +- To release, run the **Release** workflow from the Actions tab. It publishes the draft and tags the commit `vX.Y.Z`, + which Copier uses as the template version + ## Dependency Updates - Dependabot (`.github/dependabot.yml`) opens weekly PRs for GitHub Actions in this repo's workflows and in `template/` @@ -52,3 +73,4 @@ CI runs `just lint` and `just test-template`, scans the Git history for secrets - `template/` - files rendered into new projects; files ending in `.jinja` are templated - `prek.toml` - Git hooks for this repo - `.github/pull_request_template.md` - checklist filled into new PR descriptions +- `.github/release-drafter.yml` - release label to version bump and release notes section mapping