Skip to content

Commit de8ccd9

Browse files
Merge pull request #2346 from alphagov/improvements-to-release-script
Completing the release script
2 parents c11a9e7 + fc8d0c8 commit de8ccd9

2 files changed

Lines changed: 42 additions & 13 deletions

File tree

internal_docs/releasing/releasing.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@ Before the release, the content designer needs to draft the release notes, based
66

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

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

11-
4. Once the script has finished checkout the *main* branch and pull the latest changes.
11+
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).
1212

13-
5. Sign in to npm (`npm login`), using the credentials for the govuk-prototype-kit npm user from Bitwarden.
14-
15-
6. Run `npm run clean-publish` and enter the one-time password when prompted.
16-
17-
7. Run `npm logout` to log out from npm.
18-
19-
8. Let the community know about the release
13+
5. Let the community know about the release
2014

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

@@ -27,4 +21,4 @@ Write a brief summary with highlights from the release then send it to the follo
2721

2822
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.
2923

30-
9. On the sprint board, move everything that's been released from the Ready for release column to the Done column
24+
6. On the sprint board, move everything that's been released from the Ready for release column to the Done column

scripts/utils/create-release-pr

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ function findIndexOfFirstMatchingLine (changelogLines, regExp) {
1414
.at(0)
1515
}
1616

17-
async function exec (command, { allowStderr = false, hideStd = false, allowErrorCode = false } = {}) {
17+
async function exec (command, { allowStderr = false, hideStd = false, allowErrorCode = false, inheritStd = true } = {}) {
1818
const newVersion = await new Promise((resolve) => {
1919
console.log('running command', command)
20-
cp.exec(command, { cwd: projectDir },
20+
const config = { cwd: projectDir }
21+
if (inheritStd) {
22+
config.stdio = 'pipe'
23+
}
24+
cp.exec(command, config,
2125
(error, stdout, stderr) => {
2226
if (error && !allowErrorCode) {
2327
console.log(`error: ${error.message}`)
@@ -44,6 +48,19 @@ async function exec (command, { allowStderr = false, hideStd = false, allowError
4448
return newVersion
4549
}
4650

51+
function spawnWithTty (command, args = []) {
52+
return new Promise((resolve, reject) => {
53+
const result = cp.spawn(command, args, { stdio: 'inherit' })
54+
result.on('exit', function (code, signal) {
55+
if (code === 0) {
56+
resolve()
57+
} else {
58+
reject(new Error('Command failed'))
59+
}
60+
})
61+
})
62+
}
63+
4764
const wait = time => new Promise((resolve) => setTimeout(resolve, time))
4865

4966
;(async () => {
@@ -188,7 +205,25 @@ const wait = time => new Promise((resolve) => setTimeout(resolve, time))
188205
}
189206
} while (!loggedInAsCorrectNpmUser)
190207

191-
await exec('npm run clean-publish')
208+
let isPublished = false
209+
210+
while (isPublished === false) {
211+
await spawnWithTty('npm', ['run', 'clean-publish'])
212+
.then(() => {
213+
isPublished = true
214+
console.log('')
215+
console.log('Publish successful')
216+
console.log('')
217+
})
218+
.catch(() => {
219+
console.warn('')
220+
console.warn('Something went wrong, trying again.')
221+
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:')
222+
console.warn('')
223+
console.warn('git checkout main && git fetch && git reset --hard origin/main && npm run clean-publish')
224+
console.warn('')
225+
})
226+
}
192227

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

0 commit comments

Comments
 (0)