add release action that updates changelog#309
Conversation
|
Thank you for contributing! 👋 |
There was a problem hiding this comment.
Pull request overview
This PR extends the existing publish workflow by adding an update_changelog job that computes the package version, updates CHANGELOG.md, and opens an automated pull request with the changelog changes.
Changes:
- Add a new
update_changelogjob to the publish workflow. - Derive the package version from Poetry and update
CHANGELOG.mdusingsed. - Create a PR with the changelog update via
peter-evans/create-pull-request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| name: Update changelog | ||
| runs-on: ubuntu-latest | ||
| needs: [build_package] | ||
| if: github.event_name == 'release' || inputs.environment != 'none' |
There was a problem hiding this comment.
I typically rerun publish workflows manually when something goes wrong and I would expect it to do all the work that it should have done the first time.
| - name: Check out repo | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
There was a problem hiding this comment.
This will not work when releasing out of "releases/X.Y". The default branch will be "main" or "master" and the PR targeting "releases/X.Y" will have merge conflicts and include inappropriate commits.
There was a problem hiding this comment.
hmmm, this is going to be fun to fix both...
There was a problem hiding this comment.
Here's how ni/python-actions/update-project-version determines the base branch: ${{ github.event_name == 'release' && github.event.release.target_commitish || github.ref_name }}
You could check out the base branch when updating the changelog.
However, ni/python-actions/update-project-version doesn't include the checkout step, so if we want that action to support releasing from an older commit tag, I think we need to break compatibility or make a 2nd checkout somewhere else.
Is releasing from an older commit tag really that important?
There was a problem hiding this comment.
BTW update-project-version has a workflow that relies on the client calling checkout: you can checkout, update-project-version on multiple projects, and set create-pull-request: false for all but the last one. Only the last call will create a PR.
| - name: Promote package version to release | ||
| run: poetry version patch | ||
| - name: Get package version | ||
| id: get-version | ||
| run: echo "version=$(poetry version -s)" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
This makes me think this should be in the same job...
There was a problem hiding this comment.
FYI: Have you looked at Towncrier? I don't think any of our public packages have high enough velocity to require something like that, but it's worth knowing about.
| - name: Update changelog | ||
| run: | | ||
| CHANGELOG_FILE="CHANGELOG.md" | ||
| VERSION="${{ steps.get-version.outputs.version }}" |
There was a problem hiding this comment.
Does zizmor flag this as https://docs.zizmor.sh/audits/#template-injection ?
It came from the previous step, so obviously it's not untrusted input.
You could potentially merge the steps, though.
| -e "s;\[Unreleased\]: \(\(.*/compare/\).*\)\.\.\.main;[Unreleased]: \2v${VERSION}...main\n[${VERSION}]: \1...v${VERSION};" \ | ||
| -i "${CHANGELOG_FILE}" | ||
| - name: Create Pull Request | ||
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 |
There was a problem hiding this comment.
FYI, we should consider using gh pr create for stuff like this: https://docs.zizmor.sh/audits/#superfluous-actions
That said, I realize this is easier said than done.
|
|
||
| # Create the new changelog entry | ||
| sed \ | ||
| -e "s/^## \[Unreleased\]/## [Unreleased]\n\n## [$VERSION] - $TODAY/" \ |
There was a problem hiding this comment.
This runs after the build, so it's updating the main/release branch for the next version.
Does that mean the tagged CHANGELOG.md for version X says [Unreleased] rather than version X? For nidaqmx-python, we have been updating CHANGELOG.md before each release so the tagged CHANGELOG.md lists the correct version.
| commit-message: 'docs: update changelog for ${{ steps.get-version.outputs.version }}' | ||
| title: 'docs: update changelog for ${{ steps.get-version.outputs.version }}' | ||
| body: 'Automatically generated changelog update for release ${{ steps.get-version.outputs.version }}' | ||
| branch: changelog-update-${{ steps.get-version.outputs.version }} |
There was a problem hiding this comment.
This has the wrong base branch when releasing out of "releases/X.Y"
See https://github.com/ni/python-actions/blob/main/update-project-version/action.yml#L101
Add a step to release pipeline that adds the new version to the changelog and posts a PR
testing:
Used local WSL instance to run sed commands and confirm output.
The result will be a PR, so, not too worried if it's not perfect.