From a31e996d19c9c426b7953ea5faa840e18c990b2b Mon Sep 17 00:00:00 2001 From: Natalie Carey Date: Tue, 29 Aug 2023 15:54:26 +0100 Subject: [PATCH 1/3] Doing everything other than the NPM release automatically (as it can all be reversed if needed). --- scripts/utils/create-release-pr | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/utils/create-release-pr b/scripts/utils/create-release-pr index 46a6cb0af9..cee4cace79 100755 --- a/scripts/utils/create-release-pr +++ b/scripts/utils/create-release-pr @@ -118,6 +118,8 @@ const wait = time => new Promise((resolve) => setTimeout(resolve, time)) let isReadyToMerge = false const requiredReviews = 1 + await exec('npm install') + do { await wait(5000) await exec(`gh pr view ${prUrl} --json isDraft,reviewDecision,reviews,statusCheckRollup`, { hideStd: true }) @@ -168,13 +170,12 @@ const wait = time => new Promise((resolve) => setTimeout(resolve, time)) console.log('Tests pass, approval granted, ready to continue.') - console.log('To continue run these commands:') - console.log('') - console.log(`cd ${projectDir}`) + await exec(`gh pr merge ${prUrl} -m -d`) + await exec(`gh release create "v${newVersion}" --notes-file "${prBodyFile}" --target "main" --title "v${newVersion}" --latest`) console.log('') - console.log(`gh pr merge ${prUrl} -m -d`) + console.log('Everything other than the publish to NPM is complete, to publish to NPM run:') console.log('') - console.log(`gh release create "v${newVersion}" --notes-file "${prBodyFile}" --target "main" --title "v${newVersion}" --latest`) + console.log(`cd ${projectDir}`) console.log('') console.log('npm login') console.log('') From 44b1ef8d306a60f86b6cbb3003a0105763ea2efb Mon Sep 17 00:00:00 2001 From: Natalie Carey Date: Thu, 31 Aug 2023 12:07:08 +0100 Subject: [PATCH 2/3] Updated release instructions to cater for the script updates. --- internal_docs/releasing/releasing.md | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/internal_docs/releasing/releasing.md b/internal_docs/releasing/releasing.md index 5ff0d22791..67bbdaf29b 100644 --- a/internal_docs/releasing/releasing.md +++ b/internal_docs/releasing/releasing.md @@ -6,23 +6,17 @@ Before the release, the content designer needs to draft the release notes, based 2. Run `./scripts/prepare-release`. -3. Once someone has merged the pull request, [draft a new release on GitHub](https://github.com/alphagov/govuk-prototype-kit/releases) +3. When the script provides a Pull Request URL review it and approve when it's ready. -4. In Tag version and Release title, put v[version number], for example `v7.0.0`. +4. Once the script has finished checkout the *main* branch and pull the latest changes. -5. In the description, paste the relevant section from the release notes. +5. Sign in to npm (`npm login`), using the credentials for the govuk-prototype-kit npm user from Bitwarden. -6. Checkout the *main* branch and pull the latest changes. +6. Run `npm run clean-publish` and enter the one-time password when prompted. -7. Sign in to npm (`npm login`), using the credentials for the govuk-prototype-kit npm user from Bitwarden. +7. Run `npm logout` to log out from npm. -8. Run `npm run clean-publish` and enter the one-time password when prompted. - -9. Run `npm logout` to log out from npm. - -10. On GitHub, click 'Publish release'. - -11. Let the community know about the release +8. Let the community know about the release Write a brief summary with highlights from the release then send it to the following slack channels: @@ -33,4 +27,4 @@ Write a brief summary with highlights from the release then send it to the follo Make sure to send a link to the 'create a new prototype' page rather than the GitHub release page: https://prototype-kit.service.gov.uk/docs/create-new-prototype. -12. On the sprint board, move everything that's been released from the Ready for release column to the Done column +9. On the sprint board, move everything that's been released from the Ready for release column to the Done column From d41335f14959b4ac316b59c1e486a25ad9b8cb11 Mon Sep 17 00:00:00 2001 From: Natalie Carey Date: Thu, 31 Aug 2023 23:34:51 +0100 Subject: [PATCH 3/3] Adding npm user check. --- scripts/utils/create-release-pr | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/utils/create-release-pr b/scripts/utils/create-release-pr index cee4cace79..3e9e349b9a 100755 --- a/scripts/utils/create-release-pr +++ b/scripts/utils/create-release-pr @@ -14,12 +14,12 @@ function findIndexOfFirstMatchingLine (changelogLines, regExp) { .at(0) } -async function exec (command, { allowStderr = false, hideStd = false } = {}) { +async function exec (command, { allowStderr = false, hideStd = false, allowErrorCode = false } = {}) { const newVersion = await new Promise((resolve) => { console.log('running command', command) cp.exec(command, { cwd: projectDir }, (error, stdout, stderr) => { - if (error) { + if (error && !allowErrorCode) { console.log(`error: ${error.message}`) process.exit(14) } @@ -172,13 +172,28 @@ const wait = time => new Promise((resolve) => setTimeout(resolve, time)) await exec(`gh pr merge ${prUrl} -m -d`) await exec(`gh release create "v${newVersion}" --notes-file "${prBodyFile}" --target "main" --title "v${newVersion}" --latest`) + + let loggedInAsCorrectNpmUser = false + const correctNpmUser = 'govuk-prototype-kit' + + do { + await wait(2000) + const output = await exec('npm whoami', { allowStderr: true, allowErrorCode: true, hideStd: true }) + if (output === correctNpmUser) { + loggedInAsCorrectNpmUser = true + } else if (output) { + console.log(`Currently logged in as [${output}], should be loggd in as [${correctNpmUser}]. Run [npm login] in another terminal.`) + } else { + console.log(`Please log in as [${correctNpmUser}] to continue by running [npm login] in another terminal.`) + } + } while (!loggedInAsCorrectNpmUser) + console.log('') + console.log('logged in as the correct user') console.log('') console.log('Everything other than the publish to NPM is complete, to publish to NPM run:') console.log('') console.log(`cd ${projectDir}`) console.log('') - console.log('npm login') - console.log('') console.log('npm run clean-publish') console.log('') console.log('npm logout')