Skip to content

Commit

Permalink
update inputs and docs (#36)
Browse files Browse the repository at this point in the history
* update inputs and docs

adds new inputs and uses kebab-case for consistency with chrnorm/deployment-action@v2

* update dist

* CI: update args in test workflow
  • Loading branch information
chrnorm authored May 21, 2022
1 parent c1f3112 commit 07b3930
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ jobs:
uses: ./
with:
token: '${{ github.token }}'
target_url: http://my-app-url.com
environment-url: http://my-app-url.com
state: 'success'
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ Works great with my other action to create Deployments, [chrnorm/deployment-acti

## Action inputs

| name | description |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `state` | The state to set the deployment to. Must be one of the below: "error" "failure" "inactive" "in_progress" "queued" "pending" "success" |
| `token` | GitHub token |
| `log_url` | (Optional) Sets the URL for deployment output |
| `description` | (Optional) Descriptive message about the deployment |
| `environment_url` | (Optional) Sets the URL for accessing your environment |
| `deployment_id` | The ID of the deployment to update |
| name | description |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `repo` | (Optional) A custom repository to create the deployment for. Defaults to the repo the action is running in. |
| `owner` | A custom owner to create the deployment for. Defaults to the repo owner the action is running in. |
| `state` | The state to set the deployment to. Must be one of the below: "error" "failure" "inactive" "in_progress" "queued" "pending" "success" |
| `token` | GitHub token |
| `log-url` | (Optional) Sets the URL for deployment output |
| `environment-url` | (Optional) Sets the URL for accessing your environment |
| `environment` | (Optional) Name for the target deployment environment, which can be changed when setting a deploy status. Must be one of production, staging, qa, or can be undefined. |
| `description` | (Optional) Descriptive message about the deployment |
| `deployment-id` | The ID of the deployment to update |
| `github-base-url` | (Optional) Changes the API base URL for a GitHub Enterprise server. |

## Usage example

Expand All @@ -33,12 +37,12 @@ jobs:
steps:
- uses: actions/checkout@v1

- uses: chrnorm/deployment-action@releases/v1
- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
environment_url: http://my-app-url.com
token: '${{ github.token }}'
environment-url: http://my-app-url.com
environment: production

- name: Deploy my app
Expand All @@ -47,21 +51,21 @@ jobs:
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@releases/v1
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
environment_url: http://my-app-url.com
state: "success"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
token: '${{ github.token }}'
environment-url: http://my-app-url.com
state: 'success'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}

- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@releases/v1
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
environment_url: http://my-app-url.com
state: "failure"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
token: '${{ github.token }}'
environment-url: http://my-app-url.com
state: 'failure'
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
```
## Development
Expand All @@ -74,4 +78,4 @@ First build Typescript with `npm run build`. Then package to a single JS file wi

## Testing

There is a validation workflow in `.github/workflows/validate.yml` which performs a basic smoke test against the action to check that it runs.
There is a validation workflow in `.github/workflows/test.yml` which performs a basic smoke test against the action to check that it runs.
46 changes: 30 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
name: "Deployment Status"
description: "Creates a GitHub Deployment status update"
author: "chrnorm"
name: 'Deployment Status'
description: 'Creates a GitHub Deployment status update'
author: 'chrnorm'
branding:
icon: arrow-up
color: gray-dark
inputs:
repo:
description: 'A custom repository to create the deployment for. Defaults to the repo the action is running in.'
required: false
owner:
description: 'A custom owner to create the deployment for. Defaults to the repo owner the action is running in.'
required: false
state:
description: "State for the deployment"
description: 'State for the deployment'
required: true
token:
description: "Github repository token"
description: 'Github repository token'
required: true
log_url:
description: "Sets the URL for deployment output"
log-url:
description: 'Sets the URL for deployment output'
required: false
target_url:
description: "Same as log_url"
environment-url:
description: 'Sets the URL for accessing your environment'
required: false
environment_url:
description: "Sets the URL for accessing your environment"
default: ''
environment:
description: 'Name for the target deployment environment, which can be changed when setting a deploy status. Must be one of production, staging, qa, or can be undefined.'
required: false
description:
description: "Descriptive message about the deployment"
description: 'Descriptive message about the deployment'
required: false
deployment_id:
description: "The ID of the deployment"
deployment-id:
description: 'The ID of the deployment'
required: true
auto-inactive:
description: "Adds a new inactive status to all prior non-transient, non-production environment deployments with the same repository and environment name as the created status's deployment. An inactive status is only added to deployments that had a success state."
required: false
default: 'true'
github-base-url:
description: 'Changes the API base URL for a GitHub Enterprise server.'
required: false
runs:
using: "node12"
main: "dist/index.js"
using: 'node12'
main: 'dist/index.js'
26 changes: 22 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,30 @@ function run() {
const token = core.getInput('token', { required: true });
const baseUrl = core.getInput('github-base-url', { required: false }) || undefined;
const octokit = github.getOctokit(token, { baseUrl });
const logUrl = core.getInput('log_url', { required: false }) || defaultUrl;
const owner = core.getInput('owner', { required: false }) || context.repo.owner;
const repo = core.getInput('repo', { required: false }) || context.repo.repo;
const logUrl = core.getInput('log-url', { required: false }) || defaultUrl;
const description = core.getInput('description', { required: false }) || '';
const deploymentId = core.getInput('deployment_id');
const environmentUrl = core.getInput('environment_url', { required: false }) || '';
const deploymentId = core.getInput('deployment-id');
const environmentUrl = core.getInput('environment-url', { required: false }) || '';
const environment = core.getInput('environment', { required: false }) ||
undefined;
const autoInactiveStringInput = core.getInput('auto-inactive', { required: false }) || undefined;
const autoInactive = autoInactiveStringInput
? autoInactiveStringInput === 'true'
: undefined;
const state = core.getInput('state');
yield octokit.rest.repos.createDeploymentStatus(Object.assign(Object.assign({}, context.repo), { deployment_id: parseInt(deploymentId), state, log_url: logUrl, description, environment_url: environmentUrl }));
yield octokit.rest.repos.createDeploymentStatus({
owner,
repo,
environment,
auto_inactive: autoInactive,
deployment_id: parseInt(deploymentId),
state,
log_url: logUrl,
description,
environment_url: environmentUrl
});
}
catch (error) {
core.error(error);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

26 changes: 22 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,30 @@ function run() {
const token = core.getInput('token', { required: true });
const baseUrl = core.getInput('github-base-url', { required: false }) || undefined;
const octokit = github.getOctokit(token, { baseUrl });
const logUrl = core.getInput('log_url', { required: false }) || defaultUrl;
const owner = core.getInput('owner', { required: false }) || context.repo.owner;
const repo = core.getInput('repo', { required: false }) || context.repo.repo;
const logUrl = core.getInput('log-url', { required: false }) || defaultUrl;
const description = core.getInput('description', { required: false }) || '';
const deploymentId = core.getInput('deployment_id');
const environmentUrl = core.getInput('environment_url', { required: false }) || '';
const deploymentId = core.getInput('deployment-id');
const environmentUrl = core.getInput('environment-url', { required: false }) || '';
const environment = core.getInput('environment', { required: false }) ||
undefined;
const autoInactiveStringInput = core.getInput('auto-inactive', { required: false }) || undefined;
const autoInactive = autoInactiveStringInput
? autoInactiveStringInput === 'true'
: undefined;
const state = core.getInput('state');
yield octokit.rest.repos.createDeploymentStatus(Object.assign(Object.assign({}, context.repo), { deployment_id: parseInt(deploymentId), state, log_url: logUrl, description, environment_url: environmentUrl }));
yield octokit.rest.repos.createDeploymentStatus({
owner,
repo,
environment,
auto_inactive: autoInactive,
deployment_id: parseInt(deploymentId),
state,
log_url: logUrl,
description,
environment_url: environmentUrl
});
}
catch (error) {
core.error(error);
Expand Down
28 changes: 24 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type DeploymentState =
| 'pending'
| 'success'

type Environment = 'production' | 'staging' | 'qa' | undefined

async function run(): Promise<void> {
try {
const context = github.context
Expand All @@ -22,16 +24,34 @@ async function run(): Promise<void> {

const octokit = github.getOctokit(token, {baseUrl})

const logUrl = core.getInput('log_url', {required: false}) || defaultUrl
const owner =
core.getInput('owner', {required: false}) || context.repo.owner
const repo = core.getInput('repo', {required: false}) || context.repo.repo

const logUrl = core.getInput('log-url', {required: false}) || defaultUrl
const description = core.getInput('description', {required: false}) || ''
const deploymentId = core.getInput('deployment_id')
const deploymentId = core.getInput('deployment-id')
const environmentUrl =
core.getInput('environment_url', {required: false}) || ''
core.getInput('environment-url', {required: false}) || ''

const environment =
(core.getInput('environment', {required: false}) as Environment) ||
undefined

const autoInactiveStringInput =
core.getInput('auto-inactive', {required: false}) || undefined

const autoInactive = autoInactiveStringInput
? autoInactiveStringInput === 'true'
: undefined

const state = core.getInput('state') as DeploymentState

await octokit.rest.repos.createDeploymentStatus({
...context.repo,
owner,
repo,
environment,
auto_inactive: autoInactive, // GitHub API defaults to true if undefined.
deployment_id: parseInt(deploymentId),
state,
log_url: logUrl,
Expand Down

0 comments on commit 07b3930

Please sign in to comment.