Skip to content

Commit

Permalink
feat: add task input (#141)
Browse files Browse the repository at this point in the history
Hi 👋🏻 
This PR adds a `task` input, that lets you change the task assigned to the deployment.

Other housekeeping changes:
- `test` script added to `package.json`
- `getOptionalInput` now can actually return `undefined` (empty strings can cause API errors)
- the CI workflow can now be used on other repos

Closes #140
  • Loading branch information
EndBug authored May 23, 2023
1 parent b00ab86 commit 8a87bc3
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ jobs:
desc: 'Deployment starting!'
debug: true

- name: parse repo name and owner
id: parse_repo
shell: bash
# outputs: owner, name
run: |
echo "owner=$(cut -d "/" -f 1 <<<"${{ github.repository }}")" >> $GITHUB_OUTPUT
echo "name=$(cut -d "/" -f 2 <<<"${{ github.repository }}")" >> $GITHUB_OUTPUT
- name: assert deployment in progress
uses: actions/github-script@v6
env:
Expand All @@ -99,8 +108,8 @@ jobs:
throw new Error("status_id not set");
}
const res = await github.rest.repos.getDeploymentStatus({
owner: "bobheadxi",
repo: "deployments",
owner: "${{ steps.parse_repo.outputs.owner }}",
repo: "${{ steps.parse_repo.outputs.name }}",
deployment_id: parseInt(deployment_id, 10),
status_id: parseInt(status_id, 10),
});
Expand Down Expand Up @@ -137,8 +146,8 @@ jobs:
throw new Error("status_id not set");
}
const res = await github.rest.repos.getDeploymentStatus({
owner: "bobheadxi",
repo: "deployments",
owner: "${{ steps.parse_repo.outputs.owner }}",
repo: "${{ steps.parse_repo.outputs.name }}",
deployment_id: parseInt(deployment_id, 10),
status_id: parseInt(status_id, 10),
});
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ This is best used on the `push: { branches: [ ... ] }` event, but you can also h

In addition to the [core configuration](#configuration), the following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) are available:

| Variable | Default | Purpose |
| --------------- | ------- | --------------------------------------------------------------------------------------------------- |
| `deployment_id` | | Use an existing deployment instead of creating a new one (e.g. `${{ github.event.deployment.id }}`) |
| `override` | `false` | whether to mark existing deployments of this environment as inactive |
| `payload` | | JSON-formatted dictionary with extra information about the deployment |
| Variable | Default | Purpose |
| --------------- | ------- | --------------------------------------------------------------------------------------------------- |
| `deployment_id` | | Use an existing deployment instead of creating a new one (e.g. `${{ github.event.deployment.id }}`) |
| `override` | `false` | whether to mark existing deployments of this environment as inactive |
| `payload` | | JSON-formatted dictionary with extra information about the deployment |
| `task` | `'deploy'` | change the task associated with this deployment, can be any string


The following [`outputs`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#steps-context) are available:

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ inputs:
ref:
required: false
description: The git ref to use for the deploy, defaults to `github.ref`
task:
required: false
description: The task to assign to the deployment, defaults to 'deploy'

debug:
required: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"prettier": "prettier src --write",
"prettier:check": "prettier src --check",
"build": "ncc build src/main.ts --out dist --minify --source-map --license LICENSES",
"build:check": "npm run build && git diff --quiet dist"
"build:check": "npm run build && git diff --quiet dist",
"test": "npm run prettier:check & npm run build:check"
},
"repository": {
"type": "git",
Expand Down
2 changes: 2 additions & 0 deletions src/lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface DeploymentContext {
owner: string;
repo: string;
log: Logger;
task: string | undefined;

coreArgs: {
description?: string;
Expand Down Expand Up @@ -36,6 +37,7 @@ export function collectDeploymentContext(): DeploymentContext {
sha,
owner,
repo,
task: getOptionalInput("task"),
log: new Logger({ debug: getBooleanInput("debug", false) }),
coreArgs: {
environment: getRequiredInput("env"),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export function getRequiredInput(key: string): string {
}

export function getOptionalInput(key: string): string | undefined {
return getInput(key, { required: false, trimWhitespace: true });
return getInput(key, { required: false, trimWhitespace: true }) || undefined;
}
2 changes: 2 additions & 0 deletions src/steps/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function createStart(
owner,
repo,
ref,
task,
coreArgs: { environment, description, logsURL },
} = context;

Expand All @@ -33,6 +34,7 @@ async function createStart(
owner: owner,
repo: repo,
ref: ref,
task: task,
required_contexts: [],
environment: environment,
description: description,
Expand Down

0 comments on commit 8a87bc3

Please sign in to comment.