Skip to content

Commit

Permalink
Fix update script test for fetch when releasing a new version
Browse files Browse the repository at this point in the history
Previously we were relying on VERSION.txt for the name of the latest
release, however this doesn't work in scenarios where we have changed
the version number in preperation but have not yet made the release, as
we found recently (see issue #1205).

Instead we get the latest release version using the GitHub API [[1]].
Note that we have to drop the `v` at the beginning of the tag name,
because for some reason GitHub doesn't include that in the archive file
name.

This commit uses the `superagent` library to do the request to avoid a
lot of boilerplate; note that we have to set the user agent to
something, because otherwise GitHub will forbid the request [[2]].

[1]: #1205 (comment)
[2]: ladjs/superagent#1495 (comment)
  • Loading branch information
lfdebrux committed Dec 16, 2021
1 parent aa6a4a2 commit 8b053f9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions __tests__/spec/update-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs')
const os = require('os')
const path = require('path')
const process = require('process')
const request = require('superagent')

/*
* Constants
Expand All @@ -12,12 +13,6 @@ const process = require('process')
const repoDir = path.resolve(__dirname, '..', '..')
const script = path.join(repoDir, 'update.sh')

const latestReleaseVersion = fs.readFileSync(
path.join(repoDir, 'VERSION.txt'), { encoding: 'utf8' }
).trim()
const latestReleaseBasename = `govuk-prototype-kit-${latestReleaseVersion}`
const latestReleaseArchiveFilename = `${latestReleaseBasename}.zip`

const headReleaseVersion = child_process.execSync(
'git rev-parse HEAD', { encoding: 'utf8' }
).trim()
Expand Down Expand Up @@ -306,7 +301,17 @@ describe('update.sh', () => {
})

describe('fetch', () => {
it('downloads the latest release of the prototype kit into the update folder', () => {
it('downloads the latest release of the prototype kit into the update folder', async () => {
// check what GitHub thinks the latest release archive is
var response = await request
.get('https://api.github.com/repos/alphagov/govuk-prototype-kit/releases/latest')
.set('user-agent', 'node-superagent (tests for govuk-prototype-kit)')

if (response.error) throw response.error
const latestRelease = response.body
const latestReleaseVersion = latestRelease.tag_name.trim().slice(1) // need to drop the prefix 'v'
const latestReleaseArchiveFilename = `govuk-prototype-kit-${latestReleaseVersion}.zip`

const testDir = 'fetch'
fs.mkdirSync(path.join(testDir, 'update'), { recursive: true })

Expand Down

0 comments on commit 8b053f9

Please sign in to comment.