Skip to content

Commit 4716f94

Browse files
chore: onboarding dispatch-workflow action
1 parent 31464cf commit 4716f94

37 files changed

+43457
-1
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
lib/
3+
node_modules/
4+
jest.config.js

.eslintrc.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"plugins": ["jest", "@typescript-eslint"],
3+
"extends": ["plugin:github/recommended"],
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {
6+
"ecmaVersion": 9,
7+
"sourceType": "module",
8+
"project": "./tsconfig.json"
9+
},
10+
"rules": {
11+
"i18n-text/no-en": "off",
12+
"eslint-comments/no-use": "off",
13+
"import/no-namespace": "off",
14+
"no-unused-vars": "off",
15+
"@typescript-eslint/no-unused-vars": [
16+
"error",
17+
{
18+
"argsIgnorePattern": "^_",
19+
"varsIgnorePattern": "^_",
20+
"caughtErrorsIgnorePattern": "^_"
21+
}
22+
],
23+
"@typescript-eslint/explicit-member-accessibility": [
24+
"error",
25+
{"accessibility": "no-public"}
26+
],
27+
"@typescript-eslint/no-require-imports": "error",
28+
"@typescript-eslint/array-type": "error",
29+
"@typescript-eslint/await-thenable": "error",
30+
"@typescript-eslint/ban-ts-comment": "error",
31+
"camelcase": "off",
32+
"@typescript-eslint/consistent-type-assertions": "error",
33+
"@typescript-eslint/explicit-function-return-type": [
34+
"error",
35+
{"allowExpressions": true}
36+
],
37+
"@typescript-eslint/func-call-spacing": ["error", "never"],
38+
"@typescript-eslint/no-array-constructor": "error",
39+
"@typescript-eslint/no-empty-interface": "error",
40+
"@typescript-eslint/no-explicit-any": "error",
41+
"@typescript-eslint/no-extraneous-class": "error",
42+
"@typescript-eslint/no-for-in-array": "error",
43+
"@typescript-eslint/no-inferrable-types": "error",
44+
"@typescript-eslint/no-misused-new": "error",
45+
"@typescript-eslint/no-namespace": "error",
46+
"@typescript-eslint/no-non-null-assertion": "warn",
47+
"@typescript-eslint/no-unnecessary-qualifier": "error",
48+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
49+
"@typescript-eslint/no-useless-constructor": "error",
50+
"@typescript-eslint/no-var-requires": "error",
51+
"@typescript-eslint/prefer-for-of": "warn",
52+
"@typescript-eslint/prefer-function-type": "warn",
53+
"@typescript-eslint/prefer-includes": "error",
54+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
55+
"@typescript-eslint/promise-function-async": "error",
56+
"@typescript-eslint/require-array-sort-compare": "error",
57+
"@typescript-eslint/restrict-plus-operands": "error",
58+
"semi": "off",
59+
"@typescript-eslint/semi": ["error", "never"],
60+
"@typescript-eslint/type-annotation-spacing": "error",
61+
"@typescript-eslint/unbound-method": "error",
62+
"@typescript-eslint/quotes": [
63+
"error",
64+
"single",
65+
{
66+
"avoidEscape": true,
67+
"allowTemplateLiterals": true
68+
}
69+
],
70+
"no-shadow": "off",
71+
"@typescript-eslint/no-shadow": ["off"]
72+
},
73+
"env": {
74+
"node": true,
75+
"es6": true,
76+
"jest/globals": true
77+
},
78+
"overrides": [
79+
{
80+
"files": ["**/*.test.ts"],
81+
"rules": {
82+
"@typescript-eslint/no-explicit-any": "off"
83+
}
84+
}
85+
]
86+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/** -diff linguist-generated=true

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
8+
- package-ecosystem: npm
9+
directory: /
10+
schedule:
11+
interval: daily
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release GitHub Actions
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: "Tag for the release"
8+
required: true
9+
# Uncomment if using yarn
10+
# script:
11+
# description: "Specify the build script to run"
12+
# required: true
13+
# type: string
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
release:
20+
permissions:
21+
actions: read
22+
id-token: write
23+
contents: write
24+
25+
uses: step-security/reusable-workflows/.github/workflows/actions_release.yaml@v1
26+
with:
27+
tag: "${{ github.event.inputs.tag }}"
28+
# script: "${{ github.event.inputs.script }}"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: NPM Audit Fix Run
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
force:
7+
description: "Use --force flag for npm audit fix?"
8+
required: true
9+
type: boolean
10+
base_branch:
11+
description: "Specify a base branch"
12+
required: false
13+
default: "main"
14+
schedule:
15+
- cron: "0 0 * * 1"
16+
17+
jobs:
18+
audit-fix:
19+
uses: step-security/reusable-workflows/.github/workflows/audit_fix.yml@v1
20+
with:
21+
force: ${{ inputs.force || false }}
22+
base_branch: ${{ inputs.base_branch || 'main' }}
23+
24+
permissions:
25+
contents: write
26+
pull-requests: write
27+
packages: read
28+
issues: write
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Auto Cherry-Pick from Upstream
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
base_branch:
7+
description: "Base branch to create the PR against"
8+
required: true
9+
default: "main"
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
packages: read
15+
issues: write
16+
17+
jobs:
18+
cherry-pick:
19+
uses: step-security/reusable-workflows/.github/workflows/auto_cherry_pick.yaml@v1
20+
with:
21+
original-owner: "lasith-kg"
22+
repo-name: "dispatch-workflow"
23+
base_branch: ${{ inputs.base_branch }}

.github/workflows/build-test.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: 'Build and Test'
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "main"
8+
9+
jobs:
10+
integration-tests:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
actions: write
15+
env:
16+
INTEGRATION_TEST_WORKFLOW_FILE: "integration-tests.yml"
17+
INTEGRATION_TEST_WORKFLOW_ID: 64701969 # This ID Will Change On Fork
18+
steps:
19+
- uses: actions/checkout@v4
20+
- id: nvmrc
21+
name: Extract Node.JS Version
22+
shell: bash
23+
run: |
24+
echo "node-version=$(cat .nvmrc)" >> "${GITHUB_OUTPUT}"
25+
- name: Set Node.JS
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: "${{ steps.nvmrc.outputs.node-version }}"
29+
- id: clean-dist
30+
shell: bash
31+
run: |
32+
# Clean the existing dist/ folder so that we only test fresh
33+
# compiled code
34+
rm -rf dist/
35+
- run: |
36+
npm ci
37+
- run: |
38+
npm run all
39+
- uses: ./
40+
id: fail-ref-workflow-dispatch
41+
name: "Dispatch Workflow using workflow_dispatch Method, to a Non-existent Branch"
42+
continue-on-error: true
43+
with:
44+
dispatch-method: "workflow_dispatch"
45+
repo: "${{ github.event.repository.name }}"
46+
owner: "${{ github.repository_owner }}"
47+
ref: "non-existent-branch/${{ github.run_id }}" # This branch cannot realistically exist
48+
workflow: "${{ env.INTEGRATION_TEST_WORKFLOW_FILE }}"
49+
token: "${{ secrets.GITHUB_TOKEN }}"
50+
workflow-inputs: '{"placeholder": "placeholder"}'
51+
- uses: ./
52+
id: fail-file-workflow-dispatch
53+
name: "Dispatch Workflow using workflow_dispatch Method, to a Non-existent Workflow File"
54+
continue-on-error: true
55+
with:
56+
dispatch-method: "workflow_dispatch"
57+
repo: "${{ github.event.repository.name }}"
58+
owner: "${{ github.repository_owner }}"
59+
ref: "main"
60+
workflow: "${{ github.run_id }}.yml" # This workflow file cannot realistically exist
61+
token: "${{ secrets.GITHUB_TOKEN }}"
62+
workflow-inputs: '{"placeholder": "placeholder"}'
63+
- uses: ./
64+
id: fail-inputs-workflow-dispatch
65+
name: "Dispatch Workflow using workflow_dispatch Method, with an unsupported workflow inputs"
66+
continue-on-error: true
67+
with:
68+
dispatch-method: "workflow_dispatch"
69+
repo: "${{ github.event.repository.name }}"
70+
owner: "${{ github.repository_owner }}"
71+
ref: "main"
72+
workflow: "${{ env.INTEGRATION_TEST_WORKFLOW_FILE }}"
73+
token: "${{ secrets.GITHUB_TOKEN }}"
74+
workflow-inputs: '{"placeholder": 0}' # 0 is not a string type
75+
- id: verify-fail-workflow-dispatch
76+
name: "Verify Action Outputs for worflow-dispatch"
77+
shell: bash
78+
run: |
79+
set -euo pipefail
80+
81+
if [[ "${{ steps.fail-ref-workflow-dispatch.outcome }}" != "failure" ]]; then
82+
>&2 echo "🔴 fail-ref-workflow-dispatch step was expected to fail"; exit 1
83+
fi
84+
85+
if [[ "${{ steps.fail-file-workflow-dispatch.outcome }}" != "failure" ]]; then
86+
>&2 echo "🔴 fail-file-workflow-dispatch step was expected to fail"; exit 1
87+
fi
88+
89+
if [[ "${{ steps.fail-inputs-workflow-dispatch.outcome }}" != "failure" ]]; then
90+
>&2 echo "🔴 fail-inputs-workflow-dispatch step was expected to fail"; exit 1
91+
fi
92+
- uses: ./
93+
id: workflow-dispatch
94+
name: "Dispatch Using workflow_dispatch Method"
95+
with:
96+
dispatch-method: "workflow_dispatch"
97+
repo: "${{ github.event.repository.name }}"
98+
owner: "${{ github.repository_owner }}"
99+
ref: "refs/heads/main"
100+
workflow: "${{ env.INTEGRATION_TEST_WORKFLOW_FILE }}"
101+
token: "${{ secrets.GITHUB_TOKEN }}"
102+
workflow-inputs: |
103+
{
104+
"string-type": "placeholder",
105+
"number-type": "1",
106+
"boolean-type": "true"
107+
}
108+
- uses: ./
109+
id: repository-dispatch-custom-backoff
110+
name: "Dispatch Using repositroy_dispatch Method and custom exponential backoff parameters"
111+
with:
112+
dispatch-method: "repository_dispatch"
113+
event-type: "repository-dispatch"
114+
repo: "${{ github.event.repository.name }}"
115+
owner: "${{ github.repository_owner }}"
116+
token: "${{ secrets.GITHUB_TOKEN }}"
117+
workflow-inputs: |
118+
{
119+
"string-type": "placeholder",
120+
"nested": {
121+
"number-type": 1,
122+
"boolean-type": true
123+
}
124+
}
125+
starting-delay-ms: 150
126+
max-attempts: 3
127+
time-multiple: 1.5
128+
- uses: ./
129+
id: wait-repository-dispatch
130+
name: "Dispatch Using repository_dispatch Method And Wait For Run-ID"
131+
with:
132+
dispatch-method: "repository_dispatch"
133+
event-type: "repository-dispatch"
134+
repo: "${{ github.event.repository.name }}"
135+
owner: "${{ github.repository_owner }}"
136+
token: "${{ secrets.GITHUB_TOKEN }}"
137+
workflow-inputs: |
138+
{
139+
"string-type": "placeholder",
140+
"nested": {
141+
"number-type": 1,
142+
"boolean-type": true
143+
}
144+
}
145+
discover: true
146+
- id: verify-repository-dispatch-outcome
147+
name: Await Run ID ${{ steps.wait-repository-dispatch.outputs.run-id }}
148+
uses: codex-/await-remote-run@v1
149+
with:
150+
token: ${{ secrets.GITHUB_TOKEN }}
151+
repo: ${{ github.event.repository.name }}
152+
owner: ${{ github.repository_owner }}
153+
run_id: ${{ steps.wait-repository-dispatch.outputs.run-id }}
154+
- id: verify-repository-dispatch-outputs
155+
name: "Verify Action Outputs for repository-dispatch"
156+
shell: bash
157+
run: |
158+
set -euo pipefail
159+
160+
# wait-repository-dispatch
161+
if [[ -z "${{ steps.wait-repository-dispatch.outputs.run-id }}" ]]; then
162+
>&2 echo "🔴 wait-repository-dispatch step should output 'run-id'"; exit 1
163+
fi
164+
165+
if [[ -z "${{ steps.wait-repository-dispatch.outputs.run-url }}" ]]; then
166+
>&2 echo "🔴 wait-repository-dispatch step should output 'run-url'"; exit 1
167+
fi

0 commit comments

Comments
 (0)