Skip to content

Commit 1988a90

Browse files
committed
worflow for package publish + auto version bump commit on release
1 parent 4d07c41 commit 1988a90

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

.github/pypi.yaml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Publish package to PyPi
2+
3+
on:
4+
release:
5+
types: [released, prereleased]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Set up Python 3.12
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.12'
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v5
23+
24+
- name: Install python-build and twine
25+
run: |
26+
uv pip install --system build twine
27+
uv pip list --system
28+
29+
- name: Set env
30+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
31+
32+
33+
- name: Update Version
34+
run: |
35+
sed -i '/version =/ s/= "[^"][^"]*"/ = "${{ env.RELEASE_VERSION }}"/' pyproject.toml
36+
sed -i '/__version__ =/ s/= "[^"][^"]*"/ = "${{ env.RELEASE_VERSION }}"/' servicex_analysis_utils/__init__.py
37+
38+
39+
- name: Build a sdist and wheel
40+
run: |
41+
python -m build .
42+
43+
- name: Check dist
44+
run: twine check --strict dist/*
45+
46+
- name: List contents of sdist
47+
run: python -m tarfile --list dist/servicex_analysis_utils-*.tar.gz
48+
49+
- name: List contents of wheel
50+
run: python -m zipfile --list dist/servicex_analysis_utils-*.whl
51+
52+
- name: Upload an artifact of dist
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: dist-gha-artifact
56+
path: dist
57+
58+
publish:
59+
needs: build
60+
runs-on: ubuntu-latest
61+
62+
permissions:
63+
id-token: write # required to push with trusted-pypi-token
64+
65+
steps:
66+
- name: Set up Python 3.12
67+
uses: actions/setup-python@v5
68+
with:
69+
python-version: '3.12'
70+
71+
- name: Download artifact
72+
uses: actions/download-artifact@v4
73+
with:
74+
name: dist-gha-artifact
75+
path: dist
76+
77+
- name: Publish distribution
78+
if: github.repository == 'ssl-hep/ServiceX_analysis_utils'
79+
if: github.ref == 'refs/heads/main'
80+
uses: pypa/gh-action-pypi-publish@v1.12.3
81+
with:
82+
print-hash: true
83+
84+
commit version bump:
85+
needs: build, publish
86+
runs-on: ubuntu-latest
87+
permissions:
88+
contents: write # required to push with GITHUB_TOKEN
89+
90+
steps:
91+
- name: Checkout main branch
92+
uses: actions/checkout@v4
93+
with:
94+
ref: main
95+
96+
- name: Set up Python 3.12
97+
uses: actions/setup-python@v5
98+
with:
99+
python-version: '3.12'
100+
101+
- name: Set env
102+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
103+
104+
- name: Update version in pyproject.toml and __init__.py
105+
run: |
106+
sed -i '/version =/ s/= "[^"][^"]*"/ = "${{ env.RELEASE_VERSION }}"/' pyproject.toml
107+
sed -i '/__version__ =/ s/= "[^"][^"]*"/ = "${{ env.RELEASE_VERSION }}"/' servicex_analysis_utils/__init__.py
108+
109+
110+
- name: Commit version change
111+
run: |
112+
git config --local user.name "github-actions[bot]"
113+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
114+
git add pyproject.toml servicex_analysis_utils/__init__.py
115+
116+
# Check if there are changes to commit
117+
if ! git diff --cached --quiet; then
118+
echo "Changes detected, committing..."
119+
git commit -m "Update version to ${{ env.RELEASE_VERSION }}" --no-verify
120+
else
121+
echo "No changes to commit"
122+
fi
123+
124+
- name: Push commit to main
125+
# GITHUB_TOKEN is automatically provided
126+
run: |
127+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
128+
git push origin main

0 commit comments

Comments
 (0)