Skip to content

Commit 38a30dd

Browse files
committed
ci: rc publish workflow
1 parent 99bebb2 commit 38a30dd

3 files changed

Lines changed: 116 additions & 40 deletions

File tree

.github/workflows/publish.yml

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
name: Publish Python Package
1+
name: Continuous Delivery
22

33
on:
44
push:
5-
tags:
6-
- "v*.*.*"
5+
branches:
6+
- main
7+
- rc
78

89
jobs:
910
publish:
1011
runs-on: ubuntu-latest
12+
concurrency:
13+
group: ${{ github.workflow }}-release-${{ github.ref_name }}
14+
cancel-in-progress: false
1115
environment: pypi
1216
permissions:
1317
id-token: write
@@ -16,6 +20,13 @@ jobs:
1620
steps:
1721
- name: Checkout repository
1822
uses: actions/checkout@v4
23+
with:
24+
ref: ${{ github.ref_name }}
25+
fetch-depth: 0
26+
27+
- name: Setup | Force release branch to be at workflow sha
28+
run: |
29+
git reset --hard ${{ github.sha }}
1930
2031
- name: Set up Python
2132
uses: actions/setup-python@v5
@@ -32,19 +43,61 @@ jobs:
3243
virtualenvs-create: false
3344
installer-parallel: true
3445

35-
- name: Build package
36-
run: poetry build
46+
- name: Evaluate | Verify upstream has NOT changed
47+
# Last chance to abort before causing an error as another PR/push was applied to
48+
# the upstream branch while this workflow was running. This is important
49+
# because we are committing a version change (--commit). You may omit this step
50+
# if you have 'commit: false' in your configuration.
51+
#
52+
# You may consider moving this to a repo script and call it from this step instead
53+
# of writing it in-line.
54+
shell: bash
55+
run: |
56+
set +o pipefail
3757
38-
- name: Publish to PyPI
39-
uses: pypa/gh-action-pypi-publish@release/v1
58+
UPSTREAM_BRANCH_NAME="$(git status -sb | head -n 1 | cut -d' ' -f2 | grep -E '\.{3}' | cut -d'.' -f4)"
59+
printf '%s\n' "Upstream branch name: $UPSTREAM_BRANCH_NAME"
60+
61+
set -o pipefail
62+
63+
if [ -z "$UPSTREAM_BRANCH_NAME" ]; then
64+
printf >&2 '%s\n' "::error::Unable to determine upstream branch name!"
65+
exit 1
66+
fi
67+
68+
git fetch "${UPSTREAM_BRANCH_NAME%%/*}"
69+
70+
if ! UPSTREAM_SHA="$(git rev-parse "$UPSTREAM_BRANCH_NAME")"; then
71+
printf >&2 '%s\n' "::error::Unable to determine upstream branch sha!"
72+
exit 1
73+
fi
4074
41-
- name: Upload package to GitHub Releases
42-
uses: softprops/action-gh-release@v1
75+
HEAD_SHA="$(git rev-parse HEAD)"
76+
77+
if [ "$HEAD_SHA" != "$UPSTREAM_SHA" ]; then
78+
printf >&2 '%s\n' "[HEAD SHA] $HEAD_SHA != $UPSTREAM_SHA [UPSTREAM SHA]"
79+
printf >&2 '%s\n' "::error::Upstream has changed, aborting release..."
80+
exit 1
81+
fi
82+
83+
printf '%s\n' "Verified upstream branch has not changed, continuing with release..."
84+
85+
- name: Action | Semantic Version Release
86+
id: release
87+
# Adjust tag with desired version if applicable.
88+
uses: python-semantic-release/python-semantic-release@v9.21.1
89+
with:
90+
github_token: ${{ secrets.GITHUB_TOKEN }}
91+
git_committer_name: "github-actions"
92+
git_committer_email: "actions@users.noreply.github.com"
93+
94+
- name: Publish | Upload to GitHub Release Assets
95+
uses: python-semantic-release/publish-action@v9.21.1
96+
if: steps.release.outputs.released == 'true'
4397
with:
44-
tag_name: ${{ github.ref }}
45-
generate_release_notes: true
46-
files: |
47-
dist/*.tar.gz
48-
dist/*.whl
49-
env:
50-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
github_token: ${{ secrets.GITHUB_TOKEN }}
99+
tag: ${{ steps.release.outputs.tag }}
100+
101+
- name: Publish to PyPI
102+
uses: pypa/gh-action-pypi-publish@release/v1
103+
if: steps.release.outputs.released == 'true'

poetry.lock

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,40 @@ dependencies = [
2121
]
2222

2323

24+
[project.urls]
25+
Homepage = "https://github.com/Trup3s/resimulate"
26+
Repository = "https://github.com/Trup3s/resimulate"
27+
28+
2429
[build-system]
2530
requires = ["poetry-core>=2.0.0,<3.0.0"]
2631
build-backend = "poetry.core.masonry.api"
2732

2833
[tool.poetry.group.dev.dependencies]
29-
ruff = "^0.11.8"
34+
ruff = "^0.11.9"
3035
pre-commit = "^4.2.0"
3136
pytest = "^8.3.5"
3237

3338
[tool.poetry.scripts]
3439
resimulate = "resimulate.cli:run"
3540

41+
[tool.semantic_release]
42+
upload_to_pypi = true
43+
upload_to_release = true
44+
build_command = "poetry build"
45+
branch = "main"
46+
changelog_file = "CHANGELOG.md"
47+
commit_author = "github-actions <github-actions@github.com>"
48+
major_on_zero = false
49+
50+
[tool.semantic_release.branches.main]
51+
match = "main"
52+
prerelease = false
53+
54+
[tool.semantic_release.branches."rc"]
55+
match = "rc"
56+
prerelease = true
57+
prerelease_token = "rc"
58+
3659
[tool.basedpyright]
3760
venvPath = "."

0 commit comments

Comments
 (0)