Compare commits

..

5 Commits

Author SHA1 Message Date
James M. Greene
c7b5c1034e Update distributables 2023-06-15 15:14:49 -05:00
James M. Greene
b4d15f6490 Merge branch 'main' into error-count 2023-06-15 15:11:35 -05:00
James M. Greene
c883148031 Separate tests for Deployment##setOptionalUserInput to limit scope 2023-06-15 15:09:03 -05:00
Greta Parks
b1a18fc1bd little nits
Co-authored-by: James M. Greene <JamesMGreene@github.com>
2023-06-14 17:02:05 +00:00
Greta Parks
a378718509 adds a check for error_count variable 2023-05-22 22:59:30 +00:00
21 changed files with 8801 additions and 147011 deletions

View File

@@ -22,10 +22,10 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
- name: Setup Node.JS - name: Setup Node.JS
uses: actions/setup-node@v4 uses: actions/setup-node@v3
with: with:
node-version-file: '.node-version' node-version-file: '.node-version'
cache: npm cache: npm

View File

@@ -19,10 +19,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
- name: Setup Node.JS - name: Setup Node.JS
uses: actions/setup-node@v4 uses: actions/setup-node@v3
with: with:
node-version-file: '.node-version' node-version-file: '.node-version'
cache: npm cache: npm

View File

@@ -19,10 +19,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
- name: Setup Node.JS - name: Setup Node.JS
uses: actions/setup-node@v4 uses: actions/setup-node@v3
with: with:
node-version-file: '.node-version' node-version-file: '.node-version'
cache: npm cache: npm

View File

@@ -38,7 +38,7 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL

View File

@@ -11,6 +11,6 @@ jobs:
draft-release: draft-release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: release-drafter/release-drafter@09c613e259eb8d4e7c81c2cb00618eb5fc4575a7 # v5.25.0 - uses: release-drafter/release-drafter@569eb7ee3a85817ab916c8f8ff03a5bd96c9c83e # v5.23.0
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -22,12 +22,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
with: with:
token: ${{ secrets.PAGES_AUTOMATION_PAT }} token: ${{ secrets.PAGES_AUTOMATION_PAT }}
- name: Setup Node.JS - name: Setup Node.JS
uses: actions/setup-node@v4 uses: actions/setup-node@v3
with: with:
node-version-file: '.node-version' node-version-file: '.node-version'
cache: npm cache: npm

View File

@@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v3
- name: Setup Node.JS - name: Setup Node.JS
uses: actions/setup-node@v4 uses: actions/setup-node@v3
with: with:
node-version-file: '.node-version' node-version-file: '.node-version'
cache: npm cache: npm

View File

@@ -1 +1 @@
20.10.0 18.9.0

View File

@@ -6,11 +6,11 @@ This action is used to deploy [Actions artifacts][artifacts] to [GitHub Pages](h
## Usage ## Usage
See [action.yml](action.yml) for the various `inputs` this action supports (or [below](#inputs-📥)). See [action.yml](action.yml) for the various `inputs` this action supports.
For examples that make use of this action, check out our [starter-workflows][starter-workflows] in a variety of frameworks. For examples that make use of this action, check out our [starter-workflows][starter-workflows] in a variety of frameworks.
This action deploys a Pages site previously uploaded as an artifact (e.g. using [`actions/upload-pages-artifact`][upload-pages-artifact]). This action expects an artifact named `github-pages` to have been created prior to execution. This is done automatically when using [`actions/upload-pages-artifact`][upload-pages-artifact].
We recommend this action to be used in a dedicated job: We recommend this action to be used in a dedicated job:
@@ -41,7 +41,7 @@ jobs:
steps: steps:
- name: Deploy to GitHub Pages - name: Deploy to GitHub Pages
id: deployment id: deployment
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action uses: actions/deploy-pages@v2 # or the latest "vX.X.X" version tag for this action
``` ```
### Inputs 📥 ### Inputs 📥
@@ -51,7 +51,7 @@ jobs:
| `token` | `true` | `${{ github.token }}` | The GitHub token used to create an authenticated client - Provided for you by default! | | `token` | `true` | `${{ github.token }}` | The GitHub token used to create an authenticated client - Provided for you by default! |
| `timeout` | `false` | `"600000"` | Time in milliseconds after which to timeout and cancel the deployment (default: 10 minutes) | | `timeout` | `false` | `"600000"` | Time in milliseconds after which to timeout and cancel the deployment (default: 10 minutes) |
| `error_count` | `false` | `"10"` | Maximum number of status report errors before cancelling a deployment (default: 10) | | `error_count` | `false` | `"10"` | Maximum number of status report errors before cancelling a deployment (default: 10) |
| `reporting_interval` | `false` | `"5000"` | Time in milliseconds between two deployment status reports (default: 5 seconds) | | `reporting_interval` | `false` | `"5000"` | Time in milliseconds between two deployment status report (default: 5 seconds) |
| `artifact_name` | `false` | `"github-pages"` | The name of the artifact to deploy | | `artifact_name` | `false` | `"github-pages"` | The name of the artifact to deploy |
| `preview` | `false` | `"false"` | 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!) | | `preview` | `false` | `"false"` | 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!) |
@@ -67,11 +67,15 @@ jobs:
| -------- | ----------- | | -------- | ----------- |
| `GITHUB_PAGES` | This environment variable is created and set to the string value `"true"` so that framework build tools may choose to differentiate their output based on the intended target hosting platform. | | `GITHUB_PAGES` | This environment variable is created and set to the string value `"true"` so that framework build tools may choose to differentiate their output based on the intended target hosting platform. |
## Scope
⚠️ Official support for building Pages with Actions is in public beta at the moment.
## Security Considerations ## Security Considerations
There are a few important considerations to be aware of: There are a few important considerations to be aware of:
1. The artifact being deployed must have been uploaded in a previous step, either in the same job or a separate job that doesn't execute until the upload is complete. See [`actions/upload-pages-artifact`][upload-pages-artifact] for more information about the format of the artifact we expect. 1. The artifact being deployed must have been uploaded in a previous step, either in the same job or a separate job that doesn't execute until the upload is complete.
2. The job that executes the deployment must at minimum have the following permissions: 2. The job that executes the deployment must at minimum have the following permissions:
- `pages: write` - `pages: write`
@@ -85,18 +89,16 @@ There are a few important considerations to be aware of:
## Compatibility ## Compatibility
This action is primarily designed for use with GitHub.com's Actions workflows and Pages deployments. However, certain releases should also be compatible with GitHub Enterprise Server (GHES) `3.7` and above. This action is primarily design for use with GitHub.com's Actions workflows and Pages deployments. However, certain releases should also be compatible with GitHub Enterprise Server (GHES) `3.7` and above.
| Release | GHES Compatibility | | Release | GHES Compatibility |
|:---|:---| |:---|:---|
| [`v4`](https://github.com/actions/deploy-pages/releases/tag/v4) | :warning: Incompatible at this time | | [`v2`](https://github.com/actions/deploy-pages/releases/tag/v2) | 🛑 Incompatible. Anticipating compatibility with `>= 3.9`. |
| [`v3`](https://github.com/actions/deploy-pages/releases/tag/v3) | `>= 3.9` | | [`v2.0.1`](https://github.com/actions/deploy-pages/releases/tag/v2.0.1) | 🛑 Incompatible. Anticipating compatibility with `>= 3.9`. |
| `v3.x.x` | `>= 3.9` | | [`v2.0.0`](https://github.com/actions/deploy-pages/releases/tag/v2.0.0) | 🛑 Incompatible. Anticipating compatibility with `>= 3.9`. |
| [`v2`](https://github.com/actions/deploy-pages/releases/tag/v2) | `>= 3.9` |
| `v2.x.x` | `>= 3.9` |
| [`v1`](https://github.com/actions/deploy-pages/releases/tag/v1) | `>= 3.7` | | [`v1`](https://github.com/actions/deploy-pages/releases/tag/v1) | `>= 3.7` |
| [`v1.2.8`](https://github.com/actions/deploy-pages/releases/tag/v1.2.8) | `>= 3.7` | | [`v1.2.8`](https://github.com/actions/deploy-pages/releases/tag/v1.2.8) | `>= 3.7` |
| [`v1.2.7`](https://github.com/actions/deploy-pages/releases/tag/v1.2.7) | :warning: `>= 3.9` [Incompatible with prior versions!](https://github.com/actions/deploy-pages/issues/137) | | [`v1.2.7`](https://github.com/actions/deploy-pages/releases/tag/v1.2.7) | :warning: [Incompatible](https://github.com/actions/deploy-pages/issues/137). Anticipating compatibility with `>= 3.9`. |
| [`v1.2.6`](https://github.com/actions/deploy-pages/releases/tag/v1.2.6) | `>= 3.7` | | [`v1.2.6`](https://github.com/actions/deploy-pages/releases/tag/v1.2.6) | `>= 3.7` |
| `v1.x.x` | `>= 3.7` | | `v1.x.x` | `>= 3.7` |
@@ -108,7 +110,7 @@ In order to release a new version of this Action:
2. Publish the draft release from the `main` branch with semantic version as the tag name, _with_ the checkbox to publish to the GitHub Marketplace checked. :ballot_box_with_check: 2. Publish the draft release from the `main` branch with semantic version as the tag name, _with_ the checkbox to publish to the GitHub Marketplace checked. :ballot_box_with_check:
3. After publishing the release, the [`release` workflow][release] will automatically run to create/update the corresponding major version tag such as `v1`. 3. After publishing the release, the [`release` workflow][release] will automatically run to create/update the corresponding the major version tag such as `v1`.
⚠️ Environment approval is required. Check the [Release workflow run list][release-workflow-runs]. ⚠️ Environment approval is required. Check the [Release workflow run list][release-workflow-runs].

View File

@@ -2,7 +2,7 @@ name: 'Deploy GitHub Pages site'
description: 'A GitHub Action to deploy an artifact as a GitHub Pages site' description: 'A GitHub Action to deploy an artifact as a GitHub Pages site'
author: 'GitHub' author: 'GitHub'
runs: runs:
using: 'node20' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'
inputs: inputs:
token: token:

View File

@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="116" height="20" role="img" aria-label="Coverage: 81.13%"><title>Coverage: 81.13%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="116" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="53" height="20" fill="#dfb317"/><rect width="116" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="885" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">81.13%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">81.13%</text></g></svg> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="116" height="20" role="img" aria-label="Coverage: 80.18%"><title>Coverage: 80.18%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="116" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="53" height="20" fill="#dfb317"/><rect width="116" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="885" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">80.18%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">80.18%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

142631
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

2706
dist/licenses.txt generated vendored

File diff suppressed because it is too large Load Diff

9037
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,22 +4,21 @@
"description": "Deploy an actions artifact to GitHub Pages", "description": "Deploy an actions artifact to GitHub Pages",
"main": "./dist/index.js", "main": "./dist/index.js",
"dependencies": { "dependencies": {
"@actions/artifact": "^2.0.0", "@actions/core": "^1.10.0",
"@actions/core": "^1.10.1", "@actions/github": "^5.1.1",
"@actions/github": "^6.0.0", "@actions/http-client": "^2.1.0",
"@octokit/request-error": "^5.0.1", "@octokit/request-error": "^4.0.1",
"http-status-messages": "^1.1.0" "http-status-messages": "^1.1.0"
}, },
"devDependencies": { "devDependencies": {
"@vercel/ncc": "^0.38.1", "@vercel/ncc": "^0.36.1",
"eslint": "^8.55.0", "eslint": "^8.42.0",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^8.8.0",
"eslint-plugin-github": "^4.10.1", "eslint-plugin-github": "^4.8.0",
"jest": "^29.7.0", "jest": "^29.5.0",
"make-coverage-badge": "^1.2.0", "nock": "^13.3.1",
"nock": "^13.4.0", "prettier": "^2.8.8",
"prettier": "^3.1.0", "make-coverage-badge": "^1.2.0"
"undici": "^6.0.0"
}, },
"scripts": { "scripts": {
"all": "npm run format && npm run lint && npm run prepare && npm run test && npm run coverage-badge", "all": "npm run format && npm run lint && npm run prepare && npm run test && npm run coverage-badge",

View File

@@ -4,7 +4,9 @@ const path = require('path')
describe('with all environment variables set', () => { describe('with all environment variables set', () => {
beforeEach(() => { beforeEach(() => {
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.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'
@@ -24,7 +26,7 @@ describe('with all environment variables set', () => {
describe('with variables missing', () => { describe('with variables missing', () => {
it('execution fails if there are missing variables', done => { it('execution fails if there are missing variables', done => {
delete process.env.GITHUB_RUN_ID delete process.env.ACTIONS_RUNTIME_URL
const ip = path.join(__dirname, '../index.js') const ip = path.join(__dirname, '../index.js')
cp.exec(`node ${ip}`, { env: process.env }, (err, stdout) => { cp.exec(`node ${ip}`, { env: process.env }, (err, stdout) => {
expect(stdout).toBe('') expect(stdout).toBe('')

File diff suppressed because it is too large Load Diff

View File

@@ -1,118 +1,119 @@
const core = require('@actions/core') const core = require('@actions/core')
const github = require('@actions/github') const github = require('@actions/github')
const { DefaultArtifactClient } = require('@actions/artifact') const hc = require('@actions/http-client')
const { RequestError } = require('@octokit/request-error') const { RequestError } = require('@octokit/request-error')
const HttpStatusMessages = require('http-status-messages') const HttpStatusMessages = require('http-status-messages')
function wrapTwirpResponseLikeOctokit(twirpResponse, requestOptions) { // All variables we need from the runtime are loaded here
const getContext = require('./context')
async function processRuntimeResponse(res, requestOptions) {
// Parse the response body as JSON
let obj = null
try {
const contents = await res.readBody()
if (contents && contents.length > 0) {
obj = JSON.parse(contents)
}
} catch (error) {
// Invalid resource (contents not json); leaving resulting obj as null
}
// Specific response shape aligned with Octokit // Specific response shape aligned with Octokit
const response = { const response = {
url: requestOptions.url, url: res.message?.url || requestOptions.url,
status: 200, status: res.message?.statusCode || 0,
headers: { headers: {
...requestOptions.headers ...res.message?.headers
}, },
data: twirpResponse data: obj
} }
// Forcibly throw errors for negative HTTP status codes!
// @actions/http-client doesn't do this by default.
// Mimic the errors thrown by Octokit for consistency.
if (response.status >= 400) {
// Try to get an error message from the response body
const errorMsg =
(typeof response.data === 'string' && response.data) ||
response.data?.error ||
response.data?.message ||
// Try the Node HTTP IncomingMessage's statusMessage property
res.message?.statusMessage ||
// Fallback to the HTTP status message based on the status code
HttpStatusMessages[response.status] ||
// Or if the status code is unexpected...
`Unknown error (${response.status})`
throw new RequestError(errorMsg, response.status, {
response,
request: requestOptions
})
}
return response return response
} }
// Mimic the errors thrown by Octokit for consistency. async function getSignedArtifactMetadata({ runtimeToken, workflowRunId, artifactName }) {
function wrapTwirpErrorLikeOctokit(twirpError, requestOptions) { const { runTimeUrl: RUNTIME_URL } = getContext()
const rawErrorMsg = twirpError?.message || twirpError?.toString() || '' const artifactExchangeUrl = `${RUNTIME_URL}_apis/pipelines/workflows/${workflowRunId}/artifacts?api-version=6.0-preview`
const statusCodeMatch = rawErrorMsg.match(/Failed request: \((?<statusCode>\d+)\)/)
const statusCode = statusCodeMatch?.groups?.statusCode ?? 500
// Try to provide the best error message const httpClient = new hc.HttpClient()
const errorMsg = let data = null
rawErrorMsg ||
// Fallback to the HTTP status message based on the status code
HttpStatusMessages[statusCode] ||
// Or if the status code is unexpected...
`Unknown error (${statusCode})`
// RequestError is an Octokit-specific class
return new RequestError(errorMsg, statusCode, {
response: {
url: requestOptions.url,
status: statusCode,
headers: {
...requestOptions.headers
},
data: rawErrorMsg ? { message: rawErrorMsg } : ''
},
request: requestOptions
})
}
function getArtifactsServiceOrigin() {
const resultsUrl = process.env.ACTIONS_RESULTS_URL
return resultsUrl ? new URL(resultsUrl).origin : ''
}
async function getArtifactMetadata({ artifactName }) {
const artifactClient = new DefaultArtifactClient()
// Primarily for debugging purposes, accuracy is not critical
const requestOptions = {
method: 'POST',
url: `${getArtifactsServiceOrigin()}/twirp/github.actions.results.api.v1.ArtifactService/ListArtifacts`,
headers: {
'content-type': 'application/json'
},
body: {}
}
try { try {
core.info(`Fetching artifact metadata for "${artifactName}" in this workflow run`) const requestHeaders = {
accept: 'application/json',
let response authorization: `Bearer ${runtimeToken}`
try { }
const twirpResponse = await artifactClient.listArtifacts() const requestOptions = {
response = wrapTwirpResponseLikeOctokit(twirpResponse, requestOptions) method: 'GET',
} catch (twirpError) { url: artifactExchangeUrl,
core.error('Listing artifact metadata failed', twirpError) headers: {
const octokitError = wrapTwirpErrorLikeOctokit(twirpError, requestOptions) ...requestHeaders
throw octokitError },
body: null
} }
const filteredArtifacts = response.data.artifacts.filter(artifact => artifact.name === artifactName) core.info(`Artifact exchange URL: ${artifactExchangeUrl}`)
const res = await httpClient.get(artifactExchangeUrl, requestHeaders)
const artifactCount = filteredArtifacts.length // May throw a RequestError (HttpError)
core.debug(`List artifact count: ${artifactCount}`) const response = await processRuntimeResponse(res, requestOptions)
if (artifactCount === 0) { data = response.data
throw new Error( core.debug(JSON.stringify(data))
`No artifacts named "${artifactName}" were found for this workflow run. Ensure artifacts are uploaded with actions/artifact@v4 or later.`
)
} else if (artifactCount > 1) {
throw new Error(
`Multiple artifacts named "${artifactName}" were unexpectedly found for this workflow run. Artifact count is ${artifactCount}.`
)
}
const artifact = filteredArtifacts[0]
core.debug(`Artifact: ${JSON.stringify(artifact)}`)
if (!artifact.size) {
core.warning('Artifact size was not found. Unable to verify if artifact size exceeds the allowed size.')
}
return artifact
} catch (error) { } catch (error) {
core.error( core.error('Getting signed artifact URL failed', 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.',
error
)
throw error throw error
} }
const artifact = data?.value?.find(artifact => artifact.name === artifactName)
const artifactRawUrl = artifact?.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 signedArtifactUrl = `${artifactRawUrl}&%24expand=SignedContent`
const artifactSize = artifact?.size
if (!artifactSize) {
core.warning('Artifact size was not found. Unable to verify if artifact size exceeds the allowed size.')
}
return {
url: signedArtifactUrl,
size: artifactSize
}
} }
async function createPagesDeployment({ githubToken, artifactId, buildVersion, idToken, isPreview = false }) { async function createPagesDeployment({ githubToken, artifactUrl, buildVersion, idToken, isPreview = false }) {
const octokit = github.getOctokit(githubToken) const octokit = github.getOctokit(githubToken)
const payload = { const payload = {
artifact_id: artifactId, artifact_url: artifactUrl,
pages_build_version: buildVersion, pages_build_version: buildVersion,
oidc_token: idToken oidc_token: idToken
} }
@@ -172,7 +173,7 @@ async function cancelPagesDeployment({ githubToken, deploymentId }) {
} }
module.exports = { module.exports = {
getArtifactMetadata, getSignedArtifactMetadata,
createPagesDeployment, createPagesDeployment,
getPagesDeploymentStatus, getPagesDeploymentStatus,
cancelPagesDeployment cancelPagesDeployment

View File

@@ -3,7 +3,9 @@ const core = require('@actions/core')
// Load variables from Actions runtime // Load variables from Actions runtime
function getRequiredVars() { function getRequiredVars() {
return { return {
runTimeUrl: process.env.ACTIONS_RUNTIME_URL,
workflowRun: process.env.GITHUB_RUN_ID, workflowRun: process.env.GITHUB_RUN_ID,
runTimeToken: process.env.ACTIONS_RUNTIME_TOKEN,
repositoryNwo: process.env.GITHUB_REPOSITORY, repositoryNwo: process.env.GITHUB_REPOSITORY,
buildVersion: process.env.GITHUB_SHA, buildVersion: process.env.GITHUB_SHA,
buildActor: process.env.GITHUB_ACTOR, 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 // All variables we need from the runtime are loaded here
const getContext = require('./context') const getContext = require('./context')
const { const {
getArtifactMetadata, getSignedArtifactMetadata,
createPagesDeployment, createPagesDeployment,
getPagesDeploymentStatus, getPagesDeploymentStatus,
cancelPagesDeployment cancelPagesDeployment
@@ -17,7 +17,6 @@ const temporaryErrorStatus = {
const finalErrorStatus = { const finalErrorStatus = {
deployment_failed: 'Deployment failed, try again later.', deployment_failed: 'Deployment failed, try again later.',
deployment_perms_error: 'Deployment failed. Please ensure that the file permissions are correct.',
deployment_content_failed: deployment_content_failed:
'Artifact could not be deployed. Please ensure the content does not contain any hard links, symlinks and total size is less than 10GB.', 'Artifact could not be deployed. Please ensure the content does not contain any hard links, symlinks and total size is less than 10GB.',
deployment_cancelled: 'Deployment cancelled.', deployment_cancelled: 'Deployment cancelled.',
@@ -31,7 +30,9 @@ const SIZE_LIMIT_DESCRIPTION = '1 GB'
class Deployment { class Deployment {
constructor() { constructor() {
const context = getContext() const context = getContext()
this.runTimeUrl = context.runTimeUrl
this.repositoryNwo = context.repositoryNwo this.repositoryNwo = context.repositoryNwo
this.runTimeToken = context.runTimeToken
this.buildVersion = context.buildVersion this.buildVersion = context.buildVersion
this.buildActor = context.buildActor this.buildActor = context.buildActor
this.actionsId = context.actionsId this.actionsId = context.actionsId
@@ -44,26 +45,41 @@ class Deployment {
this.isPreview = context.isPreview === true this.isPreview = context.isPreview === true
this.timeout = MAX_TIMEOUT this.timeout = MAX_TIMEOUT
this.startTime = null this.startTime = null
this.maxErrorCount = null
} }
// Call GitHub api to fetch artifacts matching the provided name and deploy to GitHub Pages setOptionalUserInput() {
// by creating a deployment with that artifact id const timeoutInput = Number(core.getInput('timeout'))
async create(idToken) { if (timeoutInput > MAX_TIMEOUT) {
if (Number(core.getInput('timeout')) > MAX_TIMEOUT) {
core.warning( core.warning(
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.` `Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
) )
} }
const timeoutInput = Number(core.getInput('timeout'))
this.timeout = !timeoutInput || timeoutInput <= 0 ? MAX_TIMEOUT : Math.min(timeoutInput, MAX_TIMEOUT) this.timeout = !timeoutInput || timeoutInput <= 0 ? MAX_TIMEOUT : Math.min(timeoutInput, MAX_TIMEOUT)
const maxErrorCountInput = Number(core.getInput('error_count'))
if (!maxErrorCountInput || maxErrorCountInput <= 0) {
core.warning('Invalid error_count value will be ignored. Please ensure the value is a positive integer.')
} else {
this.maxErrorCount = maxErrorCountInput
}
}
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
// by creating a deployment with that artifact
async create(idToken) {
try { try {
this.setOptionalUserInput()
core.debug(`Actor: ${this.buildActor}`) core.debug(`Actor: ${this.buildActor}`)
core.debug(`Action ID: ${this.actionsId}`) core.debug(`Action ID: ${this.actionsId}`)
core.debug(`Actions Workflow Run ID: ${this.workflowRun}`) core.debug(`Actions Workflow Run ID: ${this.workflowRun}`)
const artifactData = await getArtifactMetadata({ artifactName: this.artifactName }) const artifactData = await getSignedArtifactMetadata({
runtimeToken: this.runTimeToken,
workflowRunId: this.workflowRun,
artifactName: this.artifactName
})
if (artifactData?.size > ONE_GIGABYTE) { if (artifactData?.size > ONE_GIGABYTE) {
core.warning( core.warning(
@@ -73,7 +89,7 @@ class Deployment {
const deployment = await createPagesDeployment({ const deployment = await createPagesDeployment({
githubToken: this.githubToken, githubToken: this.githubToken,
artifactId: artifactData.id, artifactUrl: artifactData.url,
buildVersion: this.buildVersion, buildVersion: this.buildVersion,
idToken, idToken,
isPreview: this.isPreview isPreview: this.isPreview
@@ -96,16 +112,19 @@ class Deployment {
} catch (error) { } catch (error) {
core.error(error.stack) core.error(error.stack)
// output raw error in debug mode.
core.debug(JSON.stringify(error))
// build customized error message based on server response // build customized error message based on server response
if (error.response) { if (error.response) {
let errorMessage = `Failed to create deployment (status: ${error.status}) with build version ${this.buildVersion}.` let errorMessage = `Failed to create deployment (status: ${error.status}) with build version ${this.buildVersion}. `
if (error.status === 400) { if (error.status === 400) {
errorMessage += ` Responded with: ${error.message}` errorMessage += `Responded with: ${error.message}`
} else if (error.status === 403) { } else if (error.status === 403) {
errorMessage += ' Ensure GITHUB_TOKEN has permission "pages: write".' errorMessage += 'Ensure GITHUB_TOKEN has permission "pages: write".'
} else if (error.status === 404) { } else if (error.status === 404) {
const pagesSettingsUrl = `${this.githubServerUrl}/${this.repositoryNwo}/settings/pages` const pagesSettingsUrl = `${this.githubServerUrl}/${this.repositoryNwo}/settings/pages`
errorMessage += ` Ensure GitHub Pages has been enabled: ${pagesSettingsUrl}` errorMessage += `Ensure GitHub Pages has been enabled: ${pagesSettingsUrl}`
// If using GHES, add a special note about compatibility // If using GHES, add a special note about compatibility
if (new URL(this.githubServerUrl).hostname.toLowerCase() !== 'github.com') { if (new URL(this.githubServerUrl).hostname.toLowerCase() !== 'github.com') {
errorMessage += errorMessage +=
@@ -113,7 +132,7 @@ class Deployment {
} }
} else if (error.status >= 500) { } else if (error.status >= 500) {
errorMessage += errorMessage +=
' Server error, is githubstatus.com reporting a Pages outage? Please re-run the deployment at a later time.' 'Server error, is githubstatus.com reporting a Pages outage? Please re-run the deployment at a later time.'
} }
throw new Error(errorMessage) throw new Error(errorMessage)
} else { } else {
@@ -137,7 +156,6 @@ class Deployment {
const deploymentId = this.deploymentInfo.id || this.buildVersion const deploymentId = this.deploymentInfo.id || this.buildVersion
const reportingInterval = Number(core.getInput('reporting_interval')) const reportingInterval = Number(core.getInput('reporting_interval'))
const maxErrorCount = Number(core.getInput('error_count'))
let errorCount = 0 let errorCount = 0
@@ -180,6 +198,9 @@ class Deployment {
} catch (error) { } catch (error) {
core.error(error.stack) core.error(error.stack)
// output raw error in debug mode.
core.debug(JSON.stringify(error))
// build customized error message based on server response // build customized error message based on server response
if (error.response) { if (error.response) {
errorStatus = error.status || error.response.status errorStatus = error.status || error.response.status
@@ -193,7 +214,7 @@ class Deployment {
} }
} }
if (errorCount >= maxErrorCount) { if (errorCount >= this.maxErrorCount) {
core.error('Too many errors, aborting!') core.error('Too many errors, aborting!')
core.setFailed('Failed with status code: ' + errorStatus) core.setFailed('Failed with status code: ' + errorStatus)