Skip to content

Commit f069b27

Browse files
committed
build: Add a github workflow for python-semantic-release
This should release the plugin to PyPI on new merges to main.
1 parent 9debbcb commit f069b27

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: Python CI
22

33
on:
4-
push:
5-
branches: [main]
64
pull_request:
75
branches:
86
- "**"
7+
# This is so we can call CI locally from other workflows that might want to
8+
# run CI before doing whatever task they're doing. Like the release workflow.
9+
workflow_call:
910

1011
defaults:
1112
run:

.github/workflows/release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Python Semantic Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
run_tests:
9+
uses: ./.github/workflows/ci.yml
10+
11+
release:
12+
needs: run_tests
13+
runs-on: ubuntu-latest
14+
if: github.ref_name == 'main'
15+
concurrency:
16+
group: ${{ github.workflow }}-release-${{ github.ref_name }}
17+
cancel-in-progress: false
18+
19+
permissions:
20+
contents: write
21+
22+
steps:
23+
# Note: We checkout the repository at the branch that triggered the workflow.
24+
# Python Semantic Release will automatically convert shallow clones to full clones
25+
# if needed to ensure proper history evaluation. However, we forcefully reset the
26+
# branch to the workflow sha because it is possible that the branch was updated
27+
# while the workflow was running, which prevents accidentally releasing un-evaluated
28+
# changes.
29+
- name: Setup | Checkout Repository on Release Branch
30+
uses: actions/checkout@v4
31+
with:
32+
ref: ${{ github.ref_name }}
33+
34+
- name: Setup | Force release branch to be at workflow sha
35+
run: |
36+
git reset --hard ${{ github.sha }}
37+
38+
- name: Action | Semantic Version Release
39+
id: release
40+
# Adjust tag with desired version if applicable.
41+
uses: python-semantic-release/[email protected]
42+
with:
43+
github_token: ${{ secrets.GITHUB_TOKEN }}
44+
git_committer_name: "github-actions"
45+
git_committer_email: "[email protected]"
46+
working-directory: './backend'
47+
48+
- name: Publish | Upload to GitHub Release Assets
49+
uses: python-semantic-release/[email protected]
50+
if: steps.release.outputs.released == 'true'
51+
with:
52+
github_token: ${{ secrets.GITHUB_TOKEN }}
53+
tag: ${{ steps.release.outputs.tag }}
54+
working-directory: './backend'
55+
56+
- name: Upload | Distribution Artifacts
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: distribution-artifacts
60+
path: dist
61+
if-no-files-found: error
62+
working-directory: './backend'
63+
64+
outputs:
65+
released: ${{ steps.release.outputs.released || 'false' }}
66+
67+
deploy:
68+
# 1. Separate out the deploy step from the publish step to run each step at
69+
# the least amount of token privilege
70+
# 2. Also, deployments can fail, and its better to have a separate job if you need to retry
71+
# and it won't require reversing the release.
72+
runs-on: ubuntu-latest
73+
needs: release
74+
if: github.ref_name == 'main' && needs.release.outputs.released == 'true'
75+
76+
permissions:
77+
contents: read
78+
id-token: write
79+
80+
steps:
81+
- name: Setup | Download Build Artifacts
82+
uses: actions/download-artifact@v4
83+
id: artifact-download
84+
with:
85+
name: distribution-artifacts
86+
path: dist
87+
88+
- name: Publish to PyPi
89+
uses: pypa/gh-action-pypi-publish@release/v1
90+
with:
91+
packages-dir: dist
92+
user: __token__
93+
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}

backend/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ include = ["sample_plugin*"]
4646
exclude = ["sample_plugin.tests*"]
4747

4848
[tool.semantic_release.changelog.default_templates]
49-
changelog_file = "CHANGELOG.rst"
50-
output_format = "rst"
49+
changelog_file = "../CHANGELOG.md"

0 commit comments

Comments
 (0)