-
Notifications
You must be signed in to change notification settings - Fork 0
chore: fix release.sh so release PRs pass CI, add publish-workflow.sh #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rohan-hotdata
wants to merge
2
commits into
main
Choose a base branch
from
chore/fix-release-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env bash | ||
| # Generate publish.yml for a package. Usage: publish-workflow.sh hotdata-framework | ||
| set -euo pipefail | ||
| pkg="${1:?package name}" | ||
| cat <<EOF | ||
| name: Publish to PyPI | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v[0-9]*' | ||
|
|
||
| concurrency: | ||
| group: pypi-publish-\${{ github.ref_name }} | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build distribution | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | ||
|
|
||
| - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 | ||
| with: | ||
| python-version: '3.12' | ||
|
|
||
| - name: Install build tooling | ||
| run: python -m pip install --upgrade build twine | ||
|
|
||
| - name: Verify tag matches pyproject version | ||
| run: | | ||
| if [[ ! "\$GITHUB_REF_NAME" =~ ^v[0-9] ]]; then | ||
| echo "Release tag '\$GITHUB_REF_NAME' must start with 'v' followed by a digit (e.g. v1.0.0)" >&2 | ||
| exit 1 | ||
| fi | ||
| tag="\${GITHUB_REF_NAME#v}" | ||
| pkg_version=\$(python -c "import tomllib,pathlib; print(tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version'])") | ||
| if [ "\$tag" != "\$pkg_version" ]; then | ||
| echo "Release tag (\$tag) does not match pyproject.toml version (\$pkg_version)" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Build sdist and wheel | ||
| run: python -m build | ||
|
|
||
| - name: Check distribution metadata | ||
| run: python -m twine check --strict dist/* | ||
|
|
||
| - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
|
|
||
| publish: | ||
| name: Publish to PyPI | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: pypi | ||
| url: https://pypi.org/p/${pkg} | ||
| permissions: | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
|
|
||
| - name: Publish via Trusted Publishing | ||
| uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 | ||
| EOF | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,9 +82,18 @@ PY | |
|
|
||
| default_branch() { | ||
| local remote="${1:-origin}" | ||
| git symbolic-ref --quiet "refs/remotes/${remote}/HEAD" 2>/dev/null | sed "s|refs/remotes/${remote}/||" \ | ||
| || { git branch -r | sed -n "s|^ ${remote}/\\(main\\|master\\)$|\\1|p" | head -1; } \ | ||
| || echo main | ||
| local branch | ||
| branch="$(git symbolic-ref --quiet "refs/remotes/${remote}/HEAD" 2>/dev/null | sed "s|refs/remotes/${remote}/||")" | ||
| if [[ -n "$branch" ]]; then | ||
| echo "$branch" | ||
| return | ||
| fi | ||
| branch="$(git branch -r --list "${remote}/main" "${remote}/master" | sed "s|^[[:space:]]*${remote}/||" | head -1)" | ||
| if [[ -n "$branch" ]]; then | ||
| echo "$branch" | ||
| return | ||
| fi | ||
| echo main | ||
| } | ||
|
|
||
| ensure_clean() { | ||
|
|
@@ -103,6 +112,7 @@ cmd_prepare() { | |
| [[ -n "$bump" ]] || { usage; die "missing bump kind or explicit version"; } | ||
| need gh | ||
| need python3 | ||
| need uv | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: |
||
| ensure_clean | ||
|
|
||
| local current new base branch pkg | ||
|
|
@@ -122,10 +132,12 @@ cmd_prepare() { | |
|
|
||
| set_version "$new" | ||
| update_changelog "$new" | ||
| # uv.lock records this project's own version, and CI installs with --locked. | ||
| uv lock | ||
|
|
||
| branch="release/v${new}" | ||
| git checkout -b "$branch" | ||
| git add pyproject.toml CHANGELOG.md | ||
| git add pyproject.toml CHANGELOG.md uv.lock | ||
| git commit -m "chore: release v${new}" | ||
|
|
||
| pkg="$(get_pkg_name)" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: this makes the generator a second source of truth for
.github/workflows/publish.ymlwith nothing keeping the two in sync — a hand-edit to the workflow (e.g. bumping a pinned action SHA) would be silently reverted the next time someone regenerates. A one-line CI check (./scripts/publish-workflow.sh <pkg> | diff - .github/workflows/publish.yml) would catch drift. (not blocking)