Skip to content

Commit 46a0cce

Browse files
committed
GH Actions: add a workflow to automatically deploy the wiki
This commit introduces a workflow, which will: * Automatically deploy the wiki files to the [PHP_CodeSniffer repo wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki) on every push to the `main` branch. * Will do a dry-run, without actually deploying, whenever a PR is created which would update the wiki files. This way, the wiki is opened up to contributions via pull requests and is no longer limited to only edits made by committers. A prominent warning is automatically added as a (hidden) comment at the top of each wiki file to warn committers not to edit the wiki file in the GitHub wiki interface. Any edits made via the GitHub wiki interface or by directly pushing to the wiki repository, will be lost and overwritten via this workflow the next time a change is pushed to the `main` branch of this repo. This commit also adds a `_Footer.md` file, which will automatically be displayed at the bottom of each wiki page to point out that the wiki is editable via PRs to this repo. Notes: * The files are copied to a `_wiki` directory - which is `.gitignore`d - before pre-processing to reduce the risk of the source files being accidentally updated (and committed), which would undo the automation. * Wiki commits will get the same commit message as the _last_ commit on the `main` branch. For that reason, merge commits are not allowed in this repo and PRs with only one commit are strongly preferred. * If the net effect of a commit results in no changes to the wiki files (CI changes and such), no commit will be made to the wiki. * The workflow is set up to fail if GitHub has an outage for git operations. That should protect the wiki from going down by a broken/partial commit and allows for retriggering a deploy once the outage has passed by re-running the failed build. Future scope (upcoming): * Automate generation of the Table of Contents for wiki pages. * Automate re-generation of output examples used in the wiki pages. Refs: * https://github.com/Andrew-Chen-Wang/github-wiki-action * https://github.com/crazy-max/ghaction-github-status
1 parent e1f85cc commit 46a0cce

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

.github/workflows/publish-wiki.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Publish wiki
2+
on:
3+
push:
4+
branches:
5+
- 'main'
6+
paths:
7+
- wiki/**
8+
- .github/workflows/publish-wiki.yml
9+
# Do a dry-run (check, no deploy) for PRs.
10+
pull_request:
11+
paths:
12+
- wiki/**
13+
- .github/workflows/publish-wiki.yml
14+
# Allow running this workflow manually from the Actions tab.
15+
workflow_dispatch:
16+
# Allow this workflow to be triggered from outside.
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "publish-wiki"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
publish-wiki:
26+
name: "Publish Wiki"
27+
if: github.repository == 'PHPCSStandards/PHP_CodeSniffer-documentation'
28+
29+
runs-on: ubuntu-latest
30+
31+
permissions:
32+
# Needed for the commit to the wiki.
33+
contents: write
34+
35+
steps:
36+
- name: Checkout code
37+
uses: actions/checkout@v4
38+
39+
- name: Copy wiki files to temporary location
40+
shell: bash
41+
run: cp -v -a wiki _wiki
42+
43+
- name: Preface markdown files with warning not to edit in place
44+
shell: bash
45+
# yamllint disable rule:line-length
46+
# shellcheck disable=SC2016
47+
run: >
48+
find ./_wiki/ -name "*.md*"
49+
-exec sed -i
50+
'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' {} \;
51+
# yamllint enable rule:line-length
52+
53+
- name: Check GitHub Git Operations status
54+
uses: crazy-max/ghaction-github-status@v4
55+
with:
56+
git_threshold: partial_outage
57+
58+
- name: Deploy to wiki
59+
uses: Andrew-Chen-Wang/[email protected]
60+
env:
61+
COMMIT_MSG: ${{ github.event.head_commit.message }}
62+
with:
63+
strategy: 'clone'
64+
path: '_wiki/'
65+
commit-message: ${{ env.COMMIT_MSG }}
66+
repository: PHPCSStandards/PHP_CodeSniffer
67+
token: ${{ secrets.PHPCS_PUSH_TO_WIKI_TOKEN }}
68+
dry-run: ${{ github.event_name == 'pull_request' }}
69+
disable-empty-commits: true
70+
preprocess: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_wiki/

wiki/_Footer.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_Found a mistake ? Think this documentation can be improved ?_
2+
3+
Contributions to this wiki are welcome! Submit a pull request to the [Documentation repository](https://github.com/PHPCSStandards/PHP_CodeSniffer-documentation) to propose your changes.

0 commit comments

Comments
 (0)