Skip to content

Commit 0ef1ae4

Browse files
committed
Implemented auto release to PyPI
1 parent c0eee04 commit 0ef1ae4

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

.github/workflows/release.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
# Branches that should auto-publish snapshot releases to GitHub.
6+
branches:
7+
- main
8+
- "release/**"
9+
- "hotfix/**"
10+
# Tags that should publish official releases.
11+
tags:
12+
- "v*"
13+
workflow_dispatch:
14+
15+
jobs:
16+
build:
17+
name: Build Distributions
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Set Up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.12"
28+
29+
- name: Install Build Tooling
30+
run: |
31+
python -m pip install --upgrade pip
32+
python -m pip install --upgrade build twine
33+
34+
- name: Build sdist and wheel
35+
run: python -m build
36+
37+
- name: Validate Artifacts
38+
run: python -m twine check dist/*
39+
40+
- name: Upload Dist Artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: dist
44+
path: dist/
45+
46+
github_snapshot_release:
47+
name: GitHub Snapshot Release
48+
needs: build
49+
runs-on: ubuntu-latest
50+
if: github.ref_type == 'branch' && (github.ref_name == 'main' || startsWith(github.ref_name, 'release/') || startsWith(github.ref_name, 'hotfix/'))
51+
permissions:
52+
contents: write
53+
54+
steps:
55+
- name: Download Dist Artifact
56+
uses: actions/download-artifact@v4
57+
with:
58+
name: dist
59+
path: dist/
60+
61+
- name: Create Branch Snapshot Release
62+
env:
63+
GH_TOKEN: ${{ github.token }}
64+
run: |
65+
BRANCH_SLUG="${GITHUB_REF_NAME//\//-}"
66+
TAG="snapshot-${BRANCH_SLUG}-${GITHUB_RUN_NUMBER}"
67+
TITLE="Snapshot ${GITHUB_REF_NAME} #${GITHUB_RUN_NUMBER}"
68+
NOTES="Automated snapshot release for branch '${GITHUB_REF_NAME}' at commit ${GITHUB_SHA}."
69+
70+
gh release create "$TAG" dist/* \
71+
--target "$GITHUB_SHA" \
72+
--title "$TITLE" \
73+
--notes "$NOTES" \
74+
--prerelease
75+
76+
github_tag_release:
77+
name: GitHub Tag Release
78+
needs: build
79+
runs-on: ubuntu-latest
80+
if: startsWith(github.ref, 'refs/tags/v')
81+
permissions:
82+
contents: write
83+
84+
steps:
85+
- name: Download Dist Artifact
86+
uses: actions/download-artifact@v4
87+
with:
88+
name: dist
89+
path: dist/
90+
91+
- name: Publish GitHub Release
92+
uses: softprops/action-gh-release@v2
93+
with:
94+
files: dist/*
95+
generate_release_notes: true
96+
97+
pypi_publish:
98+
name: Publish To PyPI
99+
needs: build
100+
runs-on: ubuntu-latest
101+
if: startsWith(github.ref, 'refs/tags/v')
102+
permissions:
103+
id-token: write
104+
environment:
105+
name: pypi
106+
url: https://pypi.org/p/reptrace
107+
108+
steps:
109+
- name: Download Dist Artifact
110+
uses: actions/download-artifact@v4
111+
with:
112+
name: dist
113+
path: dist/
114+
115+
- name: Publish Distributions
116+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)