Skip to content

Commit 27fdb18

Browse files
committed
adjusted publish and release workflows
1 parent a4880f4 commit 27fdb18

File tree

2 files changed

+67
-52
lines changed

2 files changed

+67
-52
lines changed

.github/workflows/publish.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: Upload Python Package
33
on:
44
release:
55
types: [created]
6+
workflow_call:
7+
inputs:
8+
version:
9+
required: true
10+
type: string
611

712
jobs:
813
deploy:
@@ -20,7 +25,8 @@ jobs:
2025
pip install build twine
2126
- name: Update version number
2227
run: |
23-
sed -i 's/version = ".*"/version = "${{ github.ref_name }}"/' pyproject.toml
28+
VERSION="${{ inputs.version || github.ref_name }}"
29+
sed -i "s/version = \".*\"/version = \"$VERSION\"/" pyproject.toml
2430
- name: Build and publish
2531
env:
2632
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}

.github/workflows/release.yml

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,67 @@
11
name: Create Release
22

33
on:
4-
workflow_dispatch:
4+
workflow_dispatch:
55

66
permissions:
7-
contents: write
7+
contents: write
88

99
jobs:
10-
release:
11-
runs-on: ubuntu-latest
12-
if: github.ref == 'refs/heads/master'
13-
14-
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v5
17-
18-
- name: Extract version and notes from CHANGELOG
19-
id: changelog
20-
run: |
21-
# Extract version from first ## [x.x.x] header
22-
VERSION=$(grep -m1 -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md)
23-
echo "version=$VERSION" >> $GITHUB_OUTPUT
24-
25-
# Extract release notes (content between first and second ## headers)
26-
NOTES=$(awk '/^## \['"$VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
27-
28-
# Handle multiline output
29-
{
30-
echo "notes<<EOF"
31-
echo "$NOTES"
32-
echo "EOF"
33-
} >> $GITHUB_OUTPUT
34-
35-
- name: Check if tag already exists
36-
id: check_tag
37-
run: |
38-
if git rev-parse "v${{ steps.changelog.outputs.version }}" >/dev/null 2>&1; then
39-
echo "exists=true" >> $GITHUB_OUTPUT
40-
else
41-
echo "exists=false" >> $GITHUB_OUTPUT
42-
fi
43-
44-
- name: Create Release
45-
if: steps.check_tag.outputs.exists == 'false'
46-
uses: softprops/action-gh-release@v2
47-
with:
48-
tag_name: ${{ steps.changelog.outputs.version }}
49-
name: v${{ steps.changelog.outputs.version }}
50-
body: ${{ steps.changelog.outputs.notes }}
51-
draft: false
52-
prerelease: false
53-
54-
- name: Skip release (tag exists)
55-
if: steps.check_tag.outputs.exists == 'true'
56-
run: |
57-
echo "⚠️ Tag v${{ steps.changelog.outputs.version }} already exists. Skipping release creation."
58-
exit 1
10+
release:
11+
runs-on: ubuntu-latest
12+
if: github.ref == 'refs/heads/master'
13+
outputs:
14+
version: ${{ steps.changelog.outputs.version }}
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v5
19+
20+
- name: Extract version and notes from CHANGELOG
21+
id: changelog
22+
run: |
23+
# Extract version from first ## [x.x.x] header
24+
VERSION=$(grep -m1 -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md)
25+
echo "version=$VERSION" >> $GITHUB_OUTPUT
26+
27+
# Extract release notes (content between first and second ## headers)
28+
NOTES=$(awk '/^## \['"$VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
29+
30+
# Handle multiline output
31+
{
32+
echo "notes<<EOF"
33+
echo "$NOTES"
34+
echo "EOF"
35+
} >> $GITHUB_OUTPUT
36+
37+
- name: Check if tag already exists
38+
id: check_tag
39+
run: |
40+
if git rev-parse "v${{ steps.changelog.outputs.version }}" >/dev/null 2>&1; then
41+
echo "exists=true" >> $GITHUB_OUTPUT
42+
else
43+
echo "exists=false" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: Create Release
47+
if: steps.check_tag.outputs.exists == 'false'
48+
uses: softprops/action-gh-release@v2
49+
with:
50+
tag_name: ${{ steps.changelog.outputs.version }}
51+
name: v${{ steps.changelog.outputs.version }}
52+
body: ${{ steps.changelog.outputs.notes }}
53+
draft: false
54+
prerelease: false
55+
56+
- name: Skip release (tag exists)
57+
if: steps.check_tag.outputs.exists == 'true'
58+
run: |
59+
echo "⚠️ Tag v${{ steps.changelog.outputs.version }} already exists. Skipping release creation."
60+
exit 1
61+
62+
publish:
63+
needs: release
64+
uses: ./.github/workflows/publish.yml
65+
with:
66+
version: ${{ needs.release.outputs.version }}
67+
secrets: inherit

0 commit comments

Comments
 (0)