Skip to content

Commit

Permalink
Merge pull request #2346 from alphagov/improvements-to-release-script
Browse files Browse the repository at this point in the history
Completing the release script
  • Loading branch information
BenSurgisonGDS authored Sep 28, 2023
2 parents c11a9e7 + fc8d0c8 commit de8ccd9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
14 changes: 4 additions & 10 deletions internal_docs/releasing/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ Before the release, the content designer needs to draft the release notes, based

2. Run `./scripts/prepare-release`.

3. When the script provides a Pull Request URL review it and approve when it's ready.
3. When the script provides a Pull Request URL review it, approve it and merge when it's ready.

4. Once the script has finished checkout the *main* branch and pull the latest changes.
4. Let the script finish, if it fails to release it should provide instructions, if not it's worth looking back at [an older copy of the release notes for manual releasing](https://github.com/alphagov/govuk-prototype-kit/blob/v13.5.0/internal_docs/releasing/releasing.md).

5. Sign in to npm (`npm login`), using the credentials for the govuk-prototype-kit npm user from Bitwarden.

6. Run `npm run clean-publish` and enter the one-time password when prompted.

7. Run `npm logout` to log out from npm.

8. Let the community know about the release
5. Let the community know about the release

Write a brief summary with highlights from the release then send it to the following slack channels:

Expand All @@ -27,4 +21,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.

9. On the sprint board, move everything that's been released from the Ready for release column to the Done column
6. On the sprint board, move everything that's been released from the Ready for release column to the Done column
41 changes: 38 additions & 3 deletions scripts/utils/create-release-pr
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ function findIndexOfFirstMatchingLine (changelogLines, regExp) {
.at(0)
}

async function exec (command, { allowStderr = false, hideStd = false, allowErrorCode = false } = {}) {
async function exec (command, { allowStderr = false, hideStd = false, allowErrorCode = false, inheritStd = true } = {}) {
const newVersion = await new Promise((resolve) => {
console.log('running command', command)
cp.exec(command, { cwd: projectDir },
const config = { cwd: projectDir }
if (inheritStd) {
config.stdio = 'pipe'
}
cp.exec(command, config,
(error, stdout, stderr) => {
if (error && !allowErrorCode) {
console.log(`error: ${error.message}`)
Expand All @@ -44,6 +48,19 @@ async function exec (command, { allowStderr = false, hideStd = false, allowError
return newVersion
}

function spawnWithTty (command, args = []) {
return new Promise((resolve, reject) => {
const result = cp.spawn(command, args, { stdio: 'inherit' })
result.on('exit', function (code, signal) {
if (code === 0) {
resolve()
} else {
reject(new Error('Command failed'))
}
})
})
}

const wait = time => new Promise((resolve) => setTimeout(resolve, time))

;(async () => {
Expand Down Expand Up @@ -188,7 +205,25 @@ const wait = time => new Promise((resolve) => setTimeout(resolve, time))
}
} while (!loggedInAsCorrectNpmUser)

await exec('npm run clean-publish')
let isPublished = false

while (isPublished === false) {
await spawnWithTty('npm', ['run', 'clean-publish'])
.then(() => {
isPublished = true
console.log('')
console.log('Publish successful')
console.log('')
})
.catch(() => {
console.warn('')
console.warn('Something went wrong, trying again.')
console.warn('If you don\'t want to try again exit this process. If you want to run the rest of the release manually run:')
console.warn('')
console.warn('git checkout main && git fetch && git reset --hard origin/main && npm run clean-publish')
console.warn('')
})
}

await exec('npm logout')
})()

0 comments on commit de8ccd9

Please sign in to comment.