This commit is contained in:
Konrad Pabjan
2023-10-27 16:13:35 -04:00
parent fa86ad3bc1
commit 08232476b8
3 changed files with 24 additions and 34 deletions

View File

@@ -54,6 +54,24 @@ async function processRuntimeResponse(res, requestOptions) {
return response
}
async function getArtifactMetadata({githubToken, runId, artifactName}) {
const octokit = github.getOctokit(githubToken)
try {
const response = await octokit.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts?name={artifactName}', {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
run_id: runId,
artifactName: artifactName
})
return response.data
} catch (error) {
core.error('Fetching artifact metadata failed', error)
throw error
}
}
async function getSignedArtifactMetadata({ runtimeToken, workflowRunId, artifactName }) {
const { runTimeUrl: RUNTIME_URL } = getContext()
const artifactExchangeUrl = `${RUNTIME_URL}_apis/pipelines/workflows/${workflowRunId}/artifacts?api-version=6.0-preview`
@@ -173,6 +191,7 @@ async function cancelPagesDeployment({ githubToken, deploymentId }) {
}
module.exports = {
getArtifactMetadata,
getSignedArtifactMetadata,
createPagesDeployment,
getPagesDeploymentStatus,

View File

@@ -3,9 +3,7 @@ const core = require('@actions/core')
// Load variables from Actions runtime
function getRequiredVars() {
return {
runTimeUrl: process.env.ACTIONS_RUNTIME_URL,
workflowRun: process.env.GITHUB_RUN_ID,
runTimeToken: process.env.ACTIONS_RUNTIME_TOKEN,
repositoryNwo: process.env.GITHUB_REPOSITORY,
buildVersion: process.env.GITHUB_SHA,
buildActor: process.env.GITHUB_ACTOR,

View File

@@ -3,7 +3,7 @@ const core = require('@actions/core')
// All variables we need from the runtime are loaded here
const getContext = require('./context')
const {
getSignedArtifactMetadata,
getArtifactMetadata,
createPagesDeployment,
getPagesDeploymentStatus,
cancelPagesDeployment
@@ -31,9 +31,7 @@ const SIZE_LIMIT_DESCRIPTION = '1 GB'
class Deployment {
constructor() {
const context = getContext()
this.runTimeUrl = context.runTimeUrl
this.repositoryNwo = context.repositoryNwo
this.runTimeToken = context.runTimeToken
this.buildVersion = context.buildVersion
this.buildActor = context.buildActor
this.actionsId = context.actionsId
@@ -65,40 +63,15 @@ class Deployment {
core.debug(`Action ID: ${this.actionsId}`)
core.debug(`Actions Workflow Run ID: ${this.workflowRun}`)
const artifactData = await getSignedArtifactMetadata({
runtimeToken: this.runTimeToken,
const artifactData = await getArtifactMetadata({
githubToken: this.githubToken,
workflowRunId: this.workflowRun,
artifactName: this.artifactName
})
if (artifactData?.size > ONE_GIGABYTE) {
core.warning(
`Uploaded artifact size of ${artifactData?.size} bytes exceeds the allowed size of ${SIZE_LIMIT_DESCRIPTION}. Deployment might fail.`
)
}
console.log(artifactData)
const deployment = await createPagesDeployment({
githubToken: this.githubToken,
artifactUrl: artifactData.url,
buildVersion: this.buildVersion,
idToken,
isPreview: this.isPreview
})
if (deployment) {
this.deploymentInfo = {
...deployment,
id: deployment.id || deployment.status_url?.split('/')?.pop() || this.buildVersion,
pending: true
}
this.startTime = Date.now()
}
core.info(`Created deployment for ${this.buildVersion}, ID: ${this.deploymentInfo?.id}`)
core.debug(JSON.stringify(deployment))
return deployment
return nil
} catch (error) {
core.error(error.stack)