mirror of
https://github.com/actions/deploy-pages.git
synced 2026-02-09 03:45:15 +00:00
bundle and fmt
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const nock = require('nock')
|
const nock = require('nock')
|
||||||
|
|
||||||
@@ -8,343 +7,343 @@ const fakeJwt =
|
|||||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w'
|
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w'
|
||||||
|
|
||||||
describe('Deployment', () => {
|
describe('Deployment', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env.ACTIONS_RUNTIME_URL = 'http://my-url/'
|
process.env.ACTIONS_RUNTIME_URL = 'http://my-url/'
|
||||||
process.env.GITHUB_RUN_ID = '123'
|
process.env.GITHUB_RUN_ID = '123'
|
||||||
process.env.ACTIONS_RUNTIME_TOKEN = 'a-token'
|
process.env.ACTIONS_RUNTIME_TOKEN = 'a-token'
|
||||||
process.env.GITHUB_REPOSITORY = 'actions/is-awesome'
|
process.env.GITHUB_REPOSITORY = 'actions/is-awesome'
|
||||||
process.env.GITHUB_TOKEN = 'gha-token'
|
process.env.GITHUB_TOKEN = 'gha-token'
|
||||||
process.env.GITHUB_SHA = '123abc'
|
process.env.GITHUB_SHA = '123abc'
|
||||||
process.env.GITHUB_ACTOR = 'monalisa'
|
process.env.GITHUB_ACTOR = 'monalisa'
|
||||||
process.env.GITHUB_ACTION = '__monalisa/octocat'
|
process.env.GITHUB_ACTION = '__monalisa/octocat'
|
||||||
process.env.GITHUB_ACTION_PATH = 'something'
|
process.env.GITHUB_ACTION_PATH = 'something'
|
||||||
|
|
||||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'artifact_name':
|
case 'artifact_name':
|
||||||
return 'github-pages'
|
return 'github-pages'
|
||||||
case 'token':
|
case 'token':
|
||||||
return process.env.GITHUB_TOKEN
|
return process.env.GITHUB_TOKEN
|
||||||
default:
|
default:
|
||||||
return process.env[`INPUT_${param.toUpperCase()}`] || ''
|
return process.env[`INPUT_${param.toUpperCase()}`] || ''
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
jest.spyOn(core, 'setOutput').mockImplementation(param => {
|
|
||||||
return param
|
|
||||||
})
|
|
||||||
|
|
||||||
jest.spyOn(core, 'setFailed').mockImplementation(param => {
|
|
||||||
return param
|
|
||||||
})
|
|
||||||
// Mock error/warning/info/debug
|
|
||||||
jest.spyOn(core, 'error').mockImplementation(jest.fn())
|
|
||||||
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
|
|
||||||
jest.spyOn(core, 'info').mockImplementation(jest.fn())
|
|
||||||
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#create', () => {
|
|
||||||
afterEach(() => {
|
|
||||||
// Remove mock for `core.getInput('preview')`
|
|
||||||
delete process.env.INPUT_PREVIEW
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can successfully create a deployment', async () => {
|
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
|
||||||
|
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
|
||||||
.reply(200, {
|
|
||||||
value: [
|
|
||||||
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
|
||||||
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
|
||||||
oidc_token: fakeJwt
|
|
||||||
})
|
|
||||||
.reply(200, {
|
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
|
||||||
})
|
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
|
||||||
|
|
||||||
// Create the deployment
|
|
||||||
const deployment = new Deployment()
|
|
||||||
await deployment.create(fakeJwt)
|
|
||||||
|
|
||||||
expect(core.setFailed).not.toHaveBeenCalled()
|
|
||||||
expect(core.info).toHaveBeenLastCalledWith(
|
|
||||||
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
|
||||||
)
|
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can successfully create a preview deployment', async () => {
|
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
|
||||||
|
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
|
||||||
.reply(200, {
|
|
||||||
value: [
|
|
||||||
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
|
||||||
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
|
||||||
oidc_token: fakeJwt,
|
|
||||||
preview: true
|
|
||||||
})
|
|
||||||
.reply(200, {
|
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
|
||||||
page_url: 'https://actions.github.io/is-awesome',
|
|
||||||
preview_url: 'https://actions.drafts.github.io/is-awesome'
|
|
||||||
})
|
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
|
||||||
|
|
||||||
// Return `"true"` for `core.getInput("preview")`
|
|
||||||
process.env.INPUT_PREVIEW = 'true'
|
|
||||||
|
|
||||||
// Create the deployment
|
|
||||||
const deployment = new Deployment()
|
|
||||||
await deployment.create(fakeJwt)
|
|
||||||
|
|
||||||
expect(core.setFailed).not.toHaveBeenCalled()
|
|
||||||
expect(core.info).toHaveBeenLastCalledWith(
|
|
||||||
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
|
||||||
)
|
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('reports errors with failed artifact exchange', async () => {
|
|
||||||
process.env.GITHUB_SHA = 'invalid-build-version'
|
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
|
||||||
.reply(400, {})
|
|
||||||
|
|
||||||
// Create the deployment
|
|
||||||
const deployment = new Deployment()
|
|
||||||
await expect(deployment.create()).rejects.toEqual(
|
|
||||||
new Error(
|
|
||||||
`Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad Request`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('reports errors with a failed 500 in a deployment', async () => {
|
jest.spyOn(core, 'setOutput').mockImplementation(param => {
|
||||||
process.env.GITHUB_SHA = 'build-version'
|
return param
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
|
||||||
})
|
|
||||||
.reply(500, { message: 'oh no' })
|
|
||||||
|
|
||||||
// Create the deployment
|
|
||||||
const deployment = new Deployment()
|
|
||||||
await expect(deployment.create()).rejects.toEqual(
|
|
||||||
new Error(
|
|
||||||
`Failed to create deployment (status: 500) with build version ${process.env.GITHUB_SHA}. Server error, is githubstatus.com reporting a Pages outage? Please re-run the deployment at a later time.`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('reports errors with an unexpected 403 during deployment', async () => {
|
|
||||||
process.env.GITHUB_SHA = 'build-version'
|
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
|
||||||
})
|
|
||||||
.reply(403, { message: 'You are forbidden' })
|
|
||||||
|
|
||||||
// Create the deployment
|
|
||||||
const deployment = new Deployment()
|
|
||||||
await expect(deployment.create()).rejects.toEqual(
|
|
||||||
new Error(
|
|
||||||
`Failed to create deployment (status: 403) with build version ${process.env.GITHUB_SHA}. Ensure GITHUB_TOKEN has permission "pages: write".`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('reports errors with an unexpected 404 during deployment', async () => {
|
|
||||||
process.env.GITHUB_SHA = 'build-version'
|
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
|
||||||
})
|
|
||||||
.reply(404, { message: 'Not found' })
|
|
||||||
|
|
||||||
// Create the deployment
|
|
||||||
const deployment = new Deployment()
|
|
||||||
await expect(deployment.create()).rejects.toEqual(
|
|
||||||
new Error(
|
|
||||||
`Failed to create deployment (status: 404) with build version ${process.env.GITHUB_SHA}. Ensure GitHub Pages has been enabled: https://github.com/actions/is-awesome/settings/pages`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('reports errors with failed deployments', async () => {
|
|
||||||
process.env.GITHUB_SHA = 'invalid-build-version'
|
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
|
||||||
|
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
|
||||||
})
|
|
||||||
.reply(400, { message: 'Bad request' })
|
|
||||||
|
|
||||||
// Create the deployment
|
|
||||||
const deployment = new Deployment()
|
|
||||||
await expect(deployment.create()).rejects.toEqual(
|
|
||||||
new Error(
|
|
||||||
`Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad request`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
|
||||||
createDeploymentScope.done()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#check', () => {
|
jest.spyOn(core, 'setFailed').mockImplementation(param => {
|
||||||
it('sets output to success when deployment is successful', async () => {
|
return param
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
})
|
||||||
|
// Mock error/warning/info/debug
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
jest.spyOn(core, 'error').mockImplementation(jest.fn())
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
|
||||||
.reply(200, {
|
jest.spyOn(core, 'info').mockImplementation(jest.fn())
|
||||||
value: [
|
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
||||||
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
})
|
||||||
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
|
||||||
]
|
describe('#create', () => {
|
||||||
})
|
afterEach(() => {
|
||||||
|
// Remove mock for `core.getInput('preview')`
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
delete process.env.INPUT_PREVIEW
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
})
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
it('can successfully create a deployment', async () => {
|
||||||
oidc_token: fakeJwt
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
})
|
|
||||||
.reply(200, {
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
.reply(200, {
|
||||||
})
|
value: [
|
||||||
|
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
||||||
const deploymentStatusScope = nock('https://api.github.com')
|
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
||||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
]
|
||||||
.reply(200, {
|
|
||||||
status: 'succeed'
|
|
||||||
})
|
|
||||||
|
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
|
||||||
core.GetInput = jest.fn(input => {
|
|
||||||
switch (input) {
|
|
||||||
case 'timeout':
|
|
||||||
return 10 * 1000
|
|
||||||
case 'reporting_interval':
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create the deployment
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
const deployment = new Deployment()
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
await deployment.create(fakeJwt)
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
await deployment.check()
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
|
oidc_token: fakeJwt
|
||||||
expect(core.setOutput).toBeCalledWith('status', 'succeed')
|
})
|
||||||
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
.reply(200, {
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
artifactExchangeScope.done()
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
createDeploymentScope.done()
|
})
|
||||||
deploymentStatusScope.done()
|
|
||||||
})
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
|
// Create the deployment
|
||||||
|
const deployment = new Deployment()
|
||||||
|
await deployment.create(fakeJwt)
|
||||||
|
|
||||||
|
expect(core.setFailed).not.toHaveBeenCalled()
|
||||||
|
expect(core.info).toHaveBeenLastCalledWith(
|
||||||
|
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
||||||
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#cancel', () => {
|
it('can successfully create a preview deployment', async () => {
|
||||||
it('can successfully cancel a deployment', async () => {
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
|
||||||
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
const artifactExchangeScope = nock(`http://my-url`)
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.reply(200, {
|
||||||
.reply(200, {
|
value: [
|
||||||
value: [
|
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
||||||
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
||||||
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
]
|
||||||
]
|
})
|
||||||
})
|
|
||||||
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
const createDeploymentScope = nock('https://api.github.com')
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
oidc_token: fakeJwt,
|
||||||
oidc_token: fakeJwt
|
preview: true
|
||||||
})
|
})
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
page_url: 'https://actions.github.io/is-awesome'
|
page_url: 'https://actions.github.io/is-awesome',
|
||||||
})
|
preview_url: 'https://actions.drafts.github.io/is-awesome'
|
||||||
|
})
|
||||||
const cancelDeploymentScope = nock('https://api.github.com')
|
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
.reply(200, {})
|
|
||||||
|
// Return `"true"` for `core.getInput("preview")`
|
||||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
process.env.INPUT_PREVIEW = 'true'
|
||||||
|
|
||||||
// Create the deployment
|
// Create the deployment
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
await deployment.create(fakeJwt)
|
await deployment.create(fakeJwt)
|
||||||
|
|
||||||
// Cancel it
|
expect(core.setFailed).not.toHaveBeenCalled()
|
||||||
await deployment.cancel()
|
expect(core.info).toHaveBeenLastCalledWith(
|
||||||
|
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
||||||
expect(core.info).toHaveBeenLastCalledWith(`Canceled deployment with ID ${process.env.GITHUB_SHA}`)
|
)
|
||||||
|
|
||||||
artifactExchangeScope.done()
|
artifactExchangeScope.done()
|
||||||
createDeploymentScope.done()
|
createDeploymentScope.done()
|
||||||
cancelDeploymentScope.done()
|
})
|
||||||
})
|
|
||||||
|
it('reports errors with failed artifact exchange', async () => {
|
||||||
|
process.env.GITHUB_SHA = 'invalid-build-version'
|
||||||
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
|
.reply(400, {})
|
||||||
|
|
||||||
|
// Create the deployment
|
||||||
|
const deployment = new Deployment()
|
||||||
|
await expect(deployment.create()).rejects.toEqual(
|
||||||
|
new Error(
|
||||||
|
`Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad Request`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('reports errors with a failed 500 in a deployment', async () => {
|
||||||
|
process.env.GITHUB_SHA = 'build-version'
|
||||||
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
|
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||||
|
pages_build_version: process.env.GITHUB_SHA
|
||||||
|
})
|
||||||
|
.reply(500, { message: 'oh no' })
|
||||||
|
|
||||||
|
// Create the deployment
|
||||||
|
const deployment = new Deployment()
|
||||||
|
await expect(deployment.create()).rejects.toEqual(
|
||||||
|
new Error(
|
||||||
|
`Failed to create deployment (status: 500) with build version ${process.env.GITHUB_SHA}. Server error, is githubstatus.com reporting a Pages outage? Please re-run the deployment at a later time.`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('reports errors with an unexpected 403 during deployment', async () => {
|
||||||
|
process.env.GITHUB_SHA = 'build-version'
|
||||||
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
|
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||||
|
pages_build_version: process.env.GITHUB_SHA
|
||||||
|
})
|
||||||
|
.reply(403, { message: 'You are forbidden' })
|
||||||
|
|
||||||
|
// Create the deployment
|
||||||
|
const deployment = new Deployment()
|
||||||
|
await expect(deployment.create()).rejects.toEqual(
|
||||||
|
new Error(
|
||||||
|
`Failed to create deployment (status: 403) with build version ${process.env.GITHUB_SHA}. Ensure GITHUB_TOKEN has permission "pages: write".`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('reports errors with an unexpected 404 during deployment', async () => {
|
||||||
|
process.env.GITHUB_SHA = 'build-version'
|
||||||
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
|
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||||
|
pages_build_version: process.env.GITHUB_SHA
|
||||||
|
})
|
||||||
|
.reply(404, { message: 'Not found' })
|
||||||
|
|
||||||
|
// Create the deployment
|
||||||
|
const deployment = new Deployment()
|
||||||
|
await expect(deployment.create()).rejects.toEqual(
|
||||||
|
new Error(
|
||||||
|
`Failed to create deployment (status: 404) with build version ${process.env.GITHUB_SHA}. Ensure GitHub Pages has been enabled: https://github.com/actions/is-awesome/settings/pages`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('reports errors with failed deployments', async () => {
|
||||||
|
process.env.GITHUB_SHA = 'invalid-build-version'
|
||||||
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
|
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||||
|
pages_build_version: process.env.GITHUB_SHA
|
||||||
|
})
|
||||||
|
.reply(400, { message: 'Bad request' })
|
||||||
|
|
||||||
|
// Create the deployment
|
||||||
|
const deployment = new Deployment()
|
||||||
|
await expect(deployment.create()).rejects.toEqual(
|
||||||
|
new Error(
|
||||||
|
`Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad request`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('#check', () => {
|
||||||
|
it('sets output to success when deployment is successful', async () => {
|
||||||
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
|
.reply(200, {
|
||||||
|
value: [
|
||||||
|
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
||||||
|
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
|
oidc_token: fakeJwt
|
||||||
|
})
|
||||||
|
.reply(200, {
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
})
|
||||||
|
|
||||||
|
const deploymentStatusScope = nock('https://api.github.com')
|
||||||
|
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
||||||
|
.reply(200, {
|
||||||
|
status: 'succeed'
|
||||||
|
})
|
||||||
|
|
||||||
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
core.GetInput = jest.fn(input => {
|
||||||
|
switch (input) {
|
||||||
|
case 'timeout':
|
||||||
|
return 10 * 1000
|
||||||
|
case 'reporting_interval':
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Create the deployment
|
||||||
|
const deployment = new Deployment()
|
||||||
|
await deployment.create(fakeJwt)
|
||||||
|
await deployment.check()
|
||||||
|
|
||||||
|
expect(core.setOutput).toBeCalledWith('status', 'succeed')
|
||||||
|
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
|
deploymentStatusScope.done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#cancel', () => {
|
||||||
|
it('can successfully cancel a deployment', async () => {
|
||||||
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
|
.reply(200, {
|
||||||
|
value: [
|
||||||
|
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
||||||
|
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
|
oidc_token: fakeJwt
|
||||||
|
})
|
||||||
|
.reply(200, {
|
||||||
|
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||||
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
|
})
|
||||||
|
|
||||||
|
const cancelDeploymentScope = nock('https://api.github.com')
|
||||||
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||||
|
.reply(200, {})
|
||||||
|
|
||||||
|
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||||
|
|
||||||
|
// Create the deployment
|
||||||
|
const deployment = new Deployment()
|
||||||
|
await deployment.create(fakeJwt)
|
||||||
|
|
||||||
|
// Cancel it
|
||||||
|
await deployment.cancel()
|
||||||
|
|
||||||
|
expect(core.info).toHaveBeenLastCalledWith(`Canceled deployment with ID ${process.env.GITHUB_SHA}`)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
|
cancelDeploymentScope.done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
21
dist/index.js
generated
vendored
21
dist/index.js
generated
vendored
@@ -4949,7 +4949,7 @@ FetchError.prototype.name = 'FetchError';
|
|||||||
|
|
||||||
let convert;
|
let convert;
|
||||||
try {
|
try {
|
||||||
convert = (__nccwpck_require__(2319).convert);
|
convert = (__nccwpck_require__(2877).convert);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
const INTERNALS = Symbol('Body internals');
|
const INTERNALS = Symbol('Body internals');
|
||||||
@@ -9781,7 +9781,7 @@ function wrappy (fn, cb) {
|
|||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 9432:
|
/***/ 1260:
|
||||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
@@ -9791,7 +9791,7 @@ const { RequestError } = __nccwpck_require__(537)
|
|||||||
const HttpStatusMessages = __nccwpck_require__(3703)
|
const HttpStatusMessages = __nccwpck_require__(3703)
|
||||||
|
|
||||||
// All variables we need from the runtime are loaded here
|
// All variables we need from the runtime are loaded here
|
||||||
const getContext = __nccwpck_require__(1319)
|
const getContext = __nccwpck_require__(7705)
|
||||||
|
|
||||||
async function processRuntimeResponse(res, requestOptions) {
|
async function processRuntimeResponse(res, requestOptions) {
|
||||||
// Parse the response body as JSON
|
// Parse the response body as JSON
|
||||||
@@ -9958,7 +9958,7 @@ module.exports = {
|
|||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 1319:
|
/***/ 7705:
|
||||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
@@ -9995,19 +9995,19 @@ module.exports = function getContext() {
|
|||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 2877:
|
/***/ 8782:
|
||||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
|
|
||||||
// All variables we need from the runtime are loaded here
|
// All variables we need from the runtime are loaded here
|
||||||
const getContext = __nccwpck_require__(1319)
|
const getContext = __nccwpck_require__(7705)
|
||||||
const {
|
const {
|
||||||
getSignedArtifactUrl,
|
getSignedArtifactUrl,
|
||||||
createPagesDeployment,
|
createPagesDeployment,
|
||||||
getPagesDeploymentStatus,
|
getPagesDeploymentStatus,
|
||||||
cancelPagesDeployment
|
cancelPagesDeployment
|
||||||
} = __nccwpck_require__(9432)
|
} = __nccwpck_require__(1260)
|
||||||
|
|
||||||
const temporaryErrorStatus = {
|
const temporaryErrorStatus = {
|
||||||
unknown_status: 'Unable to get deployment status.',
|
unknown_status: 'Unable to get deployment status.',
|
||||||
@@ -10098,6 +10098,7 @@ class Deployment {
|
|||||||
}
|
}
|
||||||
throw new Error(errorMessage)
|
throw new Error(errorMessage)
|
||||||
} else {
|
} else {
|
||||||
|
// istanbul ignore next
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10229,7 +10230,7 @@ module.exports = { Deployment }
|
|||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 2319:
|
/***/ 2877:
|
||||||
/***/ ((module) => {
|
/***/ ((module) => {
|
||||||
|
|
||||||
module.exports = eval("require")("encoding");
|
module.exports = eval("require")("encoding");
|
||||||
@@ -10412,8 +10413,8 @@ var __webpack_exports__ = {};
|
|||||||
|
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
|
|
||||||
const { Deployment } = __nccwpck_require__(2877)
|
const { Deployment } = __nccwpck_require__(8782)
|
||||||
const getContext = __nccwpck_require__(1319)
|
const getContext = __nccwpck_require__(7705)
|
||||||
|
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
|
|
||||||
|
|||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user