Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some fixes
  • Loading branch information
Greta Parks authored and Greta Parks committed May 12, 2023
1 parent c02d64f commit ccca7e9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion coverage_badge.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 17 additions & 17 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions src/__tests__/internal/deployment.test.js
@@ -1,7 +1,7 @@
const core = require('@actions/core')
const nock = require('nock')

const { Deployment, maxTimeout } = require('../../internal/deployment')
const { Deployment, MAX_TIMEOUT } = require('../../internal/deployment')

const fakeJwt =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w'
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('Deployment', () => {
case 'token':
return process.env.GITHUB_TOKEN
case 'timeout':
return maxTimeout + 1
return MAX_TIMEOUT + 1
default:
return process.env[`INPUT_${param.toUpperCase()}`] || ''
}
Expand All @@ -290,7 +290,7 @@ describe('Deployment', () => {
await deployment.create(fakeJwt)

expect(core.warning).toBeCalledWith(
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${maxTimeout} milliseconds.`
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
)

artifactExchangeScope.done()
Expand Down Expand Up @@ -421,15 +421,17 @@ describe('Deployment', () => {
return 'github-pages'
case 'token':
return process.env.GITHUB_TOKEN
case 'error_count':
return 10
case 'timeout':
return maxTimeout + 1
return MAX_TIMEOUT + 1
default:
return process.env[`INPUT_${param.toUpperCase()}`] || ''
}
})

const now = Date.now()
const mockStartTime = now - maxTimeout
const mockStartTime = now - MAX_TIMEOUT
jest
.spyOn(Date, 'now')
.mockImplementationOnce(() => mockStartTime)
Expand All @@ -440,7 +442,7 @@ describe('Deployment', () => {
await deployment.create(fakeJwt)
await deployment.check()

expect(deployment.timeout).toEqual(maxTimeout)
expect(deployment.timeout).toEqual(MAX_TIMEOUT)
expect(core.error).toBeCalledWith('Timeout reached, aborting!')
expect(core.setFailed).toBeCalledWith('Timeout reached, aborting!')

Expand Down Expand Up @@ -485,6 +487,8 @@ describe('Deployment', () => {
return 'github-pages'
case 'token':
return process.env.GITHUB_TOKEN
case 'error_count':
return 10
case 'timeout':
return 42
default:
Expand Down Expand Up @@ -551,6 +555,8 @@ describe('Deployment', () => {
return 'github-pages'
case 'token':
return process.env.GITHUB_TOKEN
case 'error_count':
return 10
case 'timeout':
return 42
default:
Expand Down
34 changes: 17 additions & 17 deletions src/internal/deployment.js
Expand Up @@ -23,7 +23,7 @@ const finalErrorStatus = {
deployment_lost: 'Deployment failed to report final status.'
}

const maxTimeout = 600000
const MAX_TIMEOUT = 600000

class Deployment {
constructor() {
Expand All @@ -41,21 +41,21 @@ class Deployment {
this.githubServerUrl = context.githubServerUrl
this.artifactName = context.artifactName
this.isPreview = context.isPreview === true
this.timeout = maxTimeout
this.timeout = MAX_TIMEOUT
this.startTime = null
}

// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
// by creating a deployment with that artifact
async create(idToken) {
if (Number(core.getInput('timeout')) > maxTimeout) {
if (Number(core.getInput('timeout')) > MAX_TIMEOUT) {
core.warning(
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${maxTimeout} milliseconds.`
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
)
}

let timeoutInput = Number(core.getInput('timeout'))
this.timeout = (!timeoutInput || timeoutInput <= 0) ? maxTimeout : Math.min(timeoutInput, maxTimeout)
const TIMEOUT_INPUT = Number(core.getInput('timeout'))
this.timeout = !TIMEOUT_INPUT || TIMEOUT_INPUT <= 0 ? MAX_TIMEOUT : Math.min(TIMEOUT_INPUT, MAX_TIMEOUT)

try {
core.debug(`Actor: ${this.buildActor}`)
Expand Down Expand Up @@ -143,16 +143,6 @@ class Deployment {

/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
while (true) {
// Handle timeout
if (Date.now() - this.startTime >= this.timeout) {
core.error('Timeout reached, aborting!')
core.setFailed('Timeout reached, aborting!')

// Explicitly cancel the deployment
await this.cancel()
return
}

// Handle reporting interval
await new Promise(resolve => setTimeout(resolve, reportingInterval + errorReportingInterval))

Expand Down Expand Up @@ -209,6 +199,16 @@ class Deployment {
await this.cancel()
return
}

// Handle timeout
if (Date.now() - this.startTime >= this.timeout) {
core.error('Timeout reached, aborting!')
core.setFailed('Timeout reached, aborting!')

// Explicitly cancel the deployment
await this.cancel()
return
}
}
}

Expand Down Expand Up @@ -238,4 +238,4 @@ class Deployment {
}
}

module.exports = { Deployment, maxTimeout }
module.exports = { Deployment, MAX_TIMEOUT }

0 comments on commit ccca7e9

Please sign in to comment.