Skip to content

Commit 41cd77c

Browse files
committed
fixup! build: Add a github workflow for python-semantic-release
1 parent c05ec00 commit 41cd77c

2 files changed

Lines changed: 93 additions & 81 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 81 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:
@@ -46,84 +49,3 @@ jobs:
4649
flags: unittests
4750
fail_ci_if_error: true
4851
working-directory: "./backend"
49-
50-
release:
51-
needs: run_tests
52-
runs-on: ubuntu-latest
53-
if: github.ref_name == 'main'
54-
concurrency:
55-
group: ${{ github.workflow }}-release-${{ github.ref_name }}
56-
cancel-in-progress: false
57-
58-
permissions:
59-
contents: write
60-
61-
steps:
62-
# Note: We checkout the repository at the branch that triggered the workflow.
63-
# Python Semantic Release will automatically convert shallow clones to full clones
64-
# if needed to ensure proper history evaluation. However, we forcefully reset the
65-
# branch to the workflow sha because it is possible that the branch was updated
66-
# while the workflow was running, which prevents accidentally releasing un-evaluated
67-
# changes.
68-
- name: Setup | Checkout Repository on Release Branch
69-
uses: actions/checkout@v4
70-
with:
71-
ref: ${{ github.ref_name }}
72-
73-
- name: Setup | Force release branch to be at workflow sha
74-
run: |
75-
git reset --hard ${{ github.sha }}
76-
77-
- name: Action | Semantic Version Release
78-
id: release
79-
# Adjust tag with desired version if applicable.
80-
uses: python-semantic-release/python-semantic-release@v10.5.3
81-
with:
82-
github_token: ${{ secrets.GITHUB_TOKEN }}
83-
git_committer_name: "github-actions"
84-
git_committer_email: "actions@users.noreply.github.com"
85-
86-
- name: Publish | Upload to GitHub Release Assets
87-
uses: python-semantic-release/publish-action@v10.5.3
88-
if: steps.release.outputs.released == 'true'
89-
with:
90-
github_token: ${{ secrets.GITHUB_TOKEN }}
91-
tag: ${{ steps.release.outputs.tag }}
92-
93-
- name: Upload | Distribution Artifacts
94-
uses: actions/upload-artifact@v4
95-
with:
96-
name: distribution-artifacts
97-
path: dist
98-
if-no-files-found: error
99-
100-
outputs:
101-
released: ${{ steps.release.outputs.released || 'false' }}
102-
103-
deploy:
104-
# 1. Separate out the deploy step from the publish step to run each step at
105-
# the least amount of token privilege
106-
# 2. Also, deployments can fail, and its better to have a separate job if you need to retry
107-
# and it won't require reversing the release.
108-
runs-on: ubuntu-latest
109-
needs: release
110-
if: github.ref_name == 'main' && needs.release.outputs.released == 'true'
111-
112-
permissions:
113-
contents: read
114-
id-token: write
115-
116-
steps:
117-
- name: Setup | Download Build Artifacts
118-
uses: actions/download-artifact@v4
119-
id: artifact-download
120-
with:
121-
name: distribution-artifacts
122-
path: dist
123-
124-
- name: Publish to PyPi
125-
uses: pypa/gh-action-pypi-publish@release/v1
126-
with:
127-
packages-dir: dist
128-
user: __token__
129-
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}

.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/python-semantic-release@v10.5.3
42+
with:
43+
github_token: ${{ secrets.GITHUB_TOKEN }}
44+
git_committer_name: "github-actions"
45+
git_committer_email: "actions@users.noreply.github.com"
46+
47+
- name: Publish | Upload to GitHub Release Assets
48+
uses: python-semantic-release/publish-action@v10.5.3
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)