Skip to content

Commit

Permalink
feat: get github.token as default input (#61)
Browse files Browse the repository at this point in the history
* feat: get github.token as default input

* mark token as optional

Signed-off-by: Rui Chen <rui@chenrui.dev>

* update test

Signed-off-by: Rui Chen <rui@chenrui.dev>

* fmt code

Signed-off-by: Rui Chen <rui@chenrui.dev>

---------

Signed-off-by: Rui Chen <rui@chenrui.dev>
Co-authored-by: Rui Chen <rui@chenrui.dev>
  • Loading branch information
qoomon and chenrui333 committed Jul 17, 2024
1 parent 35d47b4 commit c8ceeb5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ jobs:
uses: actions/checkout@v2
+ - name: Turnstyle
+ uses: softprops/turnstyle@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: sleep 30
```
Expand All @@ -65,8 +63,6 @@ jobs:
uses: actions/checkout@v2
- name: Turnstyle
uses: softprops/turnstyle@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: sleep 30
```
Expand All @@ -88,8 +84,6 @@ jobs:
uses: softprops/turnstyle@v1
with:
+ continue-after-seconds: 180
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: sleep 30
```
Expand All @@ -112,8 +106,6 @@ jobs:
uses: softprops/turnstyle@v1
with:
+ abort-after-seconds: 180
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: sleep 30
```
Expand All @@ -139,8 +131,6 @@ jobs:
uses: softprops/turnstyle@v1
with:
+ continue-after-seconds: 180
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
+ if: ! steps.turnstyle.outputs.force_continued
run: sleep 30
Expand All @@ -162,13 +152,6 @@ jobs:
|-------------------------|----------|-------------------------------------------------------------------------------------------------|
| `force_continued` | boolean | True if continue-after-seconds is used and the step using turnstyle continued. False otherwise. |

#### environment variables

The following are *required* as `step.env` keys

| Name | Description |
|----------------|--------------------------------------|
| `GITHUB_TOKEN` | GITHUB_TOKEN as provided by `secrets`|

## required permissions

Expand Down
10 changes: 5 additions & 5 deletions __tests__/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ describe("input", () => {
it("parses config from env with custom inputs", () => {
assert.deepEqual(
parseInput({
GITHUB_TOKEN: "s3cr3t",
GITHUB_REF: "refs/heads/foo",
GITHUB_REPOSITORY: "softprops/turnstyle",
GITHUB_WORKFLOW: "test",
GITHUB_RUN_ID: "1",
INPUT_TOKEN: "s3cr3t",
"INPUT_CONTINUE-AFTER-SECONDS": "10",
"INPUT_POLL-INTERVAL-SECONDS": "5",
"INPUT_SAME-BRANCH-ONLY": "false",
Expand All @@ -35,11 +35,11 @@ describe("input", () => {
it("parses config from env with abortAfterSeconds", () => {
assert.deepEqual(
parseInput({
GITHUB_TOKEN: "s3cr3t",
GITHUB_REF: "refs/heads/foo",
GITHUB_REPOSITORY: "softprops/turnstyle",
GITHUB_WORKFLOW: "test",
GITHUB_RUN_ID: "1",
INPUT_TOKEN: "s3cr3t",
"INPUT_ABORT-AFTER-SECONDS": "10",
"INPUT_POLL-INTERVAL-SECONDS": "5",
"INPUT_SAME-BRANCH-ONLY": "false",
Expand All @@ -64,11 +64,11 @@ describe("input", () => {
it("rejects env with continueAfterSeconds and abortAfterSeconds", () => {
assert.throws(() =>
parseInput({
GITHUB_TOKEN: "s3cr3t",
GITHUB_REF: "refs/heads/foo",
GITHUB_REPOSITORY: "softprops/turnstyle",
GITHUB_WORKFLOW: "test",
GITHUB_RUN_ID: "1",
INPUT_TOKEN: "s3cr3t",
"INPUT_CONTINUE-AFTER-SECONDS": "10",
"INPUT_ABORT-AFTER-SECONDS": "2",
}),
Expand All @@ -78,11 +78,11 @@ describe("input", () => {
it("parses config from env with defaults", () => {
assert.deepEqual(
parseInput({
GITHUB_TOKEN: "s3cr3t",
GITHUB_REF: "refs/heads/foo",
GITHUB_REPOSITORY: "softprops/turnstyle",
GITHUB_WORKFLOW: "test",
GITHUB_RUN_ID: "1",
INPUT_TOKEN: "s3cr3t",
"INPUT_CONTINUE-AFTER-SECONDS": "",
"INPUT_POLL-INTERVAL-SECONDS": "",
"INPUT_SAME-BRANCH-ONLY": "",
Expand All @@ -107,12 +107,12 @@ describe("input", () => {
it("favours GITHUB_HEAD_REF when present (pull requests)", () => {
assert.deepEqual(
parseInput({
GITHUB_TOKEN: "s3cr3t",
GITHUB_HEAD_REF: "pr-branch-name",
GITHUB_REF: "refs/heads/foo",
GITHUB_REPOSITORY: "softprops/turnstyle",
GITHUB_WORKFLOW: "test",
GITHUB_RUN_ID: "1",
INPUT_TOKEN: "s3cr3t",
}),
{
githubToken: "s3cr3t",
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ runs:
using: 'node20'
main: 'dist/index.js'
inputs:
token:
description: 'GitHub access token'
required: false
default: ${{ github.token }}
poll-interval-seconds:
description: "Number of seconds to wait in between checks for previous run completion (defaults to 60)"
continue-after-seconds:
Expand Down
2 changes: 1 addition & 1 deletion src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Input {
}

export const parseInput = (env: Record<string, string | undefined>): Input => {
const githubToken = env.GITHUB_TOKEN || "";
const githubToken = env["INPUT_TOKEN"] || "";
const [owner, repo] = (env.GITHUB_REPOSITORY || "").split("/");
const workflowName = env.GITHUB_WORKFLOW || "";
const branch =
Expand Down

0 comments on commit c8ceeb5

Please sign in to comment.