From 291c5c792e28160dd5f6cdb7b1137477d15641cd Mon Sep 17 00:00:00 2001 From: Axel Hecht Date: Tue, 5 Jan 2021 16:39:10 +0100 Subject: [PATCH] Hyphenate inputs and outputs, add step output, fix #558 (#559) * Hyphenate inputs and outputs, add step output, fix #558 I've also tried to make the clean docs a bit clearer, and consistent about clean being on my default. Still not totally happy with the intro of the docs there, though. * Add testing of step outputs to build integration tests --- .github/workflows/build.yml | 27 +++++++++++++++++++---- .github/workflows/integration.yml | 16 +++++++------- README.md | 18 +++++++++------- __tests__/git.test.ts | 1 + __tests__/main.test.ts | 1 + action.yml | 36 +++++++++++++++---------------- src/constants.ts | 24 ++++++++++----------- src/lib.ts | 3 ++- 8 files changed, 75 insertions(+), 51 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad8d4536..199f7291 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -91,12 +91,22 @@ jobs: name: dist - name: Deploy + id: unmodified uses: ./ with: folder: integration branch: ${{ matrix.branch }} - SINGLE_COMMIT: ${{ matrix.commit == 'singleCommit' }} - dry_run: true + single-commit: ${{ matrix.commit == 'singleCommit' }} + dry-run: true + + # Usually, this should be skipped, but if the upstream gh-pages + # branch doesn't match ours, it should still be a success. + - name: Check step output + run: | + [[ \ + ${{steps.unmodified.outputs.deployment-status}} = skipped || \ + ${{steps.unmodified.outputs.deployment-status}} = success \ + ]] - name: Tweak content to publish to existing branch if: ${{ matrix.branch == 'gh-pages' }} @@ -104,10 +114,19 @@ jobs: echo "" >> integration/index.html - name: Deploy with modifications to existing branch + id: modified uses: ./ if: ${{ matrix.branch == 'gh-pages' }} with: folder: integration branch: ${{ matrix.branch }} - single_commit: ${{ matrix.commit == 'singleCommit' }} - dry_run: true + single-commit: ${{ matrix.commit == 'singleCommit' }} + dry-run: true + + # The modified deployment should be a success, and not skipped. + - name: Check step output + if: ${{ matrix.branch == 'gh-pages' }} + run: | + [[ \ + ${{steps.modified.outputs.deployment-status}} = success \ + ]] diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 2d1de3f6..f46ad8b6 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -23,9 +23,9 @@ jobs: token: ${{ secrets.ACCESS_TOKEN }} branch: gh-pages folder: integration - target_folder: cat/montezuma - git_config_name: Montezuma - git_config_email: montezuma@jamesiv.es + target-folder: cat/montezuma + git-config-name: Montezuma + git-config-email: montezuma@jamesiv.es - name: Cleanup Generated Branch uses: dawidd6/action-delete-branch@v2.0.1 @@ -48,7 +48,7 @@ jobs: with: branch: gh-pages folder: integration - target_folder: cat/montezuma2 + target-folder: cat/montezuma2 - name: Cleanup Generated Branch uses: dawidd6/action-delete-branch@v2.0.1 @@ -80,7 +80,7 @@ jobs: with: branch: gh-pages folder: integration - target_folder: cat/montezuma2 + target-folder: cat/montezuma2 - name: Cleanup Generated Branch uses: dawidd6/action-delete-branch@v2.0.1 @@ -109,7 +109,7 @@ jobs: ssh: true branch: gh-pages folder: integration - target_folder: cat/montezuma3 + target-folder: cat/montezuma3 - name: Cleanup Generated Branch uses: dawidd6/action-delete-branch@v2.0.1 @@ -142,7 +142,7 @@ jobs: ssh: true branch: gh-pages folder: integration - target_folder: cat/montezuma4 + target-folder: cat/montezuma4 - name: Cleanup Generated Branch uses: dawidd6/action-delete-branch@v2.0.1 @@ -184,7 +184,7 @@ jobs: token: ${{ secrets.ACCESS_TOKEN }} branch: integration-test-delete-prod folder: integration - single_commit: true + single-commit: true - name: Cleanup Generated Branch uses: dawidd6/action-delete-branch@v2.0.1 diff --git a/README.md b/README.md index ddeeb655..9de87010 100644 --- a/README.md +++ b/README.md @@ -138,15 +138,15 @@ By default the action does not need any token configuration and uses the provide | Key | Value Information | Type | Required | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- | -| `git_config_name` | Allows you to customize the name that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the name in the GitHub context, followed by the name of the action. | `with` | **No** | -| `git_config_email` | Allows you to customize the email that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the email in the GitHub context, followed by a generic noreply GitHub email. | `with` | **No** | -| `repository_name` | Allows you to specify a different repository path so long as you have permissions to push to it. This should be formatted like so: `JamesIves/github-pages-deploy-action`. You'll need to use a PAT in the `token` input for this configuration option to work properly. | `with` | **No** | -| `target_folder` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** | -| `commit_message` | If you need to customize the commit message for an integration you can do so. | `with` | **No** | -| `clean` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option is turned on by default, and can be toggled off by setting it to `false`. | `with` | **No** | +| `git-config-name` | Allows you to customize the name that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the name in the GitHub context, followed by the name of the action. | `with` | **No** | +| `git-config-email` | Allows you to customize the email that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the email in the GitHub context, followed by a generic noreply GitHub email. | `with` | **No** | +| `repository-name` | Allows you to specify a different repository path so long as you have permissions to push to it. This should be formatted like so: `JamesIves/github-pages-deploy-action`. You'll need to use a PAT in the `token` input for this configuration option to work properly. | `with` | **No** | +| `target-folder` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** | +| `commit-message` | If you need to customize the commit message for an integration you can do so. | `with` | **No** | +| `clean` | If your project generates hashed files on build you can use this option to automatically delete them from the target folder on the deployment branch with each deploy. This option is turned on by default, and can be toggled off by setting it to `false`. | `with` | **No** | | `clean-exclude` | If you need to use `clean` but you'd like to preserve certain files or folders you can use this option. This should contain each pattern as a single line in a multiline string. | `with` | **No** | -| `dry_run` | Do not actually push back, but use `--dry-run` on `git push` invocations insead. | `with` | **No** | -| `single_commit` | This option can be toggled to `true` if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history. **Using this option will also cause any existing history to be wiped from the deployment branch**. | `with` | **No** | +| `dry-run` | Do not actually push back, but use `--dry-run` on `git push` invocations insead. | `with` | **No** | +| `single-commit` | This option can be toggled to `true` if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history. **Using this option will also cause any existing history to be wiped from the deployment branch**. | `with` | **No** | | `silent` | Silences the action output preventing it from displaying git messages. | `with` | **No** | | `workspace` | This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only necessary to set this variable if you're using the node module. | `with` | **No** | @@ -162,6 +162,8 @@ The action will export an environment variable called `deployment_status` that y | `failed` | The `failed` status indicates that the action encountered an error while trying to deploy. | | `skipped` | The `skipped` status indicates that the action exited early as there was nothing new to deploy. | +This value is also set as a step output as `deployment-status`. + --- ### Using an SSH Deploy Key 🔑 diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index e621385a..b6d38e76 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -18,6 +18,7 @@ jest.mock('fs', () => ({ jest.mock('@actions/core', () => ({ setFailed: jest.fn(), getInput: jest.fn(), + setOutput: jest.fn(), isDebug: jest.fn(), info: jest.fn() })) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 4d02492f..fc5b9d3b 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -24,6 +24,7 @@ jest.mock('@actions/io', () => ({ jest.mock('@actions/core', () => ({ setFailed: jest.fn(), getInput: jest.fn(), + setOutput: jest.fn(), exportVariable: jest.fn(), isDebug: jest.fn(), info: jest.fn() diff --git a/action.yml b/action.yml index 50aaba54..00e1398e 100644 --- a/action.yml +++ b/action.yml @@ -8,11 +8,11 @@ branding: icon: 'git-commit' color: 'orange' inputs: - SSH: + ssh: description: 'You can configure the action to deploy using SSH by setting this option to true. More more information on how to add your ssh key pair please refer to the Using a Deploy Key section of this README.' required: false - TOKEN: + token: description: > This option defaults to the repository scoped GitHub Token. However if you need more permissions for things such as deploying to another repository, you can add a Personal Access Token (PAT) here. @@ -25,59 +25,59 @@ inputs: required: false default: ${{ github.token }} - BRANCH: + branch: description: 'This is the branch you wish to deploy to, for example gh-pages or docs.' required: true - FOLDER: + folder: description: 'The folder in your repository that you want to deploy. If your build script compiles into a directory named build you would put it here. Folder paths cannot have a leading / or ./. If you wish to deploy the root directory you can place a . here.' required: true - TARGET_FOLDER: + target-folder: description: 'If you would like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here.' required: false - COMMIT_MESSAGE: + commit-message: description: 'If you need to customize the commit message for an integration you can do so.' required: false - CLEAN: - description: 'If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to true.' + clean: + description: 'If your project generates hashed files on build you can use this option to automatically delete them from the target folder on the deployment branch with each deploy. This option is on by default and can be toggled off by setting it to false.' required: false - default: 'true' + default: true clean-exclude: - description: "If you need to use CLEAN but you would like to preserve certain files or folders you can use this option. This should contain each pattern as a single line in a multiline string." + description: "If you need to use clean but you would like to preserve certain files or folders you can use this option. This should contain each pattern as a single line in a multiline string." required: false - DRY_RUN: + dry-run: description: "Do not actually push back, but use `--dry-run` on `git push` invocations insead." required: false - GIT_CONFIG_NAME: + git-config-name: description: "Allows you to customize the name that is attached to the GitHub config which is used when pushing the deployment commits. If this is not included it will use the name in the GitHub context, followed by the name of the action." required: false - GIT_CONFIG_EMAIL: + git-config-email: description: "Allows you to customize the email that is attached to the GitHub config which is used when pushing the deployment commits. If this is not included it will use the email in the GitHub context, followed by a generic noreply GitHub email." required: false - REPOSITORY_NAME: + repository-name: description: "Allows you to speicfy a different repository path so long as you have permissions to push to it. This should be formatted like so: JamesIves/github-pages-deploy-action" required: false - WORKSPACE: + workspace: description: "This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only neccersary to set this variable if you're using the node module." required: false - SINGLE_COMMIT: + 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 - SILENT: + silent: description: "Silences the action output preventing it from displaying git messages." required: false outputs: - DEPLOYMENT_STATUS: + deployment-status: description: 'The status of the deployment that indicates if the run failed or passed. Possible outputs include: success|failed|skipped' diff --git a/src/constants.ts b/src/constants.ts index 097612f5..2990871e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -76,9 +76,9 @@ export interface NodeActionInterface { export const action: ActionInterface = { folder: getInput('folder'), branch: getInput('branch'), - commitMessage: getInput('commit_message'), - dryRun: !isNullOrUndefined(getInput('dry_run')) - ? getInput('dry_run').toLowerCase() === 'true' + commitMessage: getInput('commit-message'), + dryRun: !isNullOrUndefined(getInput('dry-run')) + ? getInput('dry-run').toLowerCase() === 'true' : false, clean: !isNullOrUndefined(getInput('clean')) ? getInput('clean').toLowerCase() === 'true' @@ -87,28 +87,28 @@ export const action: ActionInterface = { .split('\n') .filter(l => l !== ''), isTest: TestFlag.NONE, - email: !isNullOrUndefined(getInput('git_config_email')) - ? getInput('git_config_email') + email: !isNullOrUndefined(getInput('git-config-email')) + ? getInput('git-config-email') : pusher && pusher.email ? pusher.email : `${ process.env.GITHUB_ACTOR || 'github-pages-deploy-action' }@users.noreply.github.com`, - name: !isNullOrUndefined(getInput('git_config_name')) - ? getInput('git_config_name') + name: !isNullOrUndefined(getInput('git-config-name')) + ? getInput('git-config-name') : pusher && pusher.name ? pusher.name : process.env.GITHUB_ACTOR ? process.env.GITHUB_ACTOR : 'GitHub Pages Deploy Action', - repositoryName: !isNullOrUndefined(getInput('repository_name')) - ? getInput('repository_name') + repositoryName: !isNullOrUndefined(getInput('repository-name')) + ? getInput('repository-name') : repository && repository.full_name ? repository.full_name : process.env.GITHUB_REPOSITORY, token: getInput('token'), - singleCommit: !isNullOrUndefined(getInput('single_commit')) - ? getInput('single_commit').toLowerCase() === 'true' + singleCommit: !isNullOrUndefined(getInput('single-commit')) + ? getInput('single-commit').toLowerCase() === 'true' : false, silent: !isNullOrUndefined(getInput('silent')) ? getInput('silent').toLowerCase() === 'true' @@ -116,7 +116,7 @@ export const action: ActionInterface = { ssh: !isNullOrUndefined(getInput('ssh')) ? getInput('ssh').toLowerCase() === 'true' : false, - targetFolder: getInput('target_folder'), + targetFolder: getInput('target-folder'), workspace: process.env.GITHUB_WORKSPACE || '' } diff --git a/src/lib.ts b/src/lib.ts index 072b24ea..9b3a3434 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,4 +1,4 @@ -import {exportVariable, info, setFailed} from '@actions/core' +import {exportVariable, info, setFailed, setOutput} from '@actions/core' import {ActionInterface, Status, NodeActionInterface} from './constants' import {deploy, init} from './git' import { @@ -60,5 +60,6 @@ export default async function run( ) exportVariable('deployment_status', status) + setOutput('deployment-status', status) } }