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
17 changed files with 1988 additions and 26296 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

@@ -67,6 +67,10 @@ 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:
@@ -89,11 +93,12 @@ This action is primarily design for use with GitHub.com's Actions workflows and
| Release | GHES Compatibility | | Release | GHES Compatibility |
|:---|:---| |:---|:---|
| [`v2`](https://github.com/actions/deploy-pages/releases/tag/v2) | `>= 3.9` | | [`v2`](https://github.com/actions/deploy-pages/releases/tag/v2) | 🛑 Incompatible. Anticipating compatibility with `>= 3.9`. |
| `v2.x.x` | `>= 3.9` | | [`v2.0.1`](https://github.com/actions/deploy-pages/releases/tag/v2.0.1) | 🛑 Incompatible. Anticipating compatibility with `>= 3.9`. |
| [`v2.0.0`](https://github.com/actions/deploy-pages/releases/tag/v2.0.0) | 🛑 Incompatible. Anticipating compatibility with `>= 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` |

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: 79.53%"><title>Coverage: 79.53%</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="#e05d44"/><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">79.53%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">79.53%</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

23790
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

47
dist/licenses.txt generated vendored
View File

@@ -47,28 +47,6 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@fastify/busboy
MIT
Copyright Brian White. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
@octokit/auth-token @octokit/auth-token
MIT MIT
The MIT License The MIT License
@@ -575,31 +553,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
undici
MIT
MIT License
Copyright (c) Matteo Collina and Undici contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
universal-user-agent universal-user-agent
ISC ISC
# [ISC License](https://spdx.org/licenses/ISC) # [ISC License](https://spdx.org/licenses/ISC)

4217
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,18 +6,18 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/github": "^5.1.1", "@actions/github": "^5.1.1",
"@actions/http-client": "^2.2.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.54.0", "eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.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",
"nock": "^13.3.8", "nock": "^13.3.1",
"prettier": "^3.1.0", "prettier": "^2.8.8",
"make-coverage-badge": "^1.2.0" "make-coverage-badge": "^1.2.0"
}, },
"scripts": { "scripts": {

View File

@@ -44,6 +44,101 @@ describe('Deployment', () => {
jest.spyOn(core, 'debug').mockImplementation(jest.fn()) jest.spyOn(core, 'debug').mockImplementation(jest.fn())
}) })
describe('#setOptionalUserInput', () => {
it('warns when the timeout is greater than the maximum allowed', async () => {
jest.spyOn(core, 'getInput').mockImplementation(param => {
switch (param) {
case 'timeout':
return MAX_TIMEOUT + 1
default:
return process.env[`INPUT_${param.toUpperCase()}`] || ''
}
})
const deployment = new Deployment()
deployment.setOptionalUserInput()
expect(deployment.timeout).toBe(MAX_TIMEOUT)
expect(core.warning).toBeCalledWith(
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
)
})
it('sets the error_count input when valid', async () => {
jest.spyOn(core, 'getInput').mockImplementation(param => {
switch (param) {
case 'error_count':
return '1'
default:
return process.env[`INPUT_${param.toUpperCase()}`] || ''
}
})
// Create the deployment
const deployment = new Deployment()
deployment.setOptionalUserInput()
expect(deployment.maxErrorCount).toBe(1)
})
it('sets the error_count input to null if zero and warns user', async () => {
jest.spyOn(core, 'getInput').mockImplementation(param => {
switch (param) {
case 'error_count':
return '0'
default:
return process.env[`INPUT_${param.toUpperCase()}`] || ''
}
})
const deployment = new Deployment()
deployment.setOptionalUserInput()
expect(deployment.maxErrorCount).toBe(null)
expect(core.warning).toHaveBeenCalledWith(
'Invalid error_count value will be ignored. Please ensure the value is a positive integer.'
)
})
it('sets the error_count input to null if negative and warns user', async () => {
jest.spyOn(core, 'getInput').mockImplementation(param => {
switch (param) {
case 'error_count':
return '-1'
default:
return process.env[`INPUT_${param.toUpperCase()}`] || ''
}
})
const deployment = new Deployment()
deployment.setOptionalUserInput()
expect(deployment.maxErrorCount).toBe(null)
expect(core.warning).toHaveBeenCalledWith(
'Invalid error_count value will be ignored. Please ensure the value is a positive integer.'
)
})
it('sets the error_count input to null if not a number and warns user', async () => {
jest.spyOn(core, 'getInput').mockImplementation(param => {
switch (param) {
case 'error_count':
return 'not a number'
default:
return process.env[`INPUT_${param.toUpperCase()}`] || ''
}
})
const deployment = new Deployment()
deployment.setOptionalUserInput()
expect(deployment.maxErrorCount).toBe(null)
expect(core.warning).toHaveBeenCalledWith(
'Invalid error_count value will be ignored. Please ensure the value is a positive integer.'
)
})
})
describe('#create', () => { describe('#create', () => {
afterEach(() => { afterEach(() => {
// Remove mock for `core.getInput('preview')` // Remove mock for `core.getInput('preview')`
@@ -88,6 +183,42 @@ describe('Deployment', () => {
createDeploymentScope.done() createDeploymentScope.done()
}) })
it('invokes #setOptionalUserInput', async () => {
process.env.GITHUB_SHA = 'valid-build-version'
const artifactExchangeScope = 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' }
]
})
const createDeploymentScope = nock('https://api.github.com')
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
pages_build_version: process.env.GITHUB_SHA,
oidc_token: fakeJwt
})
.reply(200, {
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
page_url: 'https://actions.github.io/is-awesome'
})
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
// Create the deployment
const deployment = new Deployment()
deployment.setOptionalUserInput = jest.fn()
await deployment.create(fakeJwt)
expect(deployment.setOptionalUserInput).toHaveBeenCalled()
artifactExchangeScope.done()
createDeploymentScope.done()
})
it('can successfully create a preview deployment', async () => { it('can successfully create a preview deployment', async () => {
process.env.GITHUB_SHA = 'valid-build-version' process.env.GITHUB_SHA = 'valid-build-version'
@@ -587,7 +718,6 @@ describe('Deployment', () => {
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
// Set timeout to great than max
jest.spyOn(core, 'getInput').mockImplementation(param => { jest.spyOn(core, 'getInput').mockImplementation(param => {
switch (param) { switch (param) {
case 'artifact_name': case 'artifact_name':

View File

@@ -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.',
@@ -46,21 +45,32 @@ 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
}
setOptionalUserInput() {
const timeoutInput = Number(core.getInput('timeout'))
if (timeoutInput > MAX_TIMEOUT) {
core.warning(
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
)
}
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 // Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
// by creating a deployment with that artifact // by creating a deployment with that artifact
async create(idToken) { async create(idToken) {
if (Number(core.getInput('timeout')) > MAX_TIMEOUT) {
core.warning(
`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)
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}`)
@@ -102,6 +112,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) {
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}. `
@@ -143,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
@@ -186,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
@@ -199,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)