GitHub Pages - Generate XML sitemap #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: GitHub Pages - Generate XML sitemap | |
| # Trigger the workflow manually or on a schedule (every day at midnight) | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 0 * * 0" | |
| jobs: | |
| sitemap_job: | |
| runs-on: ubuntu-latest | |
| name: Generate a sitemap | |
| steps: | |
| # Step to harden the runner for security purposes | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 | |
| with: | |
| disable-sudo: true | |
| egress-policy: audit | |
| allowed-endpoints: > | |
| github.com:443 | |
| # Step to checkout the repository | |
| - name: Checkout the repo | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| fetch-depth: 0 | |
| # Step to generate the sitemap using the cicirello/generate-sitemap action | |
| - name: Generate the sitemap | |
| id: sitemap | |
| uses: cicirello/generate-sitemap@eb8db82126ee30619883c8c43e8c49ec14ebd6dc # v1.10.1 | |
| with: | |
| base-url-path: https://userstyles.github.typpi.online/ | |
| additional-extensions: doc docx ppt pptx js css json xml xlsx xls pdf md markdown txt lua yaml yml png | |
| # Step to output the sitemap generation stats for debugging and verification | |
| - name: Output stats | |
| run: | | |
| echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}" | |
| echo "url-count = ${{ steps.sitemap.outputs.url-count }}" | |
| echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}" | |
| # Step to create a pull request with the new sitemap | |
| - name: Create Pull Request with new SiteMap | |
| id: create_pr | |
| uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 | |
| with: | |
| title: "Automated sitemap update" | |
| body: > | |
| Sitemap updated by the [generate-sitemap](https://github.com/cicirello/generate-sitemap) | |
| GitHub action. Automated pull-request generated by the | |
| [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action. | |
| # Step to set the pull request number or ID as an environment variable | |
| - name: Set pull request number or ID | |
| id: set_pr_number | |
| run: | | |
| pr_number=$(gh pr list --state open --base main --json number -q '.[0].number') | |
| if [ -n "$pr_number" ]; then | |
| echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV | |
| else | |
| echo "PR_NUMBER=" >> $GITHUB_ENV | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |