-
Notifications
You must be signed in to change notification settings - Fork 68.9k
Expand file tree
/
Copy pathvalidate-github-github-docs-urls.yml
More file actions
114 lines (97 loc) · 4.5 KB
/
Copy pathvalidate-github-github-docs-urls.yml
File metadata and controls
114 lines (97 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Validate github/github docs URLs
# Checks github/github docs-urls.json entries against docs-internal content.
on:
workflow_dispatch:
schedule:
- cron: '20 16 * * 1' # Run every Monday at 16:20 UTC / 8:20 PST
# Pull request triggers need https://gh.io/AAsyyao setup before they can run safely.
permissions:
contents: read
issues: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
validate_github_github_docs_urls:
name: Validate github/github docs URLs
if: github.repository == 'github/docs-internal'
runs-on: ubuntu-latest
steps:
- name: Check out repo's default branch
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: ./.github/actions/node-npm-setup
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
repository: github/github
ref: master
path: github
- name: Run validation
run: |
# checks.json feeds the later update and comment steps.
npm run validate-github-github-docs-urls -- validate \
--output checks.json \
--ignore-not-found \
github/config/docs-urls.json
- name: Update config/docs-urls.json in github/github (possibly)
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }}
run: |
npm run validate-github-github-docs-urls -- generate-new-json checks.json github/config/docs-urls.json
git config --global user.name "docs-bot"
git config --global user.email "77750099+docs-bot@users.noreply.github.com"
cd github
git status
git diff
changes=$(git diff --name-only | wc -l)
if [[ $changes -eq 0 ]]; then
echo "There are no changes to commit after running generate-new-json. Exiting this step"
exit 0
fi
current_timestamp=$(date '+%Y-%m-%d-%H%M%S')
branch_name="update-docs-urls-$current_timestamp"
git checkout -b "$branch_name"
current_daystamp=$(date '+%Y-%m-%d')
git commit -a -m "Update Docs URLs from automation ($current_daystamp)"
git push origin "$branch_name"
# Scheduled and manual runs create update-docs-urls branches for a human to turn into PRs.
- name: Clean up old branches in github/github
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }}
run: |
npm run validate-github-github-docs-urls -- clean-up-old-branches --prefix update-docs-urls
echo "To see them all, go to:"
echo "https://github.com/github/github/branches/all?query=update-docs-urls-"
# When a PR breaks docs-urls.json entries in github/github, comment for the
# author and reviewer.
# Common causes are moved pages without redirects or edited headings that break URL fragments.
# The fix can update docs-urls.json after merge or add a stable <a name="..."></a> anchor.
- name: Get changed content/data files
if: ${{ github.event_name == 'pull_request' }}
id: changed_files
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files: |
content/**
- name: Generate PR comment
if: ${{ github.event_name == 'pull_request' && steps.changed_files.outputs.any_modified == 'true' }}
env:
CHANGED_FILES: ${{ steps.changed_files.outputs.all_modified_files }}
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }}
ISSUE_NUMBER: ${{ github.event.pull_request.number }}
REPOSITORY: ${{ github.repository }}
run: |
npm run validate-github-github-docs-urls -- post-pr-comment checks.json --changed-files $CHANGED_FILES
- uses: ./.github/actions/create-workflow-failure-issue
id: create-failure-issue
if: ${{ failure() && github.event_name == 'schedule' }}
with:
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
- uses: ./.github/actions/slack-alert
if: ${{ failure() && github.event_name == 'schedule' }}
with:
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}