From b940d91d89969590af84b56a52316803174c4f65 Mon Sep 17 00:00:00 2001 From: krypton-byte Date: Wed, 1 Apr 2026 19:57:50 +0700 Subject: [PATCH] fix(test): update workflows for commit message validation and release automation --- .github/workflows/commit-messages.yml | 53 +++++++++++++++------------ .github/workflows/release.yml | 27 ++++---------- CONTRIBUTING.md | 20 ++++++---- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/.github/workflows/commit-messages.yml b/.github/workflows/commit-messages.yml index d6b2a35..2feb99f 100644 --- a/.github/workflows/commit-messages.yml +++ b/.github/workflows/commit-messages.yml @@ -1,8 +1,11 @@ name: Conventional Commits on: + push: + tags-ignore: + - "v*" pull_request: - types: [opened, synchronize, reopened, edited] + types: [opened, synchronize, reopened] permissions: contents: read @@ -20,27 +23,31 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Check commit subjects in PR range + - name: Resolve commit range + id: commit_range run: | - python scripts/check_commit_message.py --range "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" + set -euo pipefail - pr-title: - name: Validate PR title - runs-on: ubuntu-latest - steps: - - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - types: | - build - chore - ci - docs - feat - fix - perf - refactor - style - test - requireScope: false + if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then + range="${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" + else + before_sha="${{ github.event.before }}" + after_sha="${GITHUB_SHA}" + + if [ "${before_sha}" = "0000000000000000000000000000000000000000" ]; then + if git rev-parse "${after_sha}^" >/dev/null 2>&1; then + range="${after_sha}^..${after_sha}" + else + range="${after_sha}..${after_sha}" + fi + else + range="${before_sha}..${after_sha}" + fi + fi + + echo "range=${range}" >> "$GITHUB_OUTPUT" + echo "Using commit range: ${range}" + + - name: Check commit subjects in range + run: | + python scripts/check_commit_message.py --range "${{ steps.commit_range.outputs.range }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 21db282..577a493 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,6 @@ name: Semantic Release on: - pull_request: - branches: - - main - types: - - closed workflow_dispatch: permissions: @@ -18,16 +13,6 @@ concurrency: jobs: release: - if: >- - ${{ - github.event_name == 'workflow_dispatch' || - ( - github.event_name == 'pull_request' && - github.event.pull_request.merged == true && - github.event.pull_request.base.ref == 'main' && - github.event.pull_request.head.ref == 'dev' - ) - }} runs-on: ubuntu-latest steps: - name: Log trigger context @@ -35,9 +20,6 @@ jobs: echo "event=${GITHUB_EVENT_NAME}" echo "ref=${GITHUB_REF}" echo "actor=${GITHUB_ACTOR}" - echo "pr_merged=${{ github.event.pull_request.merged }}" - echo "pr_base=${{ github.event.pull_request.base.ref }}" - echo "pr_head=${{ github.event.pull_request.head.ref }}" - uses: actions/checkout@v4 with: @@ -88,12 +70,19 @@ jobs: if [ "${after_sha}" = "${{ steps.baseline.outputs.sha }}" ] && [ "${after_tag}" = "${{ steps.baseline.outputs.tag }}" ]; then echo "released=false" >> "$GITHUB_OUTPUT" - echo "No new release generated from this merge." + echo "No new release generated in this run." else echo "released=true" >> "$GITHUB_OUTPUT" echo "Release generated. Latest tag: ${after_tag:-none}" fi + - name: Create GitHub release + if: ${{ steps.release_result.outputs.released == 'true' && startsWith(steps.release_result.outputs.after_tag, 'v') }} + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.release_result.outputs.after_tag }} + generate_release_notes: true + - name: Trigger CI release build on new tag if: ${{ steps.release_result.outputs.released == 'true' && startsWith(steps.release_result.outputs.after_tag, 'v') }} env: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 939bb7c..0ad4eee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -71,7 +71,7 @@ Examples: 1. Create a feature branch from `main`. 2. Keep PR scope focused and small. 3. Ensure CI is green. -4. Use a Conventional Commit style PR title. +4. Use Conventional Commit style commit messages (`feat:`, `fix:`, `perf:`, etc.). 5. Fill the PR template completely. Recommended merge strategy: squash merge. @@ -89,11 +89,12 @@ Include: ## Release Flow Overview -- Release automation runs when a PR from `dev` into `main` is merged. -- Semantic release evaluates Conventional Commits from merged changes. +- Release is executed manually from GitHub Actions using the `Semantic Release` workflow (`workflow_dispatch`). +- Semantic release evaluates Conventional Commits already present in `main` (from PR merges or direct pushes). - If commits qualify (`feat`, `fix`, `perf`, or breaking), version and changelog are updated and a new tag (`vX.Y.Z`) is created. - If commits do not qualify (for example docs/chore only), release is a no-op and no publish is triggered. -- New `vX.Y.Z` tags trigger the CI workflow that builds multi-platform wheels and publishes to PyPI. +- After a tag is created, GitHub Release notes are generated automatically. +- CI is then triggered on that tag to build artifacts and publish to PyPI. ## Simple Trigger Guide @@ -106,10 +107,10 @@ Use this rule of thumb for automatic versioning: How to trigger semantic release until publish to PyPI: -1. Push commit to `dev` using Conventional Commit format. -2. Open PR from `dev` to `main`. -3. Merge PR. -4. Semantic Release workflow runs, creates tag `vX.Y.Z` when releasable commits exist. +1. Push commits to `main` (direct push or merged PR), using Conventional Commit messages. +2. Open GitHub Actions and run `Semantic Release` on `main`. +3. Workflow evaluates commits and creates tag `vX.Y.Z` when releasable commits exist. +4. Workflow creates the corresponding GitHub Release. 5. CI workflow runs on that tag and publishes artifacts to PyPI. Manual fallback (if needed): @@ -118,5 +119,8 @@ Manual fallback (if needed): 2. Run `Semantic Release` workflow via `workflow_dispatch`. 3. If no releasable commit exists, workflow will report no new release. +Commit validation note: +- Conventional commit message checks run on both `push` and `pull_request` events. + Required repository secrets: - `PYPI_API_TOKEN`: token used by publish job to upload wheels/sdist to PyPI.