Update README with latest project changes. #632
Workflow file for this run
This file contains 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: Diff HTML | |
on: | |
pull_request: | |
types: | |
# Defaults | |
- opened | |
- synchronize | |
- reopened | |
# Additional | |
- closed | |
env: | |
BRANCH_NAME_HTML_OLD: __diff__html_old | |
DIFF_CONTEXT: 5 | |
DIFF_TRUNCATE_TO_BYTES: 250000 | |
POST_COLLAPSE_GT_LINES: 10 | |
jobs: | |
Build: | |
uses: ./.github/workflows/build.yml | |
with: | |
prettyfy: true | |
skip_lints_tests: true | |
sphinx_github_branch: __diff__html_old | |
Commit: | |
if: github.event.action == 'closed' && github.event.pull_request.merged && github.event.pull_request.base.ref == 'main' | |
runs-on: ubuntu-latest | |
needs: Build | |
steps: | |
- name: Fetch New HTML | |
uses: actions/download-artifact@v4 | |
with: | |
name: html | |
path: html | |
- name: Store HTML in Orphaned Branch | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
commit_message: "[skip ci]" | |
enable_jekyll: true # Don't create .nojekyll | |
force_orphan: true # Discard git history | |
github_token: "${{ secrets.GITHUB_TOKEN }}" | |
publish_branch: "${{ env.BRANCH_NAME_HTML_OLD }}" | |
publish_dir: html | |
Diff: | |
if: github.event.action != 'closed' | |
runs-on: ubuntu-latest | |
needs: Build | |
steps: | |
- name: Fetch Old HTML | |
uses: actions/checkout@v4 | |
with: | |
ref: "${{ env.BRANCH_NAME_HTML_OLD }}" | |
path: html | |
- name: Prepare for New HTML | |
run: git -C html rm -r . && git -C html restore --staged . | |
- name: Fetch new HTML | |
uses: actions/download-artifact@v4 | |
with: | |
name: html | |
path: html | |
- name: Git Status | |
id: git_status | |
run: | | |
git -C html add . | |
git -C html status --porcelain |tee git_status.txt | |
if [ -s git_status.txt ]; then | |
echo "changed=true" >> $GITHUB_OUTPUT | |
else | |
echo "no-changes=true" >> $GITHUB_OUTPUT | |
rm -v git_status.txt | |
fi | |
- name: Git Diff | |
id: git_diff | |
if: hashFiles('git_status.txt') | |
run: | | |
git -C html diff --diff-filter=M --unified="$DIFF_CONTEXT" HEAD |grep -Pv "^(diff|index) " |tee git_diff.patch | |
if [ -s git_diff.patch ]; then | |
echo "modified=true" >> $GITHUB_OUTPUT | |
else | |
echo "no-modifications=true" >> $GITHUB_OUTPUT | |
rm -v git_diff.patch | |
fi | |
- name: Truncate | |
if: hashFiles('git_diff.patch') | |
run: | | |
cp git_diff.patch git_diff.patch.orig | |
truncate_to=$(( DIFF_TRUNCATE_TO_BYTES - $(wc -c < git_status.txt) )) | |
head --bytes="$truncate_to" git_diff.patch.orig > git_diff.patch | |
if ! cmp -s git_diff.patch git_diff.patch.orig; then | |
echo -e "\n\nTruncated" |tee -a git_diff.patch | |
tail --bytes=+"$(( truncate_to + 1 ))" git_diff.patch.orig > git_diff.patch.truncated | |
fi | |
rm -v git_diff.patch.orig | |
- name: Store Metafiles as Temporary Artifacts | |
if: hashFiles('git_status.txt') | |
uses: actions/upload-artifact@v4 | |
with: | |
name: git_status_diff | |
path: | | |
git_status.txt | |
git_diff.patch | |
git_diff.patch.truncated | |
outputs: | |
changed: "${{ steps.git_status.outputs.changed }}" | |
no-changes: "${{ steps.git_status.outputs.no-changes }}" | |
modified: "${{ steps.git_diff.outputs.modified }}" | |
no-modifications: "${{ steps.git_diff.outputs.no-modifications }}" | |
Post: | |
if: github.event.action != 'closed' | |
runs-on: ubuntu-latest | |
needs: Diff | |
concurrency: | |
cancel-in-progress: true | |
group: diff-post | |
env: | |
HEADER_PREFIX: "Diff Against [Old HTML]" | |
HEADER_URL_BASE: "https://github.com/${{ github.repository }}/tree" | |
steps: | |
- name: Fetch Metafiles | |
if: needs.Diff.outputs.changed | |
uses: actions/download-artifact@v4 | |
with: | |
name: git_status_diff | |
- name: Split Patch | |
if: hashFiles('git_diff.patch') | |
run: | | |
PS4="\n\033[1;33m$PS4\033[0m" | |
set -euxo pipefail | |
sudo apt-get update | |
sudo apt-get install -y rename splitpatch | |
splitpatch git_diff.patch | |
rm -v git_diff.patch | |
rename 's/.patch.(\d{3})$/.$1.patch/' *.patch.??? | |
ls -lah | |
- name: Post (No Changes) | |
if: needs.Diff.outputs.no-changes | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const url = `${process.env.HEADER_URL_BASE}/${process.env.BRANCH_NAME_HTML_OLD}` | |
const header = `${process.env.HEADER_PREFIX}(${url})` | |
const body = `*No HTML changes detected.*` | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `### ${header}\n\n${body}` | |
}) | |
- name: Post (No Modified) | |
if: needs.Diff.outputs.changed && needs.Diff.outputs.no-modifications | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const url = `${process.env.HEADER_URL_BASE}/${process.env.BRANCH_NAME_HTML_OLD}` | |
const header = `${process.env.HEADER_PREFIX}(${url})` | |
const fs = require(`fs`) | |
const gitStatus = fs.readFileSync(`git_status.txt`, {encoding:`utf8`, flag:`r`}).trimEnd() | |
const body = `\`\`\`\n${gitStatus}\n\`\`\`\n` | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `### ${header}\n\n${body}` | |
}) | |
- name: Post Diff | |
if: needs.Diff.outputs.changed && needs.Diff.outputs.modified | |
uses: actions/github-script@v7 | |
env: | |
IS_TRUNCATED: "${{ hashFiles('git_diff.patch.truncated') }}" | |
with: | |
script: | | |
const fs = require(`fs`) | |
function genHeader() { | |
const url = `${process.env.HEADER_URL_BASE}/${process.env.BRANCH_NAME_HTML_OLD}` | |
var header = `${process.env.HEADER_PREFIX}(${url})` | |
if (process.env.IS_TRUNCATED) { | |
var size = fs.statSync(`git_diff.patch.truncated`).size | |
header += ` (${size} Byte${size == 1 ? '' : 's'} Truncated)` | |
} | |
return header | |
} | |
function* yieldFileContents(dir, suffix) { | |
const files = fs.readdirSync(dir).filter(fileName => fileName.endsWith(suffix)) | |
for (const fileName of files) { | |
const contents = fs.readFileSync(fileName, {encoding:`utf8`, flag:`r`}) | |
yield {fileName: fileName.slice(0, -suffix.length), contents: contents} | |
} | |
} | |
function collapse(fileName, contents) { | |
var numLines = contents.match(/^/mg).length | |
if (numLines > parseInt(process.env.POST_COLLAPSE_GT_LINES)) | |
return `<details>\n<summary>Show ${numLines} lines from ${fileName}</summary>\n\n${contents}\n</details>` | |
return contents | |
} | |
// git status | |
const gitStatus = fs.readFileSync(`git_status.txt`, {encoding:`utf8`, flag:`r`}) | |
var body = collapse(`git_status.txt`, `\`\`\`\n${gitStatus.trimEnd()}\n\`\`\``) | |
// git diff | |
for (const {fileName, contents} of yieldFileContents(`./`, `.patch`)) { | |
body += `\n\n` + collapse(fileName, `\`\`\`diff\n${contents.trimEnd()}\n\`\`\``) | |
} | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `### ${genHeader()}\n\n${body}` | |
}) |