mirror of
https://github.com/actions/deploy-pages.git
synced 2025-12-08 08:06:15 +00:00
Merge pull request #61 from actions/upstream-preview-alpha
Add support for preview deployments internal alpha experiment 🧪
This commit is contained in:
@@ -29,6 +29,10 @@ inputs:
|
||||
description: 'Name of the artifact to deploy'
|
||||
required: false
|
||||
default: 'github-pages'
|
||||
preview:
|
||||
description: 'Is this attempting to deploy a pull request as a GitHub Pages preview site? (NOTE: This feature is only in alpha currently and is not available to the public!)'
|
||||
required: false
|
||||
default: 'false'
|
||||
outputs:
|
||||
page_url:
|
||||
description: 'URL to deployed GitHub Pages'
|
||||
|
||||
14
dist/index.js
vendored
14
dist/index.js
vendored
@@ -8177,7 +8177,8 @@ function getRequiredVars() {
|
||||
actionsId: process.env.GITHUB_ACTION,
|
||||
githubToken: core.getInput('token'),
|
||||
githubApiUrl: process.env.GITHUB_API_URL ?? 'https://api.github.com',
|
||||
artifactName: core.getInput('artifact_name') ?? 'github-pages'
|
||||
artifactName: core.getInput('artifact_name') ?? 'github-pages',
|
||||
isPreview: core.getInput('preview') === 'true'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8227,6 +8228,7 @@ class Deployment {
|
||||
this.deploymentInfo = null
|
||||
this.githubApiUrl = context.githubApiUrl
|
||||
this.artifactName = context.artifactName
|
||||
this.isPreview = context.isPreview === true
|
||||
}
|
||||
|
||||
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
|
||||
@@ -8258,6 +8260,9 @@ class Deployment {
|
||||
pages_build_version: this.buildVersion,
|
||||
oidc_token: idToken
|
||||
}
|
||||
if (this.isPreview === true) {
|
||||
payload.preview = true
|
||||
}
|
||||
core.info(`Creating deployment with payload:\n${JSON.stringify(payload, null, '\t')}`)
|
||||
const response = await axios.post(pagesDeployEndpoint, payload, {
|
||||
headers: {
|
||||
@@ -8310,7 +8315,12 @@ class Deployment {
|
||||
this.deploymentInfo != null
|
||||
? this.deploymentInfo['status_url']
|
||||
: `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/status/${this.buildVersion}`
|
||||
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo['page_url'] : '')
|
||||
let pageUrl = this.deploymentInfo != null ? this.deploymentInfo['page_url'] : ''
|
||||
const previewUrl = this.deploymentInfo != null ? this.deploymentInfo['preview_url'] : ''
|
||||
if (this.isPreview && previewUrl) {
|
||||
pageUrl = previewUrl
|
||||
}
|
||||
core.setOutput('page_url', pageUrl)
|
||||
const timeout = Number(core.getInput('timeout'))
|
||||
const reportingInterval = Number(core.getInput('reporting_interval'))
|
||||
const maxErrorCount = Number(core.getInput('error_count'))
|
||||
|
||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
14
pre/index.js
14
pre/index.js
@@ -8177,7 +8177,8 @@ function getRequiredVars() {
|
||||
actionsId: process.env.GITHUB_ACTION,
|
||||
githubToken: core.getInput('token'),
|
||||
githubApiUrl: process.env.GITHUB_API_URL ?? 'https://api.github.com',
|
||||
artifactName: core.getInput('artifact_name') ?? 'github-pages'
|
||||
artifactName: core.getInput('artifact_name') ?? 'github-pages',
|
||||
isPreview: core.getInput('preview') === 'true'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8227,6 +8228,7 @@ class Deployment {
|
||||
this.deploymentInfo = null
|
||||
this.githubApiUrl = context.githubApiUrl
|
||||
this.artifactName = context.artifactName
|
||||
this.isPreview = context.isPreview === true
|
||||
}
|
||||
|
||||
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
|
||||
@@ -8258,6 +8260,9 @@ class Deployment {
|
||||
pages_build_version: this.buildVersion,
|
||||
oidc_token: idToken
|
||||
}
|
||||
if (this.isPreview === true) {
|
||||
payload.preview = true
|
||||
}
|
||||
core.info(`Creating deployment with payload:\n${JSON.stringify(payload, null, '\t')}`)
|
||||
const response = await axios.post(pagesDeployEndpoint, payload, {
|
||||
headers: {
|
||||
@@ -8310,7 +8315,12 @@ class Deployment {
|
||||
this.deploymentInfo != null
|
||||
? this.deploymentInfo['status_url']
|
||||
: `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/status/${this.buildVersion}`
|
||||
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo['page_url'] : '')
|
||||
let pageUrl = this.deploymentInfo != null ? this.deploymentInfo['page_url'] : ''
|
||||
const previewUrl = this.deploymentInfo != null ? this.deploymentInfo['preview_url'] : ''
|
||||
if (this.isPreview && previewUrl) {
|
||||
pageUrl = previewUrl
|
||||
}
|
||||
core.setOutput('page_url', pageUrl)
|
||||
const timeout = Number(core.getInput('timeout'))
|
||||
const reportingInterval = Number(core.getInput('reporting_interval'))
|
||||
const maxErrorCount = Number(core.getInput('error_count'))
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -12,7 +12,8 @@ function getRequiredVars() {
|
||||
actionsId: process.env.GITHUB_ACTION,
|
||||
githubToken: core.getInput('token'),
|
||||
githubApiUrl: process.env.GITHUB_API_URL ?? 'https://api.github.com',
|
||||
artifactName: core.getInput('artifact_name') ?? 'github-pages'
|
||||
artifactName: core.getInput('artifact_name') ?? 'github-pages',
|
||||
isPreview: core.getInput('preview') === 'true'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ class Deployment {
|
||||
this.deploymentInfo = null
|
||||
this.githubApiUrl = context.githubApiUrl
|
||||
this.artifactName = context.artifactName
|
||||
this.isPreview = context.isPreview === true
|
||||
}
|
||||
|
||||
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
|
||||
@@ -58,6 +59,9 @@ class Deployment {
|
||||
pages_build_version: this.buildVersion,
|
||||
oidc_token: idToken
|
||||
}
|
||||
if (this.isPreview === true) {
|
||||
payload.preview = true
|
||||
}
|
||||
core.info(`Creating deployment with payload:\n${JSON.stringify(payload, null, '\t')}`)
|
||||
const response = await axios.post(pagesDeployEndpoint, payload, {
|
||||
headers: {
|
||||
@@ -110,7 +114,12 @@ class Deployment {
|
||||
this.deploymentInfo != null
|
||||
? this.deploymentInfo['status_url']
|
||||
: `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/status/${this.buildVersion}`
|
||||
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo['page_url'] : '')
|
||||
let pageUrl = this.deploymentInfo != null ? this.deploymentInfo['page_url'] : ''
|
||||
const previewUrl = this.deploymentInfo != null ? this.deploymentInfo['preview_url'] : ''
|
||||
if (this.isPreview && previewUrl) {
|
||||
pageUrl = previewUrl
|
||||
}
|
||||
core.setOutput('page_url', pageUrl)
|
||||
const timeout = Number(core.getInput('timeout'))
|
||||
const reportingInterval = Number(core.getInput('reporting_interval'))
|
||||
const maxErrorCount = Number(core.getInput('error_count'))
|
||||
|
||||
@@ -22,6 +22,11 @@ describe('with all environment variables set', () => {
|
||||
process.env.GITHUB_ACTION_PATH = 'something'
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
// Remove mock for `core.getInput('preview')`
|
||||
delete process.env.INPUT_PREVIEW
|
||||
})
|
||||
|
||||
it('Executes cleanly', done => {
|
||||
const ip = path.join(__dirname, './index.js')
|
||||
cp.exec(`node ${ip}`, { env: process.env }, (err, stdout) => {
|
||||
@@ -61,6 +66,8 @@ describe('create', () => {
|
||||
return 'github-pages'
|
||||
case 'token':
|
||||
return process.env.GITHUB_TOKEN
|
||||
default:
|
||||
return process.env[`INPUT_${param.toUpperCase()}`] || ''
|
||||
}
|
||||
})
|
||||
|
||||
@@ -120,6 +127,52 @@ describe('create', () => {
|
||||
scope.done()
|
||||
})
|
||||
|
||||
it('can successfully create a preview deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
const fakeJwt =
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w'
|
||||
const scope = 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' }
|
||||
]
|
||||
})
|
||||
|
||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||
axios.post = jest.fn().mockResolvedValue('test')
|
||||
|
||||
// Return `"true"` for `core.getInput("preview")`
|
||||
process.env.INPUT_PREVIEW = 'true'
|
||||
|
||||
// Create the deployment
|
||||
const deployment = new Deployment()
|
||||
await deployment.create(fakeJwt)
|
||||
|
||||
expect(axios.post).toBeCalledWith(
|
||||
'https://api.github.com/repos/actions/is-awesome/pages/deployment',
|
||||
{
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: 'valid-build-version',
|
||||
oidc_token: fakeJwt,
|
||||
preview: true
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
Authorization: `Bearer gha-token`,
|
||||
'Content-type': 'application/json'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
expect(core.setFailed).not.toHaveBeenCalled()
|
||||
expect(core.info).toHaveBeenCalledWith('Created deployment for valid-build-version')
|
||||
|
||||
scope.done()
|
||||
})
|
||||
|
||||
it('Reports errors with failed deployments', async () => {
|
||||
process.env.GITHUB_SHA = 'invalid-build-version'
|
||||
const scope = nock(`http://my-url`)
|
||||
|
||||
Reference in New Issue
Block a user