Skip to content

Commit addf512

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 190ec19 commit addf512

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches:
88
- "**"
9+
# This is so we can call CI locally from other workflows that might want to
10+
# run CI before doing whatever task they're doing. Like the release workflow.
11+
workflow-call:
912

1013
defaults:
1114
run:

.github/workflows/release.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Python CI
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+
47+
- name: Publish | Upload to GitHub Release Assets
48+
uses: python-semantic-release/[email protected]
49+
if: steps.release.outputs.released == 'true'
50+
with:
51+
github_token: ${{ secrets.GITHUB_TOKEN }}
52+
tag: ${{ steps.release.outputs.tag }}
53+
54+
- name: Upload | Distribution Artifacts
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: distribution-artifacts
58+
path: dist
59+
if-no-files-found: error
60+
61+
outputs:
62+
released: ${{ steps.release.outputs.released || 'false' }}
63+
64+
deploy:
65+
# 1. Separate out the deploy step from the publish step to run each step at
66+
# the least amount of token privilege
67+
# 2. Also, deployments can fail, and its better to have a separate job if you need to retry
68+
# and it won't require reversing the release.
69+
runs-on: ubuntu-latest
70+
needs: release
71+
if: github.ref_name == 'main' && needs.release.outputs.released == 'true'
72+
73+
permissions:
74+
contents: read
75+
id-token: write
76+
77+
steps:
78+
- name: Setup | Download Build Artifacts
79+
uses: actions/download-artifact@v4
80+
id: artifact-download
81+
with:
82+
name: distribution-artifacts
83+
path: dist
84+
85+
- name: Publish to PyPi
86+
uses: pypa/gh-action-pypi-publish@release/v1
87+
with:
88+
packages-dir: dist
89+
user: __token__
90+
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}

0 commit comments

Comments
 (0)