-
Notifications
You must be signed in to change notification settings - Fork 17
123 lines (113 loc) · 4.31 KB
/
publish.yml
File metadata and controls
123 lines (113 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Update Version, Test, Publish to PyPI, and Update GitHub Release
on:
release:
types: [created]
jobs:
build-test-publish-release:
runs-on: ubuntu-latest
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
contents: write #To create version branch
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.VERSION_PUSH_TOKEN }}
- name: Setup uv
uses: astral-sh/setup-uv@v3
- name: Set release version
run: |
# Get the tag from the GitHub release
TAG=${GITHUB_REF#refs/tags/}
# Remove 'v' prefix if present
VERSION=${TAG#v}
uvx hatch version $VERSION
- name: Build package
run: uvx hatch build
- name: Run tests
run: uvx hatch run test:pytest
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Verify PyPI Release
run: |
# Verify PyPI release
PACKAGE_NAME="mesa_frames"
CURRENT_VERSION=$(uvx hatch version)
uv pip install --system $PACKAGE_NAME==$CURRENT_VERSION
python -c "import mesa_frames; print(mesa_frames.__version__)"
- name: Update GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
dist/*
- name: Generate changelog from release notes
id: notes
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const tag = (context.payload.release && context.payload.release.tag_name)
? context.payload.release.tag_name
: (process.env.GITHUB_REF || '').replace('refs/tags/', '');
const body = (context.payload.release && context.payload.release.body) ? context.payload.release.body : '';
if (!body || body.trim().length === 0) {
core.setFailed('Release body is empty. Ensure the GitHub Release is created with auto-generated notes configured by .github/release.yml or supply a body.');
}
fs.writeFileSync('RELEASE_BODY.md', body, 'utf8');
core.setOutput('tag', tag);
- name: Prepend notes to CHANGELOG.md
env:
TAG: ${{ steps.notes.outputs.tag }}
run: |
VERSION_NO_V=${TAG#v}
DATE_UTC=$(date -u +%Y-%m-%d)
echo "## Version ${VERSION_NO_V} — ${DATE_UTC}" > RELEASE_HEADER.md
echo "" >> RELEASE_HEADER.md
if [ -f CHANGELOG.md ]; then
cat RELEASE_HEADER.md RELEASE_BODY.md CHANGELOG.md > CHANGELOG.new
else
cat RELEASE_HEADER.md RELEASE_BODY.md > CHANGELOG.new
fi
mv CHANGELOG.new CHANGELOG.md
- name: Commit and push CHANGELOG update
env:
TAG: ${{ steps.notes.outputs.tag }}
run: |
git config user.name github-actions
git config user.email [email protected]
# Ensure we are on the main branch before committing so the push lands on main.
git checkout main
git add CHANGELOG.md
# Avoid CI cycles
git commit -m "Changelog: add notes for ${TAG} [skip ci]" || echo "No changelog changes to commit"
git push origin main || true
- name: Create or recreate version branch
run: |
CURRENT_VERSION=$(uvx hatch version)
BRANCH_NAME="v$CURRENT_VERSION"
git config user.name github-actions
git config user.email [email protected]
# Delete the branch if it exists (both locally and remotely)
git branch -D $BRANCH_NAME || true
git push origin --delete $BRANCH_NAME || true
# Create and push the new branch
git checkout -b $BRANCH_NAME
git push -u origin $BRANCH_NAME
# Switch back to the main branch
git checkout main
- name: Update to Next Version
run: |
# Bump to next development version
uvx hatch version patch
uvx hatch version dev
# Get the new version
NEW_VERSION=$(uvx hatch version)
# Commit and push the version bump
git config user.name github-actions
git config user.email [email protected]
git add mesa_frames/__init__.py CHANGELOG.md
git commit -m "Bump version to $NEW_VERSION [skip ci]"
git push origin main