mirror of
https://github.com/actions/deploy-pages.git
synced 2025-12-08 16:16:16 +00:00
Use the Actions artifacts client to avoid needing the actions-read permission
This commit is contained in:
97349
dist/index.js
generated
vendored
97349
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
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
2764
dist/licenses.txt
generated
vendored
2764
dist/licenses.txt
generated
vendored
File diff suppressed because it is too large
Load Diff
1177
package-lock.json
generated
1177
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
"description": "Deploy an actions artifact to GitHub Pages",
|
||||
"main": "./dist/index.js",
|
||||
"dependencies": {
|
||||
"@actions/artifact": "^2.0.0",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.0"
|
||||
},
|
||||
|
||||
@@ -1,47 +1,38 @@
|
||||
const core = require('@actions/core')
|
||||
const github = require('@actions/github')
|
||||
const { DefaultArtifactClient } = require('@actions/artifact')
|
||||
|
||||
async function getArtifactMetadata({ githubToken, runId, artifactName }) {
|
||||
const octokit = github.getOctokit(githubToken)
|
||||
async function getArtifactMetadata({ artifactName }) {
|
||||
const artifactClient = new DefaultArtifactClient()
|
||||
|
||||
try {
|
||||
core.info(`Fetching artifact metadata for ${artifactName} in run ${runId}`)
|
||||
core.info(`Fetching artifact metadata for ${artifactName} in this workflow run`)
|
||||
|
||||
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
|
||||
}
|
||||
)
|
||||
const response = await artifactClient.listArtifacts()
|
||||
|
||||
const artifactCount = response.data.total_count
|
||||
const filteredArtifacts = response.artifacts.filter(artifact => artifact.name === artifactName)
|
||||
|
||||
const artifactCount = filteredArtifacts.length
|
||||
core.debug(`List artifact count: ${artifactCount}`)
|
||||
|
||||
if (artifactCount === 0) {
|
||||
throw new Error(
|
||||
`No artifacts found for workflow run ${runId}. Ensure artifacts are uploaded with actions/artifact@v4 or later.`
|
||||
'No artifacts found for this workflow run. Ensure artifacts are uploaded with actions/artifact@v4 or later.'
|
||||
)
|
||||
} else if (artifactCount > 1) {
|
||||
throw new Error(
|
||||
`Multiple artifact unexpectedly found for workflow run ${runId}. Artifact count is ${artifactCount}.`
|
||||
`Multiple artifacts unexpectedly found for this workflow run. Artifact count is ${artifactCount}.`
|
||||
)
|
||||
}
|
||||
|
||||
const artifact = response.data.artifacts[0]
|
||||
const artifact = filteredArtifacts[0]
|
||||
core.debug(`Artifact: ${JSON.stringify(artifact)}`)
|
||||
|
||||
const artifactSize = artifact.size_in_bytes
|
||||
if (!artifactSize) {
|
||||
if (!artifact.size) {
|
||||
core.warning('Artifact size was not found. Unable to verify if artifact size exceeds the allowed size.')
|
||||
}
|
||||
|
||||
return {
|
||||
id: artifact.id,
|
||||
size: artifactSize
|
||||
}
|
||||
return artifact
|
||||
} catch (error) {
|
||||
core.error(
|
||||
'Fetching artifact metadata failed. Is githubstatus.com reporting issues with API requests, Pages or Actions? Please re-run the deployment at a later time.',
|
||||
|
||||
@@ -63,11 +63,7 @@ class Deployment {
|
||||
core.debug(`Action ID: ${this.actionsId}`)
|
||||
core.debug(`Actions Workflow Run ID: ${this.workflowRun}`)
|
||||
|
||||
const artifactData = await getArtifactMetadata({
|
||||
githubToken: this.githubToken,
|
||||
runId: this.workflowRun,
|
||||
artifactName: this.artifactName
|
||||
})
|
||||
const artifactData = await getArtifactMetadata({ artifactName: this.artifactName })
|
||||
|
||||
if (artifactData?.size > ONE_GIGABYTE) {
|
||||
core.warning(
|
||||
|
||||
Reference in New Issue
Block a user