Skip to content

Commit a82b13f

Browse files
ci: fix release
Signed-off-by: jaapschoutenalliander <[email protected]>
1 parent a6d3654 commit a82b13f

File tree

2 files changed

+157
-191
lines changed

2 files changed

+157
-191
lines changed

.github/workflows/build-test-release.yml

Lines changed: 0 additions & 186 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 157 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,167 @@ jobs:
2828
steps:
2929
- run: echo "ci started"
3030

31-
build-test-release:
31+
build-python:
3232
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
33-
name: build-test-release
34-
uses: "./.github/workflows/build-test-release.yml"
33+
runs-on: ubuntu-latest
34+
outputs:
35+
version: ${{ steps.version.outputs.version }}
36+
steps:
37+
- name: Checkout source code
38+
uses: actions/checkout@v5
39+
40+
- name: Install uv
41+
uses: astral-sh/setup-uv@v6
42+
if: ${{ always() }}
43+
with:
44+
activate-environment: true
45+
enable-cache: true
46+
47+
- name: Install dependencies
48+
if: ${{ always() }}
49+
run: uv sync --frozen
50+
51+
- name: Set PyPI version
52+
uses: PowerGridModel/pgm-version-bump@main
53+
with:
54+
token: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Save version
57+
id: version
58+
run: echo "version=$(cat PYPI_VERSION)" >> $GITHUB_OUTPUT
59+
60+
- name: Build
61+
run: |
62+
uv build
63+
64+
- name: Store built wheel file
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: power-grid-model-ds
68+
path: dist/
69+
70+
tests:
71+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
72+
needs: build-python
73+
strategy:
74+
matrix:
75+
os: [ ubuntu-latest, macos-latest, windows-latest ]
76+
python: ["3.11", "3.12", "3.13"]
77+
fail-fast: false
78+
runs-on: ${{ matrix.os }}
79+
steps:
80+
- name: Checkout source code
81+
uses: actions/checkout@v5
82+
83+
- name: Install uv
84+
uses: astral-sh/setup-uv@v6
85+
if: ${{ always() }}
86+
with:
87+
activate-environment: true
88+
enable-cache: true
89+
90+
- name: install poe
91+
run: uv tool install poethepoet
92+
93+
- name: Load built wheel file
94+
uses: actions/download-artifact@v4
95+
with:
96+
name: power-grid-model-ds
97+
path: dist/
98+
99+
- name: Install built wheel file
100+
run: uv pip install power-grid-model-ds[dev]==${{ needs.build-python.outputs.version }} --find-links=dist
101+
102+
- name: Run All Code Quality Checks & Tests
103+
run: poe all --check
104+
105+
github-release:
106+
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' && inputs.create_release }}
107+
needs:
108+
- build-python
109+
- tests
110+
permissions:
111+
contents: write
112+
runs-on: ubuntu-latest
113+
outputs:
114+
tag: ${{ steps.tag.outputs.tag }}
115+
steps:
116+
- name: Checkout source code
117+
uses: actions/checkout@v5
118+
119+
- name: Load built wheel file
120+
uses: actions/download-artifact@v4
121+
with:
122+
name: power-grid-model-ds
123+
path: dist/
124+
125+
- name: Prevent automatic major/minor release
126+
run: |
127+
echo "Fetching the latest release..."
128+
tag=$(gh release view --json tagName --jq '.tagName' || echo "v0.0.0")
129+
tag=${tag#v} # Remove the leading 'v'
130+
major_minor=$(echo "$tag" | cut -d. -f1,2)
131+
version_file=$(cat VERSION)
132+
133+
if [ "$major_minor" = "$version_file" ]; then
134+
echo "Patch release detected. Proceeding with automatic release."
135+
else
136+
echo "Cannot automatically release a new major/minor version. Please trigger manually if desired."
137+
exit 1
138+
fi
139+
env:
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141+
142+
- name: Get tag
143+
id: tag
144+
run: echo "tag=v${{ needs.build-python.outputs.version }}" >> $GITHUB_OUTPUT
145+
146+
- name: Display tag
147+
run: echo "${{ steps.tag.outputs.tag }}"
148+
149+
- name: Release
150+
uses: softprops/action-gh-release@v2
151+
with:
152+
files: |
153+
./dist/*
154+
tag_name: ${{ steps.tag.outputs.tag }}
155+
generate_release_notes: true
156+
target_commitish: ${{ github.sha }}
157+
158+
publish:
159+
name: Publish to PyPI
160+
if: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' && inputs.create_release }}
161+
needs: github-release
162+
runs-on: ubuntu-latest
35163
permissions:
36164
contents: write
37165
id-token: write # Required for Trusted Publishing
38-
with:
39-
create_release: ${{ inputs.create_release }}
166+
steps:
167+
- name: Download assets from latest GitHub release using gh CLI
168+
env:
169+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
170+
run: |
171+
mkdir -p assets-to-publish
172+
release_tag="${{ needs.github-release.outputs.tag }}"
173+
gh release download "$release_tag" --repo "$GITHUB_REPOSITORY" --dir assets-to-publish
174+
175+
- name: List downloaded assets
176+
run: ls -la assets-to-publish
177+
178+
- name: Upload assets to PyPI
179+
uses: pypa/gh-action-pypi-publish@release/v1
180+
with:
181+
# To test, use the TestPyPI:
182+
# repository-url: https://test.pypi.org/legacy/
183+
# You must also create an account and project on TestPyPI,
184+
# as well as set the trusted-publisher in the project settings:
185+
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
186+
# To publish to the official PyPI repository, just keep
187+
# repository-url commented out.
188+
packages-dir: assets-to-publish
189+
skip-existing: true
190+
print-hash: true
191+
verbose: true
40192

41193
check-code-quality:
42194
uses: "./.github/workflows/check-code-quality.yml"

0 commit comments

Comments
 (0)