mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Deploy Status (#296)
* Deploy Status changes * DEPLOY_STATUS -> DEPLOYMENT_STATUS
This commit is contained in:
parent
a524440a72
commit
1ada96b8f7
10
README.md
10
README.md
@ -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 🔑
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
@ -67,3 +67,7 @@ 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
|
||||
|
||||
outputs:
|
||||
DEPLOYMENT_STATUS:
|
||||
description: 'The status of the deployment that indicates if the run failed or passed. Possible outputs include: success|failed|skipped'
|
@ -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'
|
||||
}
|
||||
|
@ -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(
|
||||
|
19
src/lib.ts
19
src/lib.ts
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user