Skip to content

Commit

Permalink
Merge pull request #35528 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
  • Loading branch information
docs-bot authored Dec 2, 2024
2 parents c460a19 + a21ae01 commit b2264a9
Show file tree
Hide file tree
Showing 59 changed files with 371 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .github/actions/get-docs-early-access/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ runs:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
GITHUB_TOKEN: ${{ inputs.token }}
shell: bash
run: node src/early-access/scripts/what-docs-early-access-branch.js
run: npm run what-docs-early-access-branch

- name: Clone
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/labeler/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ runs:
using: 'composite'
steps:
- name: Add label to an issue or pr
run: node .github/actions/labeler/labeler.js
run: npm run labeler
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
/* See function main in this file for documentation */

import coreLib from '@actions/core'

import github from '#src/workflows/github.js'
import { getActionContext } from '#src/workflows/action-context.js'
import { boolEnvVar } from '#src/workflows/get-env-inputs.js'
import { type Octokit } from '@octokit/rest'
import { CoreInject } from '@/links/scripts/action-injections'

import github from '#src/workflows/github.ts'
import { getActionContext } from '#src/workflows/action-context.ts'
import { boolEnvVar } from '#src/workflows/get-env-inputs.ts'

type Options = {
addLabels?: string[]
removeLabels?: string[]
ignoreIfAssigned?: boolean
ignoreIfLabeled?: boolean
issue_number?: number
owner?: string
repo?: string
}

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

const octokit = github()

const opts = {
addLabels: ADD_LABELS,
removeLabels: REMOVE_LABELS,
const opts: Options = {
ignoreIfAssigned: boolEnvVar('IGNORE_IF_ASSIGNED'),
ignoreIfLabeled: boolEnvVar('IGNORE_IF_LABELED'),
}

// labels come in comma separated from actions
let addLabels

if (opts.addLabels) {
addLabels = [...opts.addLabels.split(',')]
opts.addLabels = addLabels.map((l) => l.trim())
if (typeof ADD_LABELS === 'string') {
opts.addLabels = [...ADD_LABELS.split(',')].map((l) => l.trim())
} else {
opts.addLabels = []
}

let removeLabels

if (opts.removeLabels) {
removeLabels = [...opts.removeLabels.split(',')]
opts.removeLabels = removeLabels.map((l) => l.trim())
if (typeof REMOVE_LABELS === 'string') {
opts.removeLabels = [...REMOVE_LABELS.split(',')].map((l) => l.trim())
} else {
opts.removeLabels = []
}
Expand All @@ -54,7 +57,7 @@ if (import.meta.url.endsWith(process.argv[1])) {
opts.owner = owner
opts.repo = repo

main(coreLib, octokit, opts, {})
main(coreLib, octokit, opts)
}

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

if (!opts.issue_number || !opts.owner || !opts.repo) {
throw new Error(`Missing required parameters ${JSON.stringify(opts)}`)
}
const issueOpts = {
issue_number: opts.issue_number,
owner: opts.owner,
repo: opts.repo,
}

if (opts.ignoreIfAssigned || opts.ignoreIfLabeled) {
try {
const { data } = await octokit.issues.get({
issue_number: opts.issue_number,
owner: opts.owner,
repo: opts.repo,
})
const { data } = await octokit.issues.get(issueOpts)

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

if (opts.removeLabels?.length > 0) {
if (opts.removeLabels?.length) {
// removing a label fails if the label isn't already applied
let appliedLabels = []

try {
const { data } = await octokit.issues.get({
issue_number: opts.issue_number,
owner: opts.owner,
repo: opts.repo,
})

appliedLabels = data.labels.map((l) => l.name)
const { data } = await octokit.issues.get(issueOpts)
appliedLabels = data.labels.map((l) => (typeof l === 'string' ? l : l.name))
} catch (err) {
throw new Error(`Error getting issue: ${err}`)
}

opts.removeLabels = opts.removeLabels.filter((l) => appliedLabels.includes(l))
opts.removeLabels = opts.removeLabels?.filter((l) => appliedLabels.includes(l))

await Promise.all(
opts.removeLabels.map(async (label) => {
try {
await octokit.issues.removeLabel({
issue_number: opts.issue_number,
owner: opts.owner,
repo: opts.repo,
...issueOpts,
name: label,
})
} catch (err) {
Expand All @@ -138,17 +143,15 @@ export default async function main(core, octokit, opts = {}) {
}),
)

if (opts.removeLabels.length > 0) {
if (opts.removeLabels?.length) {
core.info(`Removed labels: ${opts.removeLabels.join(', ')}`)
}
}

if (opts.addLabels?.length > 0) {
if (opts.addLabels?.length) {
try {
await octokit.issues.addLabels({
issue_number: opts.issue_number,
owner: opts.owner,
repo: opts.repo,
...issueOpts,
labels: opts.addLabels,
})

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/azure-prod-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
CHECK_INTERVAL: 10000
EXPECTED_SHA: ${{ github.sha }}
CANARY_BUILD_URL: https://ghdocs-prod-canary.azurewebsites.net/_build
run: src/workflows/check-canary-slots.js
run: npm run check-canary-slots

- name: 'Swap canary slot to production'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/azure-staging-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
CHECK_INTERVAL: 10000
EXPECTED_SHA: ${{ github.sha }}
CANARY_BUILD_URL: https://ghdocs-staging-canary.azurewebsites.net/_build
run: src/workflows/check-canary-slots.js
run: npm run check-canary-slots

- name: 'Swap deployment slot to production'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-review-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Run script for audit-log-allowlists
run: |
node src/workflows/fr-add-docs-reviewers-requests.js
npm run fr-add-docs-reviewers-requests
env:
TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
PROJECT_NUMBER: 2936
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/enterprise-dates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ jobs:
- uses: ./.github/actions/node-npm-setup

- name: Run src/ghes-releases/scripts/update-enterprise-dates.js
run: |
src/ghes-releases/scripts/update-enterprise-dates.js
run: npm run update-enterprise-dates
env:
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}

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

- if: ${{ failure() }}
name: Delete remote branch (if previous steps failed)
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/enterprise-release-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ jobs:
- uses: ./.github/actions/node-npm-setup

- name: Create an enterprise release issue
run: |
src/ghes-releases/scripts/create-enterprise-issue.js release
run: npm run create-enterprise-issue -- release
env:
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}

- name: Create an enterprise deprecation issue
run: |
src/ghes-releases/scripts/create-enterprise-issue.js deprecation
run: npm run create-enterprise-issue -- deprecation
env:
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/index-general-search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:
FASTLY_TOKEN: ${{ secrets.FASTLY_TOKEN }}
FASTLY_SERVICE_ID: ${{ secrets.FASTLY_SERVICE_ID }}
FASTLY_SURROGATE_KEY: api-search:${{ matrix.language }}
run: src/workflows/purge-fastly-edge-cache.js
run: npm run purge-fastly-edge-cache

- uses: ./.github/actions/slack-alert
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/link-check-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
run: node src/early-access/scripts/what-docs-early-access-branch.js
run: npm run what-docs-early-access-branch

- name: Check out docs-early-access too, if internal repo
if: ${{ github.repository == 'github/docs-internal' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manually-purge-fastly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
FASTLY_TOKEN: ${{ secrets.FASTLY_TOKEN }}
FASTLY_SERVICE_ID: ${{ secrets.FASTLY_SERVICE_ID }}
FASTLY_SURROGATE_KEY: 'manual-purge'
run: src/workflows/purge-fastly-edge-cache.js
run: npm run purge-fastly-edge-cache
17 changes: 8 additions & 9 deletions .github/workflows/orphaned-files-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
- 'package*.json'
- src/assets/scripts/find-orphaned-assets.js
- src/content-render/scripts/reusables-cli/find/unused.ts
- src/workflows/walk-files.js
- src/workflows/walk-files.ts
- src/languages/lib/languages.js
- .github/actions/clone-translations/action.yml
- .github/actions/node-npm-setup/action.yml
Expand Down Expand Up @@ -91,14 +91,13 @@ jobs:
git push origin $branchname
body=$(cat <<-EOM
Found with the npm run find-orphaned-assets script.
The orphaned files workflow file .github/workflows/orphaned-files-check.yml
runs every Monday at 16:20 UTC / 8:20 PST.
The first responder should just spot-check some of the unused assets
to make sure they aren't referenced anywhere
and then approve and merge the pull request.
For more information, see [Doc: Orphaned Assets](https://github.com/github/docs-engineering/blob/main/docs/orphaned-assets.md)
and [Doc: Reusables CLI](https://github.com/github/docs-internal/tree/main/src/content-render/scripts/reusables-cli).
Found with the `npm run find-orphaned-assets` and `npm run -s reusables -- find unused` scripts.
The orphaned files workflow file .github/workflows/orphaned-files-check.yml runs every Monday at 16:20 UTC / 8:20 PST.
If you are the first responder, please spot check some of the unused assets to make sure they aren't referenced anywhere. Then, approve and merge the pull request.
For more information, see [Doc: Orphaned Assets](https://github.com/github/docs-engineering/blob/main/docs/orphaned-assets.md) and [Doc: Reusables CLI](https://github.com/github/docs-internal/tree/main/src/content-render/scripts/reusables-cli).
EOM
)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/os-ready-for-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

- name: Run script
run: |
node src/workflows/ready-for-docs-review.js
npm run ready-for-docs-review
env:
TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
PROJECT_NUMBER: 2936
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/purge-fastly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ jobs:

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

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

- uses: ./.github/actions/slack-alert
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/purge-old-deployment-environments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
env:
# Necessary to be able to delete deployment environments
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WORKFLOW_READORG }}
run: src/workflows/purge-old-deployment-environments.js
run: npm run purge-old-deployment-environments

- uses: ./.github/actions/slack-alert
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/purge-old-workflow-runs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
env:
# Necessary to be able to delete deployment environments
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WORKFLOW_READORG }}
run: src/workflows/purge-old-workflow-runs.js
run: npm run purge-old-workflow-runs

- uses: ./.github/actions/slack-alert
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ready-for-doc-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Run script
run: |
node src/workflows/ready-for-docs-review.js
npm run ready-for-docs-review
env:
TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
PROJECT_NUMBER: 2936
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/sync-graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
env:
# need to use a token from a user with access to github/github for this step
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WRITEORG_PROJECT }}
run: |
src/graphql/scripts/sync.js
run: npm run graphql-sync
- name: Create pull request
id: create-pull-request
uses: peter-evans/create-pull-request@6cd32fd93684475c31847837f87bb135d40a2b79 # pin @v7.0.3
Expand All @@ -53,7 +52,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
AUTOMERGE_PR_NUMBER: ${{ steps.create-pull-request.outputs.pull-request-number }}
run: node src/workflows/enable-automerge.js
run: npm run enable-automerge

- if: ${{ failure() }}
name: Delete remote branch (if previous steps failed)
Expand Down
Loading

0 comments on commit b2264a9

Please sign in to comment.