mirror of
https://github.com/actions/deploy-pages.git
synced 2025-12-08 16:16:16 +00:00
adjust pages hard code endpoint + fix artifact look up
This commit is contained in:
@@ -24,6 +24,10 @@ inputs:
|
||||
description: 'Time in milliseconds between two deployment status report (default: 5 seconds)'
|
||||
required: false
|
||||
default: "5000"
|
||||
artifact_name:
|
||||
description: 'Name of the artifact to deploy'
|
||||
required: false
|
||||
default: "github-pages"
|
||||
outputs:
|
||||
page_url:
|
||||
description: 'URL to deployed GitHub Pages'
|
||||
|
||||
22
dist/index.js
vendored
22
dist/index.js
vendored
@@ -7057,7 +7057,9 @@ function getRequiredVars() {
|
||||
buildVersion: process.env.GITHUB_SHA,
|
||||
buildActor: process.env.GITHUB_ACTOR,
|
||||
actionsId: process.env.GITHUB_ACTION,
|
||||
githubToken: core.getInput('token')
|
||||
githubApiUrl: process.env.GITHUB_API_URL ?? `https://api.github.com`,
|
||||
githubToken: core.getInput('token'),
|
||||
artifactName: core.getInput('artifact_name'),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7105,6 +7107,8 @@ class Deployment {
|
||||
this.workflowRun = context.workflowRun
|
||||
this.requestedDeployment = false
|
||||
this.deploymentInfo = null
|
||||
this.githubApiUrl = context.githubApiUrl
|
||||
this.artifactName = context.artifactName
|
||||
}
|
||||
|
||||
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
|
||||
@@ -7113,7 +7117,7 @@ class Deployment {
|
||||
try {
|
||||
core.info(`Actor: ${this.buildActor}`)
|
||||
core.info(`Action ID: ${this.actionsId}`)
|
||||
const pagesDeployEndpoint = `https://api.github.com/repos/${this.repositoryNwo}/pages/deployment`
|
||||
const pagesDeployEndpoint = `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment`
|
||||
const artifactExgUrl = `${this.runTimeUrl}_apis/pipelines/workflows/${this.workflowRun}/artifacts?api-version=6.0-preview`
|
||||
core.info(`Artifact URL: ${artifactExgUrl}`)
|
||||
const {data} = await axios.get(artifactExgUrl, {
|
||||
@@ -7123,10 +7127,12 @@ class Deployment {
|
||||
}
|
||||
})
|
||||
core.info(JSON.stringify(data))
|
||||
if (data.value.length == 0) {
|
||||
throw new Error('No uploaded artifact was found! Please check if there are any errors at build step.')
|
||||
const artifactRawUrl = data?.value?.find(artifact => artifact.name === this.artifactName)?.url
|
||||
if (!artifactRawUrl) {
|
||||
throw new Error('No uploaded artifact was found! Please check if there are any errors at build step, or uploaded artifact name is correct.')
|
||||
}
|
||||
const artifactUrl = `${data.value[0].url}&%24expand=SignedContent`
|
||||
|
||||
const artifactUrl = `${artifactRawUrl}&%24expand=SignedContent`
|
||||
const payload = {
|
||||
artifact_url: artifactUrl,
|
||||
pages_build_version: this.buildVersion,
|
||||
@@ -7185,7 +7191,7 @@ class Deployment {
|
||||
try {
|
||||
const statusUrl = this.deploymentInfo != null ?
|
||||
this.deploymentInfo["status_url"] :
|
||||
`https://api.github.com/repos/${this.repositoryNwo}/pages/deployment/status/${process.env['GITHUB_SHA']}`
|
||||
`${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/status/${process.env['GITHUB_SHA']}`
|
||||
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo["page_url"] : "")
|
||||
const timeout = Number(core.getInput('timeout'))
|
||||
const reportingInterval = Number(core.getInput('reporting_interval'))
|
||||
@@ -7290,7 +7296,7 @@ const {Deployment} = __nccwpck_require__(2877)
|
||||
async function emitTelemetry() {
|
||||
// All variables we need from the runtime are set in the Deployment constructor
|
||||
const deployment = new Deployment()
|
||||
const telemetryUrl = `https://api.github.com/repos/${deployment.repositoryNwo}/pages/telemetry`
|
||||
const telemetryUrl = `${deployment.githubApiUrl}/repos/${deployment.repositoryNwo}/pages/telemetry`
|
||||
core.info(`Sending telemetry for run id ${deployment.workflowRun}`)
|
||||
await axios
|
||||
.post(
|
||||
@@ -7500,7 +7506,7 @@ const deployment = new Deployment()
|
||||
async function cancelHandler(evtOrExitCodeOrError) {
|
||||
try {
|
||||
if (deployment.requestedDeployment) {
|
||||
const pagesCancelDeployEndpoint = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployment/cancel/${process.env.GITHUB_SHA}`
|
||||
const pagesCancelDeployEndpoint = `${deployment.githubApiUrl}/repos/${process.env.GITHUB_REPOSITORY}/pages/deployment/cancel/${process.env.GITHUB_SHA}`
|
||||
await axios.put(
|
||||
pagesCancelDeployEndpoint,
|
||||
{},
|
||||
|
||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
20
pre/index.js
20
pre/index.js
@@ -7057,7 +7057,9 @@ function getRequiredVars() {
|
||||
buildVersion: process.env.GITHUB_SHA,
|
||||
buildActor: process.env.GITHUB_ACTOR,
|
||||
actionsId: process.env.GITHUB_ACTION,
|
||||
githubToken: core.getInput('token')
|
||||
githubApiUrl: process.env.GITHUB_API_URL ?? `https://api.github.com`,
|
||||
githubToken: core.getInput('token'),
|
||||
artifactName: core.getInput('artifact_name'),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7105,6 +7107,8 @@ class Deployment {
|
||||
this.workflowRun = context.workflowRun
|
||||
this.requestedDeployment = false
|
||||
this.deploymentInfo = null
|
||||
this.githubApiUrl = context.githubApiUrl
|
||||
this.artifactName = context.artifactName
|
||||
}
|
||||
|
||||
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
|
||||
@@ -7113,7 +7117,7 @@ class Deployment {
|
||||
try {
|
||||
core.info(`Actor: ${this.buildActor}`)
|
||||
core.info(`Action ID: ${this.actionsId}`)
|
||||
const pagesDeployEndpoint = `https://api.github.com/repos/${this.repositoryNwo}/pages/deployment`
|
||||
const pagesDeployEndpoint = `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment`
|
||||
const artifactExgUrl = `${this.runTimeUrl}_apis/pipelines/workflows/${this.workflowRun}/artifacts?api-version=6.0-preview`
|
||||
core.info(`Artifact URL: ${artifactExgUrl}`)
|
||||
const {data} = await axios.get(artifactExgUrl, {
|
||||
@@ -7123,10 +7127,12 @@ class Deployment {
|
||||
}
|
||||
})
|
||||
core.info(JSON.stringify(data))
|
||||
if (data.value.length == 0) {
|
||||
throw new Error('No uploaded artifact was found! Please check if there are any errors at build step.')
|
||||
const artifactRawUrl = data?.value?.find(artifact => artifact.name === this.artifactName)?.url
|
||||
if (!artifactRawUrl) {
|
||||
throw new Error('No uploaded artifact was found! Please check if there are any errors at build step, or uploaded artifact name is correct.')
|
||||
}
|
||||
const artifactUrl = `${data.value[0].url}&%24expand=SignedContent`
|
||||
|
||||
const artifactUrl = `${artifactRawUrl}&%24expand=SignedContent`
|
||||
const payload = {
|
||||
artifact_url: artifactUrl,
|
||||
pages_build_version: this.buildVersion,
|
||||
@@ -7185,7 +7191,7 @@ class Deployment {
|
||||
try {
|
||||
const statusUrl = this.deploymentInfo != null ?
|
||||
this.deploymentInfo["status_url"] :
|
||||
`https://api.github.com/repos/${this.repositoryNwo}/pages/deployment/status/${process.env['GITHUB_SHA']}`
|
||||
`${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/status/${process.env['GITHUB_SHA']}`
|
||||
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo["page_url"] : "")
|
||||
const timeout = Number(core.getInput('timeout'))
|
||||
const reportingInterval = Number(core.getInput('reporting_interval'))
|
||||
@@ -7290,7 +7296,7 @@ const {Deployment} = __nccwpck_require__(2877)
|
||||
async function emitTelemetry() {
|
||||
// All variables we need from the runtime are set in the Deployment constructor
|
||||
const deployment = new Deployment()
|
||||
const telemetryUrl = `https://api.github.com/repos/${deployment.repositoryNwo}/pages/telemetry`
|
||||
const telemetryUrl = `${deployment.githubApiUrl}/repos/${deployment.repositoryNwo}/pages/telemetry`
|
||||
core.info(`Sending telemetry for run id ${deployment.workflowRun}`)
|
||||
await axios
|
||||
.post(
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -10,7 +10,9 @@ function getRequiredVars() {
|
||||
buildVersion: process.env.GITHUB_SHA,
|
||||
buildActor: process.env.GITHUB_ACTOR,
|
||||
actionsId: process.env.GITHUB_ACTION,
|
||||
githubToken: core.getInput('token')
|
||||
githubApiUrl: process.env.GITHUB_API_URL ?? `https://api.github.com`,
|
||||
githubToken: core.getInput('token'),
|
||||
artifactName: core.getInput('artifact_name'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ class Deployment {
|
||||
this.workflowRun = context.workflowRun
|
||||
this.requestedDeployment = false
|
||||
this.deploymentInfo = null
|
||||
this.githubApiUrl = context.githubApiUrl
|
||||
this.artifactName = context.artifactName
|
||||
}
|
||||
|
||||
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
|
||||
@@ -33,7 +35,7 @@ class Deployment {
|
||||
try {
|
||||
core.info(`Actor: ${this.buildActor}`)
|
||||
core.info(`Action ID: ${this.actionsId}`)
|
||||
const pagesDeployEndpoint = `https://api.github.com/repos/${this.repositoryNwo}/pages/deployment`
|
||||
const pagesDeployEndpoint = `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment`
|
||||
const artifactExgUrl = `${this.runTimeUrl}_apis/pipelines/workflows/${this.workflowRun}/artifacts?api-version=6.0-preview`
|
||||
core.info(`Artifact URL: ${artifactExgUrl}`)
|
||||
const {data} = await axios.get(artifactExgUrl, {
|
||||
@@ -43,10 +45,12 @@ class Deployment {
|
||||
}
|
||||
})
|
||||
core.info(JSON.stringify(data))
|
||||
if (data.value.length == 0) {
|
||||
throw new Error('No uploaded artifact was found! Please check if there are any errors at build step.')
|
||||
const artifactRawUrl = data?.value?.find(artifact => artifact.name === this.artifactName)?.url
|
||||
if (!artifactRawUrl) {
|
||||
throw new Error('No uploaded artifact was found! Please check if there are any errors at build step, or uploaded artifact name is correct.')
|
||||
}
|
||||
const artifactUrl = `${data.value[0].url}&%24expand=SignedContent`
|
||||
|
||||
const artifactUrl = `${artifactRawUrl}&%24expand=SignedContent`
|
||||
const payload = {
|
||||
artifact_url: artifactUrl,
|
||||
pages_build_version: this.buildVersion,
|
||||
@@ -105,7 +109,7 @@ class Deployment {
|
||||
try {
|
||||
const statusUrl = this.deploymentInfo != null ?
|
||||
this.deploymentInfo["status_url"] :
|
||||
`https://api.github.com/repos/${this.repositoryNwo}/pages/deployment/status/${process.env['GITHUB_SHA']}`
|
||||
`${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/status/${process.env['GITHUB_SHA']}`
|
||||
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo["page_url"] : "")
|
||||
const timeout = Number(core.getInput('timeout'))
|
||||
const reportingInterval = Number(core.getInput('reporting_interval'))
|
||||
|
||||
@@ -17,7 +17,7 @@ const deployment = new Deployment()
|
||||
async function cancelHandler(evtOrExitCodeOrError) {
|
||||
try {
|
||||
if (deployment.requestedDeployment) {
|
||||
const pagesCancelDeployEndpoint = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployment/cancel/${process.env.GITHUB_SHA}`
|
||||
const pagesCancelDeployEndpoint = `${deployment.githubApiUrl}/repos/${process.env.GITHUB_REPOSITORY}/pages/deployment/cancel/${process.env.GITHUB_SHA}`
|
||||
await axios.put(
|
||||
pagesCancelDeployEndpoint,
|
||||
{},
|
||||
|
||||
@@ -20,6 +20,7 @@ describe('with all environment variables set', () => {
|
||||
process.env.GITHUB_ACTOR = 'monalisa'
|
||||
process.env.GITHUB_ACTION = '__monalisa/octocat'
|
||||
process.env.GITHUB_ACTION_PATH = 'something'
|
||||
process.env.ARTIFACT_NAME = 'github-pages'
|
||||
})
|
||||
|
||||
it('Executes cleanly', done => {
|
||||
@@ -55,6 +56,14 @@ describe('create', () => {
|
||||
process.env.GITHUB_ACTOR = 'monalisa'
|
||||
process.env.GITHUB_ACTION = '__monalisa/octocat'
|
||||
process.env.GITHUB_ACTION_PATH = 'something'
|
||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||
switch (param) {
|
||||
case 'artifact_name':
|
||||
return 'github-pages'
|
||||
case 'token':
|
||||
return process.env.GITHUB_TOKEN
|
||||
}
|
||||
})
|
||||
|
||||
jest.spyOn(core, 'setOutput').mockImplementation(param => {
|
||||
return param
|
||||
@@ -75,7 +84,7 @@ describe('create', () => {
|
||||
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://fake-artifact.com' }] })
|
||||
.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')
|
||||
@@ -94,7 +103,7 @@ describe('create', () => {
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
Authorization: 'Bearer ',
|
||||
Authorization: `Bearer gha-token`,
|
||||
'Content-type': 'application/json'
|
||||
}
|
||||
}
|
||||
@@ -112,7 +121,7 @@ describe('create', () => {
|
||||
process.env.GITHUB_SHA = 'invalid-build-version'
|
||||
const scope = nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com' }] })
|
||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||
|
||||
axios.post = jest.fn().mockRejectedValue({
|
||||
status: 400
|
||||
@@ -161,6 +170,7 @@ describe('check', () => {
|
||||
process.env.GITHUB_ACTOR = 'monalisa'
|
||||
process.env.GITHUB_ACTION = '__monalisa/octocat'
|
||||
process.env.GITHUB_ACTION_PATH = 'something'
|
||||
process.env.ARTIFACT_NAME = 'github-pages'
|
||||
|
||||
jest.spyOn(core, 'setOutput').mockImplementation(param => {
|
||||
return param
|
||||
@@ -209,7 +219,7 @@ describe('check', () => {
|
||||
`https://api.github.com/repos/${repositoryNwo}/pages/deployment/status/${buildVersion}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: 'token '
|
||||
Authorization: 'token gha-token'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ const {Deployment} = require('./deployment')
|
||||
async function emitTelemetry() {
|
||||
// All variables we need from the runtime are set in the Deployment constructor
|
||||
const deployment = new Deployment()
|
||||
const telemetryUrl = `https://api.github.com/repos/${deployment.repositoryNwo}/pages/telemetry`
|
||||
const telemetryUrl = `${deployment.githubApiUrl}/repos/${deployment.repositoryNwo}/pages/telemetry`
|
||||
core.info(`Sending telemetry for run id ${deployment.workflowRun}`)
|
||||
await axios
|
||||
.post(
|
||||
|
||||
Reference in New Issue
Block a user