Deploy Status (#296)

* Deploy Status changes

* DEPLOY_STATUS -> DEPLOYMENT_STATUS
This commit is contained in:
James Ives 2020-05-14 17:24:32 -04:00 committed by GitHub
parent a524440a72
commit 1ada96b8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 15 deletions

View File

@ -151,6 +151,16 @@ In addition to the deployment options you must also configure the following.
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
#### Deployment Status
The action will export an environment variable called `DEPLOYMENT_STATUS` that you can use in your workflow to determine if the deployment was successful or not. You can find an explanation of each status code below.
| Status | Description |
| ------------- |:-------------:|
| `success` | The `success` status indicates that the action was able to successfully deploy the project to the branch. |
| `failed` | The `failed` status indicates that the action encountered an error while trying to deploy the project. |
| `skipped` | The `skipped` status indicates that the action exited early as there was nothing new to deploy. |
---
### Using an SSH Deploy Key 🔑

View File

@ -88,7 +88,7 @@ describe('git', () => {
pusher: {
name: 'asd',
email: 'as@cat'
},
}
})
try {
@ -110,7 +110,7 @@ describe('git', () => {
name: 'asd',
email: 'as@cat'
},
accessToken: '',
accessToken: ''
})
try {

View File

@ -8,7 +8,7 @@ import {action} from '../src/constants'
import run from '../src/lib'
import {execute} from '../src/execute'
import {rmRF} from '@actions/io'
import {setFailed} from '@actions/core'
import {setFailed, exportVariable} from '@actions/core'
const originalAction = JSON.stringify(action)
@ -49,6 +49,24 @@ describe('main', () => {
await run(action)
expect(execute).toBeCalledTimes(18)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
it('should run through the commands and succeed', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build',
branch: 'branch',
gitHubToken: '123',
pusher: {
name: 'asd',
email: 'as@cat'
}
})
await run(action)
expect(execute).toBeCalledTimes(17)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
it('should throw if an error is encountered', async () => {
@ -68,5 +86,6 @@ describe('main', () => {
await run(action)
expect(execute).toBeCalledTimes(0)
expect(setFailed).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
})

View File

@ -66,4 +66,8 @@ inputs:
SINGLE_COMMIT:
description: "This option can be used if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history."
required: false
required: false
outputs:
DEPLOYMENT_STATUS:
description: 'The status of the deployment that indicates if the run failed or passed. Possible outputs include: success|failed|skipped'

View File

@ -93,3 +93,11 @@ export const action: ActionInterface = {
targetFolder: getInput('TARGET_FOLDER'),
workspace: process.env.GITHUB_WORKSPACE || ''
}
/** Status codes for the action. */
export enum Status {
SUCCESS = 'success',
FAILED = 'failed',
SKIPPED = 'skipped',
RUNNING = 'running'
}

View File

@ -1,6 +1,6 @@
import {info} from '@actions/core'
import {rmRF, mkdirP} from '@actions/io'
import {ActionInterface} from './constants'
import {ActionInterface, Status} from './constants'
import {execute} from './execute'
import {
hasRequiredParameters,
@ -92,7 +92,7 @@ export async function generateBranch(action: ActionInterface): Promise<void> {
}
/* Runs the necessary steps to make the deployment. */
export async function deploy(action: ActionInterface): Promise<void> {
export async function deploy(action: ActionInterface): Promise<Status> {
const temporaryDeploymentDirectory = 'gh-action-temp-deployment-folder'
const temporaryDeploymentBranch = 'gh-action-temp-deployment-branch'
@ -179,8 +179,7 @@ export async function deploy(action: ActionInterface): Promise<void> {
)
if (!hasFilesToCommit && !action.isTest) {
info('There is nothing to commit. Exiting early… 📭')
return
return Status.SKIPPED
}
// Commits to GitHub.
@ -236,6 +235,8 @@ export async function deploy(action: ActionInterface): Promise<void> {
`git checkout --progress --force ${action.defaultBranch}`,
action.workspace
)
return Status.SUCCESS
} catch (error) {
throw new Error(
`The deploy step encountered an error: ${suppressSensitiveInformation(

View File

@ -1,5 +1,5 @@
import {info, setFailed} from '@actions/core'
import {action, ActionInterface} from './constants'
import {exportVariable, info, setFailed} from '@actions/core'
import {action, ActionInterface, Status} from './constants'
import {deploy, generateBranch, init} from './git'
import {generateRepositoryPath, generateTokenType} from './util'
@ -10,7 +10,7 @@ import {generateRepositoryPath, generateTokenType} from './util'
export default async function run(
configuration: ActionInterface
): Promise<void> {
let errorState = false
let status: Status = Status.RUNNING
try {
info('Checking configuration and starting deployment… 🚦')
@ -25,18 +25,23 @@ export default async function run(
settings.tokenType = generateTokenType(settings)
await init(settings)
await deploy(settings)
status = await deploy(settings)
} catch (error) {
errorState = true
status = Status.FAILED
setFailed(error.message)
} finally {
console.log(status)
info(
`${
errorState
status === Status.FAILED
? 'Deployment Failed ❌'
: 'Completed Deployment Successfully! ✅'
: status === Status.SUCCESS
? 'Completed Deployment Successfully! ✅'
: 'There is nothing to commit. Exiting early… 📭'
}`
)
exportVariable('DEPLOYMENT_STATUS', status)
}
}