Repository navigation
[SPIKE] Explore extracting release script in a package - #2685
romaricpascal wants to merge 8 commits into
Conversation
e72a2bc to
04ce14b
Compare
This avoids the workflow to rely on `github.workspace`
7e2b38f to
3c8b56a
Compare
The workflow no longer needs a relative path and we can switch to a JS script transparently
Not much gain besides being regrouped with the rest of the release. The script can now receive the path to the CHANGELOG file to accomodate the CHANGELOG not being in the folder of the package whose version is being updated.
Avoids relying on GitHub actions script to run a single function
The function is only used in that script so makes sense for it to be there
65b30f1 to
386465e
Compare
386465e to
46cb63e
Compare
|
|
||
| # Save the new version number for access in future steps | ||
| echo "PACKAGE_VERSION=$(npm pkg get version | jq -r)" >> $GITHUB_ENV | ||
| echo "PACKAGE_VERSION=$(npm pkg get version | jq -r)" >> $GITHUB_OUTPUT |
There was a problem hiding this comment.
note Using $GITHUB_OUTPUT leads to using env in further steps, which makes visible where the environment variable comes from compared to outputting to $GITHUB_ENV. It also restricts the PACKAGE_VERSION environment to the steps that need it.
| generateReleaseNotes('CHANGELOG.md', `v${process.env.PACKAGE_VERSION}`, { actor: '${{ github.actor }}', runId: '${{ github.run_id }}' }) | ||
| run: npm exec extract-release-notes > release-notes-body | ||
| env: | ||
| PACKAGE_VERSION: v${{ steps.npm-version.outputs.PACKAGE_VERSION}} |
There was a problem hiding this comment.
note Not a big fan of that one, but worked for the spike. Thinking it'd be preferable that:
extract-release-notestakes on a non-prefixed version number- reading the packages version number is its own step, shared by
build-releaseandpublish-to-github
| await generateReleaseNotes('CHANGELOG.md', '${{ steps.create-github-tag.outputs.GH_TAG }}') | ||
| run: npm exec extract-release-notes > release-notes-body | ||
| env: | ||
| PACKAGE_VERSION: ${{ steps.create-github-tag.outputs.GH_TAG }} |
There was a problem hiding this comment.
note See previous note, but this should work off a non-prefixed version number read from package.json rather than the GitHub tag.
|
|
||
| if (require.main === module) { | ||
| (async () => { | ||
| const changelogPath = resolve(process.argv[2] ?? 'CHANGELOG.md') |
There was a problem hiding this comment.
note Possibly a silly one, the CHANGELOG would always be at the root of the repository, it's the package which might be in a nested folder.
| const { generateReleaseNotes } = await import('${{ github.workspace }}/scripts/release/changelog-release-helper.js') | ||
|
|
||
| generateReleaseNotes('CHANGELOG.md', `v${process.env.PACKAGE_VERSION}`, { actor: '${{ github.actor }}', runId: '${{ github.run_id }}' }) | ||
| run: npm exec extract-release-notes > release-notes-body |
There was a problem hiding this comment.
note Making the script log rather than write to file allows to keep mentions of release-notes-body to this file.
| * @returns {Array<number>} - Indexes in the changelog identifying start and end lines | ||
| */ | ||
| function getChangelogLineIndexes (changelogLines, heading = undefined) { | ||
| const startHeading = `## ${heading ?? 'Unreleased'}` |
There was a problem hiding this comment.
note This expects the heading to include the 'v' and does a similar formatting as updateChangelog so it might be worth extracting a function that ensures headings are formatted as expected both when injected and looked for.
There was a problem hiding this comment.
note This file only explores the shape a configuration file would take. If we had an actual package shared across repositories, the config file would be in the repository being released.
| const { outdent } = require('outdent') | ||
|
|
||
| module.exports = { | ||
| githubRepository: 'alphagov/govuk-prototype-kit', |
There was a problem hiding this comment.
note We can probably extract that from the package.json file, which would also ensure the git metadata is filled correctly.
| @@ -0,0 +1,73 @@ | |||
| const semver = require('semver') | |||
|
|
|||
| const { versionIsAPrerelease, getPrereleaseIdentifier } = require('./changelog-release-helper.js') | |||
There was a problem hiding this comment.
note Those could possibly live in this package 🤔
| "lint:fix": "npm run lint -- --fix", | ||
| "prepack": "npm ls --all", | ||
| "postversion": "node scripts/release/update-changelog.js", | ||
| "postversion": "update-changelog", |
There was a problem hiding this comment.
note Having @govuk-prototype-kit/release provide scripts in its bin field allows to invoke them directly. We'll likely want to have a clear naming here to help figure the provenance.
Explore how release scripts could be move in their own package for reuse across multiple repositories