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
This commit is contained in:
Axel Hecht 2021-01-05 16:39:10 +01:00 committed by GitHub
parent 7bf80b4b88
commit 291c5c792e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 51 deletions

View File

@ -91,12 +91,22 @@ jobs:
name: dist name: dist
- name: Deploy - name: Deploy
id: unmodified
uses: ./ uses: ./
with: with:
folder: integration folder: integration
branch: ${{ matrix.branch }} branch: ${{ matrix.branch }}
SINGLE_COMMIT: ${{ matrix.commit == 'singleCommit' }} single-commit: ${{ matrix.commit == 'singleCommit' }}
dry_run: true 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 - name: Tweak content to publish to existing branch
if: ${{ matrix.branch == 'gh-pages' }} if: ${{ matrix.branch == 'gh-pages' }}
@ -104,10 +114,19 @@ jobs:
echo "<!-- just sayin -->" >> integration/index.html echo "<!-- just sayin -->" >> integration/index.html
- name: Deploy with modifications to existing branch - name: Deploy with modifications to existing branch
id: modified
uses: ./ uses: ./
if: ${{ matrix.branch == 'gh-pages' }} if: ${{ matrix.branch == 'gh-pages' }}
with: with:
folder: integration folder: integration
branch: ${{ matrix.branch }} branch: ${{ matrix.branch }}
single_commit: ${{ matrix.commit == 'singleCommit' }} single-commit: ${{ matrix.commit == 'singleCommit' }}
dry_run: true 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 \
]]

View File

@ -23,9 +23,9 @@ jobs:
token: ${{ secrets.ACCESS_TOKEN }} token: ${{ secrets.ACCESS_TOKEN }}
branch: gh-pages branch: gh-pages
folder: integration folder: integration
target_folder: cat/montezuma target-folder: cat/montezuma
git_config_name: Montezuma git-config-name: Montezuma
git_config_email: montezuma@jamesiv.es git-config-email: montezuma@jamesiv.es
- name: Cleanup Generated Branch - name: Cleanup Generated Branch
uses: dawidd6/action-delete-branch@v2.0.1 uses: dawidd6/action-delete-branch@v2.0.1
@ -48,7 +48,7 @@ jobs:
with: with:
branch: gh-pages branch: gh-pages
folder: integration folder: integration
target_folder: cat/montezuma2 target-folder: cat/montezuma2
- name: Cleanup Generated Branch - name: Cleanup Generated Branch
uses: dawidd6/action-delete-branch@v2.0.1 uses: dawidd6/action-delete-branch@v2.0.1
@ -80,7 +80,7 @@ jobs:
with: with:
branch: gh-pages branch: gh-pages
folder: integration folder: integration
target_folder: cat/montezuma2 target-folder: cat/montezuma2
- name: Cleanup Generated Branch - name: Cleanup Generated Branch
uses: dawidd6/action-delete-branch@v2.0.1 uses: dawidd6/action-delete-branch@v2.0.1
@ -109,7 +109,7 @@ jobs:
ssh: true ssh: true
branch: gh-pages branch: gh-pages
folder: integration folder: integration
target_folder: cat/montezuma3 target-folder: cat/montezuma3
- name: Cleanup Generated Branch - name: Cleanup Generated Branch
uses: dawidd6/action-delete-branch@v2.0.1 uses: dawidd6/action-delete-branch@v2.0.1
@ -142,7 +142,7 @@ jobs:
ssh: true ssh: true
branch: gh-pages branch: gh-pages
folder: integration folder: integration
target_folder: cat/montezuma4 target-folder: cat/montezuma4
- name: Cleanup Generated Branch - name: Cleanup Generated Branch
uses: dawidd6/action-delete-branch@v2.0.1 uses: dawidd6/action-delete-branch@v2.0.1
@ -184,7 +184,7 @@ jobs:
token: ${{ secrets.ACCESS_TOKEN }} token: ${{ secrets.ACCESS_TOKEN }}
branch: integration-test-delete-prod branch: integration-test-delete-prod
folder: integration folder: integration
single_commit: true single-commit: true
- name: Cleanup Generated Branch - name: Cleanup Generated Branch
uses: dawidd6/action-delete-branch@v2.0.1 uses: dawidd6/action-delete-branch@v2.0.1

View File

@ -138,15 +138,15 @@ By default the action does not need any token configuration and uses the provide
| Key | Value Information | Type | Required | | 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-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** | | `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** | | `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** | | `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** | | `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** | | `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** | | `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** | | `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** | | `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** | | `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** | | `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. | | `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. | | `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 🔑 ### Using an SSH Deploy Key 🔑

View File

@ -18,6 +18,7 @@ jest.mock('fs', () => ({
jest.mock('@actions/core', () => ({ jest.mock('@actions/core', () => ({
setFailed: jest.fn(), setFailed: jest.fn(),
getInput: jest.fn(), getInput: jest.fn(),
setOutput: jest.fn(),
isDebug: jest.fn(), isDebug: jest.fn(),
info: jest.fn() info: jest.fn()
})) }))

View File

@ -24,6 +24,7 @@ jest.mock('@actions/io', () => ({
jest.mock('@actions/core', () => ({ jest.mock('@actions/core', () => ({
setFailed: jest.fn(), setFailed: jest.fn(),
getInput: jest.fn(), getInput: jest.fn(),
setOutput: jest.fn(),
exportVariable: jest.fn(), exportVariable: jest.fn(),
isDebug: jest.fn(), isDebug: jest.fn(),
info: jest.fn() info: jest.fn()

View File

@ -8,11 +8,11 @@ branding:
icon: 'git-commit' icon: 'git-commit'
color: 'orange' color: 'orange'
inputs: 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.' 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 required: false
TOKEN: token:
description: > description: >
This option defaults to the repository scoped GitHub Token. 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. 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 required: false
default: ${{ github.token }} default: ${{ github.token }}
BRANCH: branch:
description: 'This is the branch you wish to deploy to, for example gh-pages or docs.' description: 'This is the branch you wish to deploy to, for example gh-pages or docs.'
required: true 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.' 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 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.' 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 required: false
COMMIT_MESSAGE: commit-message:
description: 'If you need to customize the commit message for an integration you can do so.' description: 'If you need to customize the commit message for an integration you can do so.'
required: false required: false
CLEAN: 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.' 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 required: false
default: 'true' default: true
clean-exclude: 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 required: false
DRY_RUN: dry-run:
description: "Do not actually push back, but use `--dry-run` on `git push` invocations insead." description: "Do not actually push back, but use `--dry-run` on `git push` invocations insead."
required: false 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." 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 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." 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 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" 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 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." 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 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." 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
SILENT: silent:
description: "Silences the action output preventing it from displaying git messages." description: "Silences the action output preventing it from displaying git messages."
required: false required: false
outputs: 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' description: 'The status of the deployment that indicates if the run failed or passed. Possible outputs include: success|failed|skipped'

View File

@ -76,9 +76,9 @@ export interface NodeActionInterface {
export const action: ActionInterface = { export const action: ActionInterface = {
folder: getInput('folder'), folder: getInput('folder'),
branch: getInput('branch'), branch: getInput('branch'),
commitMessage: getInput('commit_message'), commitMessage: getInput('commit-message'),
dryRun: !isNullOrUndefined(getInput('dry_run')) dryRun: !isNullOrUndefined(getInput('dry-run'))
? getInput('dry_run').toLowerCase() === 'true' ? getInput('dry-run').toLowerCase() === 'true'
: false, : false,
clean: !isNullOrUndefined(getInput('clean')) clean: !isNullOrUndefined(getInput('clean'))
? getInput('clean').toLowerCase() === 'true' ? getInput('clean').toLowerCase() === 'true'
@ -87,28 +87,28 @@ export const action: ActionInterface = {
.split('\n') .split('\n')
.filter(l => l !== ''), .filter(l => l !== ''),
isTest: TestFlag.NONE, isTest: TestFlag.NONE,
email: !isNullOrUndefined(getInput('git_config_email')) email: !isNullOrUndefined(getInput('git-config-email'))
? getInput('git_config_email') ? getInput('git-config-email')
: pusher && pusher.email : pusher && pusher.email
? pusher.email ? pusher.email
: `${ : `${
process.env.GITHUB_ACTOR || 'github-pages-deploy-action' process.env.GITHUB_ACTOR || 'github-pages-deploy-action'
}@users.noreply.github.com`, }@users.noreply.github.com`,
name: !isNullOrUndefined(getInput('git_config_name')) name: !isNullOrUndefined(getInput('git-config-name'))
? getInput('git_config_name') ? getInput('git-config-name')
: pusher && pusher.name : pusher && pusher.name
? pusher.name ? pusher.name
: process.env.GITHUB_ACTOR : process.env.GITHUB_ACTOR
? process.env.GITHUB_ACTOR ? process.env.GITHUB_ACTOR
: 'GitHub Pages Deploy Action', : 'GitHub Pages Deploy Action',
repositoryName: !isNullOrUndefined(getInput('repository_name')) repositoryName: !isNullOrUndefined(getInput('repository-name'))
? getInput('repository_name') ? getInput('repository-name')
: repository && repository.full_name : repository && repository.full_name
? repository.full_name ? repository.full_name
: process.env.GITHUB_REPOSITORY, : process.env.GITHUB_REPOSITORY,
token: getInput('token'), token: getInput('token'),
singleCommit: !isNullOrUndefined(getInput('single_commit')) singleCommit: !isNullOrUndefined(getInput('single-commit'))
? getInput('single_commit').toLowerCase() === 'true' ? getInput('single-commit').toLowerCase() === 'true'
: false, : false,
silent: !isNullOrUndefined(getInput('silent')) silent: !isNullOrUndefined(getInput('silent'))
? getInput('silent').toLowerCase() === 'true' ? getInput('silent').toLowerCase() === 'true'
@ -116,7 +116,7 @@ export const action: ActionInterface = {
ssh: !isNullOrUndefined(getInput('ssh')) ssh: !isNullOrUndefined(getInput('ssh'))
? getInput('ssh').toLowerCase() === 'true' ? getInput('ssh').toLowerCase() === 'true'
: false, : false,
targetFolder: getInput('target_folder'), targetFolder: getInput('target-folder'),
workspace: process.env.GITHUB_WORKSPACE || '' workspace: process.env.GITHUB_WORKSPACE || ''
} }

View File

@ -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 {ActionInterface, Status, NodeActionInterface} from './constants'
import {deploy, init} from './git' import {deploy, init} from './git'
import { import {
@ -60,5 +60,6 @@ export default async function run(
) )
exportVariable('deployment_status', status) exportVariable('deployment_status', status)
setOutput('deployment-status', status)
} }
} }