Skip to content

add release action that updates changelog#309

Open
mshafer-NI wants to merge 2 commits into
ni:mainfrom
mshafer-NI:dev/auto_update_changelog
Open

add release action that updates changelog#309
mshafer-NI wants to merge 2 commits into
ni:mainfrom
mshafer-NI:dev/auto_update_changelog

Conversation

@mshafer-NI

@mshafer-NI mshafer-NI commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

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.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for contributing! 👋

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_changelog job to the publish workflow.
  • Derive the package version from Poetry and update CHANGELOG.md using sed.
  • 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.

Comment thread .github/workflows/Publish-Package.yml
Comment thread .github/workflows/Publish-Package.yml
Comment thread .github/workflows/Publish-Package.yml Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

name: Update changelog
runs-on: ubuntu-latest
needs: [build_package]
if: github.event_name == 'release' || inputs.environment != 'none'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +116 to +117
- name: Check out repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, this is going to be fun to fix both...

@bkeryan bkeryan Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +122 to +126
- 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"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think this should be in the same job...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/" \

@bkeryan bkeryan Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants