Skip to content

Commit

Permalink
Add option to create test release archive of any ref
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdebrux committed Jul 27, 2022
1 parent 3cf3c5d commit 7662dab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions __tests__/spec/update-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ describe('update.sh', () => {
}
}

async function _mktestPrototype (src) {
// Create a release archive from the HEAD we are running tests in
await utils.mkPrototype(src)
async function _mktestPrototype (src, { ref } = {}) {
// Create a release archive from a ref, or the HEAD we are running tests in
const archivePath = await utils.mkReleaseArchive({ ref })
await utils.mkPrototype(src, { archivePath })

// Create a git repo from the new release archive so we can see changes.
await execFilePromise('git', ['init'], { cwd: src })
Expand All @@ -226,12 +227,12 @@ describe('update.sh', () => {
await utils.mkPrototype(path.join(src, 'update'))
}

async function mktestPrototype (dest) {
const src = path.resolve(fixtureDir, 'prototype')
async function mktestPrototype (dest, { ref } = {}) {
const src = path.resolve(fixtureDir, ref ? `prototype-${ref}` : 'prototype')
try {
await fs.access(src)
} catch (error) {
await _mktestPrototype(src)
await _mktestPrototype(src, { ref })
}

if (dest) {
Expand Down
11 changes: 6 additions & 5 deletions __tests__/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ function getWorktreeCommit () {
return _worktreeCommit
}

function _mkReleaseArchiveOptions ({ archiveType = 'tar', dir } = {}) {
function _mkReleaseArchiveOptions ({ archiveType = 'tar', dir, ref } = {}) {
dir = dir || path.join(mkdtempSync(), '__fixtures__')
const commitRef = getWorktreeCommit()
const releaseName = process.env.KIT_JEST_RUN_ID
? getJestId() : commitRef
const commitRef = ref || getWorktreeCommit()
const releaseName = ref || (process.env.KIT_JEST_RUN_ID ? getJestId() : commitRef)
const name = `govuk-prototype-kit-${releaseName}`
const archive = path.format({ dir, name, ext: '.' + archiveType })

Expand All @@ -86,7 +85,7 @@ function _mkReleaseArchiveOptions ({ archiveType = 'tar', dir } = {}) {
}

/**
* Return a path to the release archive for the current git worktree
* Return a path to the release archive for a git ref
*
* Creates a release archive from the git HEAD for the project we are currently
* running tests in. This will include uncommitted changes for tracked files, but
Expand All @@ -95,6 +94,7 @@ function _mkReleaseArchiveOptions ({ archiveType = 'tar', dir } = {}) {
* @param {Object} [options]
* @param {string} [options.archiveType=tar] - The type of archive to make, tar or zip
* @param {string} [options.dir] - The folder to place the archive in, by default is a fixture folder in the temporary directory
* @param {string} [options.ref] - The branch or tag to archive, defaults to a stash of the worktree
* @returns {string} - The absolute path to the archive
*/
async function mkReleaseArchive (options) {
Expand Down Expand Up @@ -130,6 +130,7 @@ async function mkReleaseArchive (options) {
* @param {Object} [options]
* @param {string} [options.archiveType=tar] - The type of archive to make, tar or zip
* @param {string} [options.dir] - The folder to place the archive in, by default is a fixture folder in the temporary directory
* @param {string} [options.ref] - The branch or tag to archive, defaults to a stash of the worktree
* @returns {string} - The absolute path to the archive
*/
function mkReleaseArchiveSync (options) {
Expand Down

0 comments on commit 7662dab

Please sign in to comment.