Skip to content

Commit

Permalink
ci: automate releases
Browse files Browse the repository at this point in the history
  • Loading branch information
xenophonf committed Nov 30, 2023
1 parent de62e92 commit 4234625
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
name: Release

# Trigger this workflow manually or after testing (main branch only).
on:
workflow_dispatch:
workflow_run:
workflows:
- Test
branches:
- main
types:
- completed

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
release:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/cache/restore@v3
with:
key: workdir-${{ github.sha }}
path: .
- id: release
uses: python-semantic-release/python-semantic-release@v8.3.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache/save@v3
with:
key: release-${{ github.sha }}
path: .
outputs:
released: ${{ steps.release.outputs.released }}
tag: ${{ steps.release.outputs.tag }}

build:
needs: release
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/cache/restore@v3
with:
key: release-${{ github.sha }}
path: .
- run: pip install build && python -m build
- uses: actions/cache/save@v3
with:
key: build-${{ github.sha }}
path: .

testpypi:
needs:
- release
- build
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/stuart
permissions:
id-token: write
steps:
- uses: actions/cache/restore@v3
with:
key: build-${{ github.sha }}
path: .
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
repository-url: https://test.pypi.org/legacy/
verbose: true

pypi:
needs:
- release
- build
- testpypi
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/stuart
permissions:
id-token: write
steps:
- uses: actions/cache/restore@v3
with:
key: build-${{ github.sha }}
path: .
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
verbose: true

github:
needs:
- release
- build
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/cache/restore@v3
with:
key: build-${{ github.sha }}
path: .
- name: Publish package distributions to GitHub Releases
uses: python-semantic-release/upload-to-gh-release@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.release.outputs.tag }}
58 changes: 58 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,63 @@ markers = [
"smoke",
]

[tool.semantic_release]
assets = []
commit_message = "release: cut the v{version} release\n\nAutomatically generated by python-semantic-release"
commit_parser = "angular"
logging_use_named_masks = false
# Change back to true once ready for the 1.0 release. See also
# https://python-semantic-release.readthedocs.io/en/stable/algorithm.html.
major_on_zero = false
tag_format = "v{version}"
version_toml = [
"pyproject.toml:project.version",
]

[tool.semantic_release.branches.main]
match = "(main|master)"
prerelease = false
prerelease_token = "rc"

[tool.semantic_release.changelog]
template_dir = "templates"
changelog_file = "CHANGELOG.md"
exclude_commit_patterns = []

[tool.semantic_release.changelog.environment]
block_start_string = "{%"
block_end_string = "%}"
variable_start_string = "{{"
variable_end_string = "}}"
comment_start_string = "{#"
comment_end_string = "#}"
trim_blocks = false
lstrip_blocks = false
newline_sequence = "\n"
keep_trailing_newline = false
extensions = []
autoescape = true

[tool.semantic_release.commit_author]
env = "GIT_COMMIT_AUTHOR"
default = "semantic-release <releng@irtnog.org>"

[tool.semantic_release.commit_parser_options]
allowed_tags = ["build", "ci", "docs", "feat", "fix", "perf", "refactor", "test"]
minor_tags = ["feat"]
patch_tags = ["fix", "perf"]

[tool.semantic_release.remote]
name = "origin"
type = "github"
ignore_token_for_push = false

[tool.semantic_release.remote.token]
env = "GH_TOKEN"

[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = true

[tool.setuptools.package-dir]
stuart = "src"

0 comments on commit 4234625

Please sign in to comment.