Skip to content

Commit

Permalink
refactor: add semantic release and PyPi upload (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmontag authored Jul 2, 2024
1 parent 11f9beb commit be088ec
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Config file for semantic-prs (https://github.com/Ezard/semantic-prs).
---
# PRs will be rebased before being merged. Individual commits need to
# follow the semantic PR spec.
commitsOnly: true
52 changes: 50 additions & 2 deletions .github/workflows/test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
branches: [main]
pull_request:
branches: [main]
release:
types: [published]

jobs:
validate:
Expand All @@ -17,12 +19,58 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- run: python -m pip install hatch
- run: hatch fmt --check
- run: hatch test
- run: hatch run types:check

semantic_release:
name: "semantic release"
runs-on: ubuntu-latest

if: github.event_name == 'push'

# Make sure tests pass before running.
needs:
- validate

permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.12
# `python-semantic-release` will run `hatch build`.
- run: python -m pip install hatch
- uses: python-semantic-release/[email protected]

pypi:
name: "publish to PyPi"
runs-on: ubuntu-latest

if: github.event_name == 'release'

needs:
- validate

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.12
- run: python -m pip install hatch
# Tests should have already run in the `validate` job; just run
# them again as a sanity check.
- run: hatch test
- run: hatch build
- run: hatch publish
env:
HATCH_INDEX_USER: __token__
HATCH_INDEX_AUTH: ${{ secrets.PYPI_TOKEN }}
57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,60 @@ extend-select = ["ARG", "B", "E", "I", "W"]
# Turn off strict max line length; B950 allows for exceeding the max
# line length in some cases.
extend-ignore = ["E501"]

[tool.semantic_release]
assets = []
build_command = "hatch build"
build_command_env = []
commit_message = "{version}\n\nAutomatically generated by python-semantic-release"
commit_parser = "angular"
logging_use_named_masks = false
major_on_zero = true
allow_zero_version = true
no_git_verify = false
tag_format = "v{version}"
version_variables = ["src/alpacks/__about__.py:__version__"]

[tool.semantic_release.branches.main]
match = "main"
prerelease_token = "rc"
prerelease = false

[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 <semantic-release>"

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

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

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

0 comments on commit be088ec

Please sign in to comment.