-
-
Notifications
You must be signed in to change notification settings - Fork 7
183 lines (152 loc) · 7.11 KB
/
publish-wiki.yml
File metadata and controls
183 lines (152 loc) · 7.11 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Publish wiki
on:
push:
branches:
- 'main'
paths:
- .github/workflows/publish-wiki.yml
- .github/workflows/pr-comment.yml
- build/wiki-code-samples/**
- build/wiki-command-replacer.sh
- wiki/**
# Do a dry-run (check, no deploy) for PRs.
pull_request:
paths:
- .github/workflows/publish-wiki.yml
- .github/workflows/pr-comment.yml
- build/wiki-code-samples/**
- build/wiki-command-replacer.sh
- wiki/**
# Allow running this workflow manually from the Actions tab.
workflow_dispatch:
# Allow this workflow to be triggered from outside.
repository_dispatch:
types:
- 'phpcs-release'
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "publish-wiki"
cancel-in-progress: false
jobs:
publish-wiki:
name: "Publish Wiki"
if: github.repository == 'PHPCSStandards/PHP_CodeSniffer-documentation'
runs-on: ubuntu-latest
permissions:
# Needed for the commit to the wiki.
contents: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
with:
php-version: 'latest'
ini-values: error_reporting=-1, display_errors=On, display_startup_errors=On, log_errors_max_len=0
tools: phpcs, phpcbf
coverage: none
# Make sure we've gotten the latest PHPCS version from setup-php.
- name: Retrieve latest release info
uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
id: get_latest_release
with:
route: GET /repos/PHPCSStandards/PHP_CodeSniffer/releases/latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Grab latest tag name from API response
id: latest_version
run: |
echo "TAG=${{ fromJson(steps.get_latest_release.outputs.data).tag_name }}" >> "$GITHUB_OUTPUT"
- name: Grab the version
id: phar_version
# yamllint disable-line rule:line-length
run: echo "VERSION=$(phpcs --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+(\.[0-9]+)+')" >> "$GITHUB_OUTPUT"
- name: Fail the build if the PHAR is not the correct version
if: ${{ steps.phar_version.outputs.VERSION != steps.latest_version.outputs.TAG }}
run: exit 1
# ################################################################################
# Update Wiki files.
# ################################################################################
- name: Install DocToc table of contents generator
run: npm install -g doctoc
- name: Copy wiki files to temporary location
shell: bash
run: cp -v -a wiki _wiki
- name: Find / replace output example placeholders
shell: bash
run: build/wiki-command-replacer.sh
- name: Update tables of contents
run: doctoc ./_wiki/ --github --maxlevel 4 --update-only
- name: Re-run tables of contents with different settings for specific file
run: doctoc ./_wiki/Version-4.0-User-Upgrade-Guide.md --github --maxlevel 3 --update-only
- name: Preface markdown files with warning not to edit in place
shell: bash
# yamllint disable rule:line-length
# shellcheck disable=SC2016
run: >
find ./_wiki/ -name "*.md*"
-exec sed -i
'1i\<!--\nWARNING: DO NOT EDIT THIS FILE IN THE WIKI.\nThis wiki is updated from the https://github.com/PHPCSStandards/PHP_CodeSniffer-documentation repository.\nSubmit a PR to that repository updating the relevant file in the /wiki/ subdirectory instead.\n-->\n' {} \;
# yamllint enable rule:line-length
# ################################################################################
# Dry-run/PRs: upload artifact with pre-processed files and post comment in PR.
# ################################################################################
# Retention is normally 90 days, but this artifact is only to help with reviewing PRs,
# especially when new output blocks are added or the (workflow) code for existing ones
# is updated. All in all, no need to keep the artifact for more than a few days.
- name: "[PR only] Upload the preprocessed wiki files as an artifact"
if: ${{ github.event_name == 'pull_request' }}
id: artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: wiki-files
path: ./_wiki
if-no-files-found: error
retention-days: 10
# ################################################################################
# Deploy to the wiki in the PHPCS repo.
# ################################################################################
- name: Check GitHub Git Operations status
uses: crazy-max/ghaction-github-status@f0ef9e1cf727f9f76f8485f8c525fa03afc4ec02 # v5.0.0
with:
git_threshold: partial_outage
- name: Deploy to wiki
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
uses: Andrew-Chen-Wang/github-wiki-action@64efa0a9436db17670a2259e0ac249d6f08bb352 # v5.0.4
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
DEFAULT_COMMIT_MSG: "Update wiki ${{ github.sha }}"
with:
strategy: 'clone'
path: '_wiki/'
commit-message: ${{ env.COMMIT_MSG != '' && env.COMMIT_MSG || env.DEFAULT_COMMIT_MSG }}
repository: PHPCSStandards/PHP_CodeSniffer
token: ${{ secrets.PHPCS_PUSH_TO_WIKI_TOKEN }}
dry-run: ${{ github.event_name == 'pull_request' }}
disable-empty-commits: true
preprocess: false
# ################################################################################
# Dry-run/PRs: save PR info for use in Pull Request Comment workflow.
# ################################################################################
- name: Create temporary directory
if: ${{ github.event_name == 'pull_request' }}
run: mkdir -p ./pr
- name: Save PR number
if: ${{ github.event_name == 'pull_request' }}
env:
PR_NUMBER: ${{ github.event.number }}
run: echo "${PR_NUMBER}" > ./pr/pr_number
- name: Save artifact URL
if: ${{ github.event_name == 'pull_request' }}
env:
ARTIFACT_URL: ${{ steps.artifact.outputs.artifact-url }}
run: echo "${ARTIFACT_URL}" > ./pr/artifact_url
- name: Upload PR info as artifact
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: pr_info
path: pr/