Skip to content

Commit 8c5934e

Browse files
authored
Update src/workflows to TypeScript (#53220)
1 parent c78f2db commit 8c5934e

File tree

59 files changed

+364
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+364
-244
lines changed

.github/actions/get-docs-early-access/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ runs:
1616
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
1717
GITHUB_TOKEN: ${{ inputs.token }}
1818
shell: bash
19-
run: node src/early-access/scripts/what-docs-early-access-branch.js
19+
run: npm run what-docs-early-access-branch
2020

2121
- name: Clone
2222
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

.github/actions/labeler/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ runs:
2323
using: 'composite'
2424
steps:
2525
- name: Add label to an issue or pr
26-
run: node .github/actions/labeler/labeler.js
26+
run: npm run labeler
2727
shell: bash
2828
env:
2929
GITHUB_TOKEN: ${{ inputs.token }}

.github/actions/labeler/labeler.js renamed to .github/actions/labeler/labeler.ts

+46-43
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
/* See function main in this file for documentation */
22

33
import coreLib from '@actions/core'
4-
5-
import github from '#src/workflows/github.js'
6-
import { getActionContext } from '#src/workflows/action-context.js'
7-
import { boolEnvVar } from '#src/workflows/get-env-inputs.js'
4+
import { type Octokit } from '@octokit/rest'
5+
import { CoreInject } from '@/links/scripts/action-injections'
6+
7+
import github from '#src/workflows/github.ts'
8+
import { getActionContext } from '#src/workflows/action-context.ts'
9+
import { boolEnvVar } from '#src/workflows/get-env-inputs.ts'
10+
11+
type Options = {
12+
addLabels?: string[]
13+
removeLabels?: string[]
14+
ignoreIfAssigned?: boolean
15+
ignoreIfLabeled?: boolean
16+
issue_number?: number
17+
owner?: string
18+
repo?: string
19+
}
820

921
// When this file is invoked directly from action as opposed to being imported
1022
if (import.meta.url.endsWith(process.argv[1])) {
@@ -16,28 +28,19 @@ if (import.meta.url.endsWith(process.argv[1])) {
1628

1729
const octokit = github()
1830

19-
const opts = {
20-
addLabels: ADD_LABELS,
21-
removeLabels: REMOVE_LABELS,
31+
const opts: Options = {
2232
ignoreIfAssigned: boolEnvVar('IGNORE_IF_ASSIGNED'),
2333
ignoreIfLabeled: boolEnvVar('IGNORE_IF_LABELED'),
2434
}
2535

2636
// labels come in comma separated from actions
27-
let addLabels
28-
29-
if (opts.addLabels) {
30-
addLabels = [...opts.addLabels.split(',')]
31-
opts.addLabels = addLabels.map((l) => l.trim())
37+
if (typeof ADD_LABELS === 'string') {
38+
opts.addLabels = [...ADD_LABELS.split(',')].map((l) => l.trim())
3239
} else {
3340
opts.addLabels = []
3441
}
35-
36-
let removeLabels
37-
38-
if (opts.removeLabels) {
39-
removeLabels = [...opts.removeLabels.split(',')]
40-
opts.removeLabels = removeLabels.map((l) => l.trim())
42+
if (typeof REMOVE_LABELS === 'string') {
43+
opts.removeLabels = [...REMOVE_LABELS.split(',')].map((l) => l.trim())
4144
} else {
4245
opts.removeLabels = []
4346
}
@@ -54,7 +57,7 @@ if (import.meta.url.endsWith(process.argv[1])) {
5457
opts.owner = owner
5558
opts.repo = repo
5659

57-
main(coreLib, octokit, opts, {})
60+
main(coreLib, octokit, opts)
5861
}
5962

6063
/*
@@ -69,22 +72,31 @@ if (import.meta.url.endsWith(process.argv[1])) {
6972
* ignoreIfAssigned {boolean} don't apply labels if there are assignees
7073
* ignoreIfLabeled {boolean} don't apply labels if there are already labels added
7174
*/
72-
export default async function main(core, octokit, opts = {}) {
75+
export default async function main(
76+
core: typeof coreLib | CoreInject,
77+
octokit: Octokit,
78+
opts: Options = {},
79+
) {
7380
if (opts.addLabels?.length === 0 && opts.removeLabels?.length === 0) {
7481
core.info('No labels to add or remove specified, nothing to do.')
7582
return
7683
}
7784

85+
if (!opts.issue_number || !opts.owner || !opts.repo) {
86+
throw new Error(`Missing required parameters ${JSON.stringify(opts)}`)
87+
}
88+
const issueOpts = {
89+
issue_number: opts.issue_number,
90+
owner: opts.owner,
91+
repo: opts.repo,
92+
}
93+
7894
if (opts.ignoreIfAssigned || opts.ignoreIfLabeled) {
7995
try {
80-
const { data } = await octokit.issues.get({
81-
issue_number: opts.issue_number,
82-
owner: opts.owner,
83-
repo: opts.repo,
84-
})
96+
const { data } = await octokit.issues.get(issueOpts)
8597

8698
if (opts.ignoreIfAssigned) {
87-
if (data.assignees.length > 0) {
99+
if (data.assignees?.length) {
88100
core.info(
89101
`ignore-if-assigned is true: not applying labels since there's ${data.assignees.length} assignees`,
90102
)
@@ -105,31 +117,24 @@ export default async function main(core, octokit, opts = {}) {
105117
}
106118
}
107119

108-
if (opts.removeLabels?.length > 0) {
120+
if (opts.removeLabels?.length) {
109121
// removing a label fails if the label isn't already applied
110122
let appliedLabels = []
111123

112124
try {
113-
const { data } = await octokit.issues.get({
114-
issue_number: opts.issue_number,
115-
owner: opts.owner,
116-
repo: opts.repo,
117-
})
118-
119-
appliedLabels = data.labels.map((l) => l.name)
125+
const { data } = await octokit.issues.get(issueOpts)
126+
appliedLabels = data.labels.map((l) => (typeof l === 'string' ? l : l.name))
120127
} catch (err) {
121128
throw new Error(`Error getting issue: ${err}`)
122129
}
123130

124-
opts.removeLabels = opts.removeLabels.filter((l) => appliedLabels.includes(l))
131+
opts.removeLabels = opts.removeLabels?.filter((l) => appliedLabels.includes(l))
125132

126133
await Promise.all(
127134
opts.removeLabels.map(async (label) => {
128135
try {
129136
await octokit.issues.removeLabel({
130-
issue_number: opts.issue_number,
131-
owner: opts.owner,
132-
repo: opts.repo,
137+
...issueOpts,
133138
name: label,
134139
})
135140
} catch (err) {
@@ -138,17 +143,15 @@ export default async function main(core, octokit, opts = {}) {
138143
}),
139144
)
140145

141-
if (opts.removeLabels.length > 0) {
146+
if (opts.removeLabels?.length) {
142147
core.info(`Removed labels: ${opts.removeLabels.join(', ')}`)
143148
}
144149
}
145150

146-
if (opts.addLabels?.length > 0) {
151+
if (opts.addLabels?.length) {
147152
try {
148153
await octokit.issues.addLabels({
149-
issue_number: opts.issue_number,
150-
owner: opts.owner,
151-
repo: opts.repo,
154+
...issueOpts,
152155
labels: opts.addLabels,
153156
})
154157

.github/workflows/azure-prod-build-deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
CHECK_INTERVAL: 10000
127127
EXPECTED_SHA: ${{ github.sha }}
128128
CANARY_BUILD_URL: https://ghdocs-prod-canary.azurewebsites.net/_build
129-
run: src/workflows/check-canary-slots.js
129+
run: npm run check-canary-slots
130130

131131
- name: 'Swap canary slot to production'
132132
run: |

.github/workflows/azure-staging-build-deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
CHECK_INTERVAL: 10000
115115
EXPECTED_SHA: ${{ github.sha }}
116116
CANARY_BUILD_URL: https://ghdocs-staging-canary.azurewebsites.net/_build
117-
run: src/workflows/check-canary-slots.js
117+
run: npm run check-canary-slots
118118

119119
- name: 'Swap deployment slot to production'
120120
run: |

.github/workflows/docs-review-collect.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Run script for audit-log-allowlists
3535
run: |
36-
node src/workflows/fr-add-docs-reviewers-requests.js
36+
npm run fr-add-docs-reviewers-requests
3737
env:
3838
TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
3939
PROJECT_NUMBER: 2936

.github/workflows/enterprise-dates.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ jobs:
2929
- uses: ./.github/actions/node-npm-setup
3030

3131
- name: Run src/ghes-releases/scripts/update-enterprise-dates.js
32-
run: |
33-
src/ghes-releases/scripts/update-enterprise-dates.js
32+
run: npm run update-enterprise-dates
3433
env:
3534
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
3635

@@ -57,7 +56,7 @@ jobs:
5756
env:
5857
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
5958
AUTOMERGE_PR_NUMBER: ${{ steps.create-pull-request.outputs.pull-request-number }}
60-
run: node src/workflows/enable-automerge.js
59+
run: npm run enable-automerge
6160

6261
- if: ${{ failure() }}
6362
name: Delete remote branch (if previous steps failed)

.github/workflows/enterprise-release-issue.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ jobs:
2424
- uses: ./.github/actions/node-npm-setup
2525

2626
- name: Create an enterprise release issue
27-
run: |
28-
src/ghes-releases/scripts/create-enterprise-issue.js release
27+
run: npm run create-enterprise-issue -- release
2928
env:
3029
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
3130

3231
- name: Create an enterprise deprecation issue
33-
run: |
34-
src/ghes-releases/scripts/create-enterprise-issue.js deprecation
32+
run: npm run create-enterprise-issue -- deprecation
3533
env:
3634
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
3735

.github/workflows/index-general-search.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ jobs:
207207
FASTLY_TOKEN: ${{ secrets.FASTLY_TOKEN }}
208208
FASTLY_SERVICE_ID: ${{ secrets.FASTLY_SERVICE_ID }}
209209
FASTLY_SURROGATE_KEY: api-search:${{ matrix.language }}
210-
run: src/workflows/purge-fastly-edge-cache.js
210+
run: npm run purge-fastly-edge-cache
211211

212212
- uses: ./.github/actions/slack-alert
213213
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

.github/workflows/link-check-daily.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
env:
3434
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
3535
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
36-
run: node src/early-access/scripts/what-docs-early-access-branch.js
36+
run: npm run what-docs-early-access-branch
3737

3838
- name: Check out docs-early-access too, if internal repo
3939
if: ${{ github.repository == 'github/docs-internal' }}

.github/workflows/manually-purge-fastly.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
FASTLY_TOKEN: ${{ secrets.FASTLY_TOKEN }}
2828
FASTLY_SERVICE_ID: ${{ secrets.FASTLY_SERVICE_ID }}
2929
FASTLY_SURROGATE_KEY: 'manual-purge'
30-
run: src/workflows/purge-fastly-edge-cache.js
30+
run: npm run purge-fastly-edge-cache

.github/workflows/orphaned-files-check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
- 'package*.json'
1717
- src/assets/scripts/find-orphaned-assets.js
1818
- src/content-render/scripts/reusables-cli/find/unused.ts
19-
- src/workflows/walk-files.js
19+
- src/workflows/walk-files.ts
2020
- src/languages/lib/languages.js
2121
- .github/actions/clone-translations/action.yml
2222
- .github/actions/node-npm-setup/action.yml

.github/workflows/os-ready-for-review.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
- name: Run script
6060
run: |
61-
node src/workflows/ready-for-docs-review.js
61+
npm run ready-for-docs-review
6262
env:
6363
TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
6464
PROJECT_NUMBER: 2936

.github/workflows/purge-fastly.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ jobs:
4545

4646
- name: Purge Fastly edge cache independent of language
4747
if: ${{ inputs.nuke_all }}
48-
run: src/workflows/purge-fastly-edge-cache.js
48+
run: npm run purge-fastly-edge-cache
4949

5050
- name: Purge Fastly edge cache per language
5151
if: ${{ !inputs.nuke_all }}
5252
env:
5353
LANGUAGES: ${{ inputs.languages }}
54-
run: src/languages/scripts/purge-fastly-edge-cache-per-language.js
54+
run: npm run purge-fastly-edge-cache-per-language
5555

5656
- uses: ./.github/actions/slack-alert
5757
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

.github/workflows/purge-old-deployment-environments.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
env:
3030
# Necessary to be able to delete deployment environments
3131
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WORKFLOW_READORG }}
32-
run: src/workflows/purge-old-deployment-environments.js
32+
run: npm run purge-old-deployment-environments
3333

3434
- uses: ./.github/actions/slack-alert
3535
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

.github/workflows/purge-old-workflow-runs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
env:
2727
# Necessary to be able to delete deployment environments
2828
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WORKFLOW_READORG }}
29-
run: src/workflows/purge-old-workflow-runs.js
29+
run: npm run purge-old-workflow-runs
3030

3131
- uses: ./.github/actions/slack-alert
3232
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

.github/workflows/ready-for-doc-review.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Run script
4747
run: |
48-
node src/workflows/ready-for-docs-review.js
48+
npm run ready-for-docs-review
4949
env:
5050
TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
5151
PROJECT_NUMBER: 2936

.github/workflows/sync-graphql.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ jobs:
2525
env:
2626
# need to use a token from a user with access to github/github for this step
2727
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
28-
run: |
29-
src/graphql/scripts/sync.js
28+
run: npm run graphql-sync
3029
- name: Create pull request
3130
id: create-pull-request
3231
uses: peter-evans/create-pull-request@6cd32fd93684475c31847837f87bb135d40a2b79 # pin @v7.0.3
@@ -53,7 +52,7 @@ jobs:
5352
env:
5453
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
5554
AUTOMERGE_PR_NUMBER: ${{ steps.create-pull-request.outputs.pull-request-number }}
56-
run: node src/workflows/enable-automerge.js
55+
run: npm run enable-automerge
5756

5857
- if: ${{ failure() }}
5958
name: Delete remote branch (if previous steps failed)

0 commit comments

Comments
 (0)