Skip to content

Commit 8a87bc3

Browse files
authored
feat: add task input (#141)
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
1 parent b00ab86 commit 8a87bc3

File tree

9 files changed

+32
-13
lines changed

9 files changed

+32
-13
lines changed

.github/workflows/pipeline.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ jobs:
8484
desc: 'Deployment starting!'
8585
debug: true
8686

87+
- name: parse repo name and owner
88+
id: parse_repo
89+
shell: bash
90+
# outputs: owner, name
91+
run: |
92+
echo "owner=$(cut -d "/" -f 1 <<<"${{ github.repository }}")" >> $GITHUB_OUTPUT
93+
echo "name=$(cut -d "/" -f 2 <<<"${{ github.repository }}")" >> $GITHUB_OUTPUT
94+
95+
8796
- name: assert deployment in progress
8897
uses: actions/github-script@v6
8998
env:
@@ -99,8 +108,8 @@ jobs:
99108
throw new Error("status_id not set");
100109
}
101110
const res = await github.rest.repos.getDeploymentStatus({
102-
owner: "bobheadxi",
103-
repo: "deployments",
111+
owner: "${{ steps.parse_repo.outputs.owner }}",
112+
repo: "${{ steps.parse_repo.outputs.name }}",
104113
deployment_id: parseInt(deployment_id, 10),
105114
status_id: parseInt(status_id, 10),
106115
});
@@ -137,8 +146,8 @@ jobs:
137146
throw new Error("status_id not set");
138147
}
139148
const res = await github.rest.repos.getDeploymentStatus({
140-
owner: "bobheadxi",
141-
repo: "deployments",
149+
owner: "${{ steps.parse_repo.outputs.owner }}",
150+
repo: "${{ steps.parse_repo.outputs.name }}",
142151
deployment_id: parseInt(deployment_id, 10),
143152
status_id: parseInt(status_id, 10),
144153
});

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ This is best used on the `push: { branches: [ ... ] }` event, but you can also h
8282

8383
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:
8484

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

9193
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:
9294

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ inputs:
3131
ref:
3232
required: false
3333
description: The git ref to use for the deploy, defaults to `github.ref`
34+
task:
35+
required: false
36+
description: The task to assign to the deployment, defaults to 'deploy'
3437

3538
debug:
3639
required: false

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"prettier": "prettier src --write",
99
"prettier:check": "prettier src --check",
1010
"build": "ncc build src/main.ts --out dist --minify --source-map --license LICENSES",
11-
"build:check": "npm run build && git diff --quiet dist"
11+
"build:check": "npm run build && git diff --quiet dist",
12+
"test": "npm run prettier:check & npm run build:check"
1213
},
1314
"repository": {
1415
"type": "git",

src/lib/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface DeploymentContext {
88
owner: string;
99
repo: string;
1010
log: Logger;
11+
task: string | undefined;
1112

1213
coreArgs: {
1314
description?: string;
@@ -36,6 +37,7 @@ export function collectDeploymentContext(): DeploymentContext {
3637
sha,
3738
owner,
3839
repo,
40+
task: getOptionalInput("task"),
3941
log: new Logger({ debug: getBooleanInput("debug", false) }),
4042
coreArgs: {
4143
environment: getRequiredInput("env"),

src/lib/input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ export function getRequiredInput(key: string): string {
1717
}
1818

1919
export function getOptionalInput(key: string): string | undefined {
20-
return getInput(key, { required: false, trimWhitespace: true });
20+
return getInput(key, { required: false, trimWhitespace: true }) || undefined;
2121
}

src/steps/start.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ async function createStart(
2323
owner,
2424
repo,
2525
ref,
26+
task,
2627
coreArgs: { environment, description, logsURL },
2728
} = context;
2829

@@ -33,6 +34,7 @@ async function createStart(
3334
owner: owner,
3435
repo: repo,
3536
ref: ref,
37+
task: task,
3638
required_contexts: [],
3739
environment: environment,
3840
description: description,

0 commit comments

Comments
 (0)