Build GitHub Pages #219
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: "Build GitHub Pages" | |
run-name: "Build GitHub Pages" | |
on: | |
workflow_call: | |
push: | |
branches-ignore: [main] | |
permissions: | |
contents: read | |
env: | |
GH_TOKEN: ${{ github.token }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Checkout" | |
uses: actions/checkout@v4 | |
- name: "Install tools" | |
run: sudo apt install tidy pandoc | |
- name: "Install templates" | |
run: | | |
mkdir -p ~/.pandoc/templates | |
curl -sSL 'https://github.com/tajmone/pandoc-goodies/raw/refs/heads/master/templates/html5/github/GitHub.html5' -o ~/.pandoc/templates/GitHub.html5 | |
- name: "Retrieve Code of Conduct" | |
run: curl --header "${MEDIA_TYPE_HEADER}" --header "${AUTH_TOKEN_HEADER}" --create-dirs --output code-of-conduct.md "${CONTENTS_ENDPOINT}/CODE_OF_CONDUCT.md" | |
env: | |
CONTENTS_ENDPOINT: '${{ github.api_url }}/repos/${{ github.repository_owner }}/.github/contents' | |
MEDIA_TYPE_HEADER: "Accept: application/vnd.github.raw" | |
AUTH_TOKEN_HEADER: "Authorization: Bearer ${{ github.token }}" | |
- name: "Retrieve Security Policy" | |
run: curl --header "${MEDIA_TYPE_HEADER}" --header "${AUTH_TOKEN_HEADER}" --create-dirs --output security/policy.md "${CONTENTS_ENDPOINT}/SECURITY.md" | |
env: | |
CONTENTS_ENDPOINT: '${{ github.api_url }}/repos/${{ github.repository_owner }}/.github/contents' | |
MEDIA_TYPE_HEADER: "Accept: application/vnd.github.raw" | |
AUTH_TOKEN_HEADER: "Authorization: Bearer ${{ github.token }}" | |
- name: "Retrieve Contribution Guidlines" | |
run: curl --header "${MEDIA_TYPE_HEADER}" --header "${AUTH_TOKEN_HEADER}" --create-dirs --output contributing.md "${CONTENTS_ENDPOINT}/CONTRIBUTING.md" | |
env: | |
CONTENTS_ENDPOINT: '${{ github.api_url }}/repos/${{ github.repository_owner }}/.github/contents' | |
MEDIA_TYPE_HEADER: "Accept: application/vnd.github.raw" | |
AUTH_TOKEN_HEADER: "Authorization: Bearer ${{ github.token }}" | |
- id: latest-release | |
name: "Get Details of Latest Release" | |
run: gh release view --json "${JQ_PROPS}" --jq "${JQ_QUERY}" | tee -a "${GITHUB_OUTPUT}" | |
env: | |
GH_REPO: '${{ github.repository }}' | |
JQ_PROPS: 'tagName' | |
JQ_QUERY: '"tag_name=" + (.tagName | tostring)' | |
- name: "Generate an authors.yaml file" | |
run: gh api "${ENDPOINT}" --jq "${JQ_QUERY}" | tee authors.yaml | |
env: | |
ENDPOINT: '/repos/${{ github.repository }}/contributors' | |
JQ_QUERY: '"author-meta:" + (["", (.[] | .login)] | join("\n- "))' | |
- name: "Generate a changelog.md file" | |
run: gh api "${ENDPOINT}" --template "${TEMPLATE}" | tee changelog.md | |
env: | |
ENDPOINT: '/repos/${{ github.repository }}/releases' | |
TEMPLATE: | | |
--- | |
lang: en | |
title: Changelog | |
... | |
{{ range . -}} | |
## [{{.name}}]({{ .html_url }}) | |
{{- if .draft -}} | |
{{ " " }}![This is a draft release.](https://img.shields.io/badge/DRAFT-grey) | |
{{- else if .prerelease -}} | |
{{ " " }}![This is a pre-release.](https://img.shields.io/badge/PRE--RELEASE-orange) | |
{{- else if eq .tag_name "${{ steps.latest-release.outputs.tag_name }}" -}} | |
{{ " " }}![This is the latest release.](https://img.shields.io/badge/LATEST-green) | |
{{- end }} | |
{{ .body }} | |
{{ if .assets -}} | |
### Asset Downloads | |
{{- "\n" -}} | |
{{ range .assets }} | |
- [{{ or .label .name }}]({{ .browser_download_url }}) | |
{{- end }} | |
{{ end }} | |
{{- end }} | |
{{- /* noop */ -}} | |
- name: "Create generated HTML files" | |
run: | | |
make -f - << \EOF | |
all: $(patsubst %.md,%.html,$(wildcard *.md */*.md */*/*.md)) | |
rm -f header.html | |
%.html: %.md | |
pandoc --metadata-file=authors.yaml --template=GitHub.html5 --include-in-header=header.html --from markdown+yaml_metadata_block+backtick_code_blocks+fenced_code_attributes+inline_notes+emoji-implicit_figures --to html --standalone $< --output $@ | |
EOF | |
- name: "Create redirect HTML files" | |
run: | | |
make -f - << \EOF | |
all: $(patsubst %.redirect,%.html,$(wildcard *.redirect */*.redirect */*/*.redirect)) | |
rm -f redirect.html $(wildcard *.redirect */*.redirect */*/*.redirect) | |
%.html: %.redirect | |
@echo "Generating $@..." | |
$(file > $@, $(subst {{ .REDIRECT }},$(file < $<),$(file < redirect.html))) | |
EOF | |
- name: "Tidy the HTML" | |
run: find . -name '*.html' | xargs tidy -indent --wrap 0 --output-html yes --warn-proprietary-attributes no -quiet -modify | |
- name: "Generate a security.txt file" | |
run: | | |
tee security.txt << EOF | |
Contact: ${{ steps.configure-pages.outputs.base_url }}/contact | |
Policy: ${{ steps.configure-pages.outputs.base_url }}/security/policy | |
Acknowledgments: ${{ steps.configure-pages.outputs.base_url }}/humans.txt | |
Canonical: ${{ steps.configure-pages.outputs.base_url }}/security.txt | |
Expires: $(date -u +"%Y-12-31T23:59:59.999Z") | |
EOF | |
- name: "Generate a humans.txt file" | |
run: gh api "${ENDPOINT}" --template "${TEMPLATE}" | sh | tee humans.txt | |
env: | |
ENDPOINT: '/orgs/${{ github.repository_owner }}/repos' | |
TEMPLATE: | | |
echo "# Contributors by Repository" | |
echo | |
echo "A huge thanks to all and colaborators who have contributed on GitHub!" | |
echo | |
{{range .}} | |
echo "## {{.full_name}}" | |
echo | |
gh api '/repos/{{.full_name}}/contributors' --jq '.[].login' | sort -u | xargs -ILOGIN gh api '/users/LOGIN' --jq '"- @" + .login + " (" + (.name // .login) + ")"' | |
echo | |
{{end}} | |
- name: "Generate a robots.txt file" | |
run: | | |
tee robots.txt << EOF | |
# Block AI Crawlers (see: https://github.com/ai-robots-txt) | |
$(gh release download --repo ai-robots-txt/ai.robots.txt --pattern 'robots.txt' --output -) | |
# List of pages and files | |
Sitemap: ${{ steps.configure-pages.outputs.base_url }}/sitemap.txt | |
EOF | |
- name: "Generate a version.txt file" | |
run: | | |
tee version.txt << EOF | |
Deployed: $(date --universal +'%FT%TZ') | |
Version: v0.0.${{ github.run_number }}.$((${{ github.run_attempt }} - 1)) | |
Source: ${{ github.server_url }}/${{ github.repository }}/tree/$(echo "${{ github.sha }}" | head -c 7) | |
EOF | |
- name: "Generate a sitemap.txt file" | |
env: { BASE_URL: '${{ steps.configure-pages.outputs.base_url }}' } | |
run: | | |
touch sitemap.txt # this ensures that the sitemap detects itself | |
find . -type f -printf "${BASE_URL}/%P\n" | sed -e 's/\(\.html\)*$//g' | sort --unique | tee -a sitemap.txt | |
- name: "Archive Pages Artifact" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pages | |
path: | | |
. | |
!CNAME | |
!.nojekyll | |
!.git*/** |