diff --git a/.github/actions/build-font/action.yml b/.github/actions/build-font/action.yml index 0f8f717..bf0980b 100644 --- a/.github/actions/build-font/action.yml +++ b/.github/actions/build-font/action.yml @@ -15,17 +15,17 @@ runs: steps: - name: Log in to GitHub Container Registry if: inputs.push-image == 'true' - uses: docker/login-action@v3 + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ env.GITHUB_TOKEN }} - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 - name: Build (and optionally push) Docker image - uses: docker/build-push-action@v6 + uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: context: xkcd-script/generator load: true @@ -44,11 +44,13 @@ runs: - name: Check generated files match committed files shell: bash + env: + VERSION: ${{ inputs.version }} run: | git diff --exit-code xkcd-script/font/ xkcd-script/samples/ || { echo "" echo "Generated files differ from committed files." - echo "Download the 'xkcd-script-font-${{ inputs.version }}' artifact from this run and commit the updated unversioned files (xkcd-script.{otf,ttf,woff,sfd} and the sample PNGs)." + echo "Download the 'xkcd-script-font-${VERSION}' artifact from this run and commit the updated unversioned files (xkcd-script.{otf,ttf,woff,sfd} and the sample PNGs)." exit 1 } @@ -60,17 +62,19 @@ runs: - name: Generate release artifacts shell: bash + env: + VERSION: ${{ inputs.version }} run: | rm -rf dist docker run --rm -v "$PWD":/repo -w /repo ghcr.io/ipython/xkcd-font:fontbuilder \ python3 xkcd-script/generator/generate_release_artifacts.py \ - --version "${{ inputs.version }}" \ + --version "$VERSION" \ --font-dir xkcd-script/font \ --js xkcd-script/xkcd-mathjax3.js \ --out-dir dist - name: Upload unversioned + release artifacts - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 if: always() with: name: xkcd-script-font-${{ inputs.version }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 364d427..feae7cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,8 +15,10 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/build-font + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + - uses: $/.github/actions/build-font with: version: 0.0-dev push-image: ${{ github.event_name == 'push' }} diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 4ab1d18..8a2d5e1 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -12,8 +12,6 @@ on: permissions: contents: read - pages: write - id-token: write concurrency: group: pages @@ -22,28 +20,36 @@ concurrency: jobs: build: runs-on: ubuntu-latest + permissions: + contents: read + pages: read # configure-pages reads the Pages site config env: GH_TOKEN: ${{ github.token }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false - name: Assemble site env: REPO: ${{ github.repository }} run: ./docs/build.sh - - uses: actions/configure-pages@v5 + - uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0 - - uses: actions/upload-pages-artifact@v3 + - uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1 with: path: build/html deploy: needs: build runs-on: ubuntu-latest + permissions: + pages: write + id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} steps: - id: deployment - uses: actions/deploy-pages@v4 + uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 diff --git a/.github/workflows/preview-link.yml b/.github/workflows/preview-link.yml index e533aa4..56d792a 100644 --- a/.github/workflows/preview-link.yml +++ b/.github/workflows/preview-link.yml @@ -1,7 +1,10 @@ name: Font preview link on: - pull_request_target: + # pull_request_target is required so fork PRs get a writable commit status. + # This job never checks out or executes PR code; it only reads the head SHA + # and posts a status, so the usual pull_request_target risks do not apply. + pull_request_target: # zizmor: ignore[dangerous-triggers] branches: [master] jobs: @@ -13,11 +16,13 @@ jobs: - name: Post font preview link env: GH_TOKEN: ${{ github.token }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + REPO: ${{ github.repository }} run: | - sha="${{ github.event.pull_request.head.sha }}" - font_url="https://raw.githubusercontent.com/${{ github.repository }}/${sha}/xkcd-script/font/xkcd-script.woff" + sha="$HEAD_SHA" + font_url="https://raw.githubusercontent.com/${REPO}/${sha}/xkcd-script/font/xkcd-script.woff" encoded=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$font_url") - gh api "repos/${{ github.repository }}/statuses/${sha}" \ + gh api "repos/${REPO}/statuses/${sha}" \ -f state=success \ -f target_url="https://ipython.org/xkcd-font/xkcd-script/?font=${encoded}" \ -f description="Click to preview the font from this PR" \ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ff8c688..df779a2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,9 +13,10 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: ref: ${{ github.event.release.tag_name }} + persist-credentials: false - name: Derive version from release tag id: version @@ -23,7 +24,7 @@ jobs: env: TAG: ${{ github.event.release.tag_name }} - - uses: ./.github/actions/build-font + - uses: $/.github/actions/build-font with: version: ${{ steps.version.outputs.value }} push-image: 'true' diff --git a/.github/workflows/zizmor.yml b/.github/workflows/zizmor.yml new file mode 100644 index 0000000..055b60d --- /dev/null +++ b/.github/workflows/zizmor.yml @@ -0,0 +1,25 @@ +name: GitHub Actions Security Analysis with zizmor + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + +permissions: + contents: read + +jobs: + zizmor: + runs-on: ubuntu-latest + permissions: + contents: read + # Needed to upload the results to the code-scanning dashboard. + security-events: write + actions: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + - name: Run zizmor + uses: zizmorcore/zizmor-action@85b2b9fb8e3325e7a23d7d0a9d7ba5ae0f999e3e # v0.7.1