From 929adb2236097e51c13184f7c79769060e70bac1 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Wed, 17 Apr 2024 23:38:21 -0700 Subject: [PATCH] Add semantic-release support --- .github/workflows/format.yml | 2 +- .github/workflows/generate.yml | 2 +- .github/workflows/publish.yml | 11 ++++++ .github/workflows/semantic-release.yml | 49 ++++++++++++++++++++++++++ .releaserc.json | 11 ++++++ README.rst | 6 ++-- makenew.sh | 2 +- 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/semantic-release.yml create mode 100644 .releaserc.json diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 5fe6351..568aab3 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -35,7 +35,7 @@ jobs: uses: stefanzweifel/git-auto-commit-action@v5 if: always() with: - commit_message: Run format + commit_message: 'ci: Format code' commit_user_name: ${{ secrets.GIT_USER_NAME }} commit_user_email: ${{ secrets.GIT_USER_EMAIL }} commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}> diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index 3570eed..2ed4ab1 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -36,7 +36,7 @@ jobs: - name: Commit uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: Generate code + commit_message: 'ci: Generate code' commit_user_name: ${{ secrets.GIT_USER_NAME }} commit_user_email: ${{ secrets.GIT_USER_EMAIL }} commit_author: ${{ secrets.GIT_USER_NAME }} <${{ secrets.GIT_USER_EMAIL }}> diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0ca7588..d082d40 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,11 +22,21 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Download artifact uses: actions/download-artifact@v4 with: name: ${{ needs.build.outputs.artifact_name }} path: dist/ + - name: Generate release notes + id: changelog + run: | + mkdir tmp + outfile=tmp/changelog.txt + echo "outfile=${outfile}" >> $GITHUB_OUTPUT + npx standard-changelog@^2.0.0 --release-count 2 --infile $outfile.tmp --outfile $outfile.tmp + sed '1,3d' $outfile.tmp > $outfile - name: Create GitHub release uses: softprops/action-gh-release@v2 with: @@ -34,6 +44,7 @@ jobs: fail_on_unmatched_files: true prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }} files: dist/* + body_path: ${{ github.workspace }}/${{ steps.changelog.outputs.outfile }} pypi: name: PyPI uses: ./.github/workflows/_publish.yml diff --git a/.github/workflows/semantic-release.yml b/.github/workflows/semantic-release.yml new file mode 100644 index 0000000..20a1f4f --- /dev/null +++ b/.github/workflows/semantic-release.yml @@ -0,0 +1,49 @@ +--- +name: Semantic Release + +run-name: Semantic Release from ${{ github.ref_name }} + +on: + push: + branches: + - '**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + +jobs: + semantic: + name: Determine version + runs-on: ubuntu-latest + timeout-minutes: 30 + outputs: + new_release_published: ${{ steps.release.outputs.new_release_published }} + new_release_version: ${{ steps.release.outputs.new_release_version }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Semantic release + id: release + uses: cycjimmy/semantic-release-action@v4 + with: + dry_run: true + release: + name: Release version + runs-on: ubuntu-latest + timeout-minutes: 30 + needs: semantic + if: needs.semantic.outputs.new_release_published == 'true' && needs.semantic.outputs.new_release_version != '1.0.0' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Release version ${{ needs.semantic.outputs.new_release_version }} on ${{ github.ref_name }} + run: gh workflow run version.yml --raw-field version=$VERSION --ref $BRANCH + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + VERSION: ${{ needs.semantic.outputs.new_release_version }} + BRANCH: ${{ github.ref_name }} diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..bd9c6e5 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,11 @@ +{ + "branches": [ + "+([0-9])?(.{+([0-9]),x}).x", + "main", + "next", + "next-major", + { "name": "beta", "prerelease": true }, + { "name": "alpha", "prerelease": true } + ], + "plugins": ["@semantic-release/commit-analyzer"] +} diff --git a/README.rst b/README.rst index 667e920..6a384b0 100644 --- a/README.rst +++ b/README.rst @@ -28,7 +28,8 @@ Features - Uncompromising code formatting with Black_. - pytest_ helps you write better programs. - Code coverage reporting with Codecov_. -- Continuous testing and deployment with `GitHub Actions`__. +- Fully automated version management and package publishing with semantic-release_. +- Continuous checks and tests with `GitHub Actions`__. - `Keep a CHANGELOG`_. - Consistent coding with EditorConfig_. - Badges from Shields.io_. @@ -37,13 +38,14 @@ Features .. _Black: https://black.readthedocs.io/en/stable/ .. _Codecov: https://codecov.io/ .. _EditorConfig: https://editorconfig.org/ -.. __: https://github.com/features/actions .. _GitHub Codespaces: https://github.com/features/codespaces .. _Keep a CHANGELOG: https://keepachangelog.com/ .. _PyPI: https://pypi.python.org/pypi .. _Pylint: https://www.pylint.org/ .. _Shields.io: https://shields.io/ +.. __: https://github.com/features/actions .. _pytest: https://docs.pytest.org/ +.. _semantic-release: https://semantic-release.gitbook.io/semantic-release/ Bootstrapping a New Project ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/makenew.sh b/makenew.sh index 6ec6f50..6343f8d 100755 --- a/makenew.sh +++ b/makenew.sh @@ -59,7 +59,7 @@ makenew () { read -p '> GitHub user or organization name (my-user): ' mk_user read -p '> GitHub repository name (my-repo): ' mk_repo - sed_delete README.rst '18,128d' + sed_delete README.rst '18,130d' sed_insert README.rst '18i' 'TODO' old_title="Python Package Skeleton"