ADD TO: publish action / post comment about available artifact #45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish wiki | |
on: | |
push: | |
branches: | |
- 'main' | |
paths: | |
- wiki/** | |
- .github/workflows/publish-wiki.yml | |
# Do a dry-run (check, no deploy) for PRs. | |
pull_request: | |
paths: | |
- wiki/** | |
- .github/workflows/publish-wiki.yml | |
# 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 | |
# Needed for the PR comment. | |
pull-requests: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- 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: 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 | |
# 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@v4 | |
with: | |
name: wiki-files | |
path: ./_wiki | |
if-no-files-found: error | |
retention-days: 10 | |
- name: "[PR only] Post comment to review artifact if workflow was updated" | |
if: ${{ github.event_name == 'pull_request' }} | |
uses: mshick/add-pr-comment@v2 | |
with: | |
# TODO: replace this with PAT | |
repo-token: ${{ secrets.PHPCS_GITHUB_TOKEN }} | |
message: | | |
Thank you for this PR. | |
A dry-run has been executed on your PR, executing all markdown pre-processing for the wiki files. | |
Please review the resulting final markdown files via the [created artifact](${{ steps.artifact.outputs.artifact-url }}). | |
This is especially important when adding new pages or updating auto-generated output blocks. | |
_N.B.: the above link will automatically be updated when this PR is updated._ | |
- name: Check GitHub Git Operations status | |
uses: crazy-max/ghaction-github-status@v4 | |
with: | |
git_threshold: partial_outage | |
- name: Deploy to wiki | |
uses: Andrew-Chen-Wang/github-wiki-action@v4 | |
env: | |
COMMIT_MSG: ${{ github.event.head_commit.message }} | |
with: | |
strategy: 'clone' | |
path: '_wiki/' | |
commit-message: ${{ env.COMMIT_MSG }} | |
# repository: PHPCSStandards/PHP_CodeSniffer | |
# token: ${{ secrets.PHPCS_GITHUB_TOKEN }} | |
dry-run: ${{ github.event_name == 'pull_request' }} |