Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 0 additions & 212 deletions .github/workflows/deploy-preview.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/preview-build-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: preview-build-pr

on:
pull_request:
branches: [master]
types: [opened, synchronize, reopened]

permissions: {}

concurrency:
group: preview-build-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
build:
permissions:
contents: read
# Local reference for now; point at the central repo once published:
# uses: <org>/<central-repo>/.github/workflows/preview-build.yml@<pinned-sha>
uses: ./.github/workflows/preview-build.yml
with:
deployment-url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
Comment thread
banana-three-join marked this conversation as resolved.
70 changes: 70 additions & 0 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: preview-build

on:
workflow_call:
inputs:
deployment-url:
description: Base URL of the calling repo's GitHub Pages site, no trailing slash (e.g. https://owner.github.io/repo).
required: true
type: string

permissions: {}

defaults:
run:
shell: bash

jobs:
build:
if: github.event_name == 'pull_request'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be mistaken, but I suspect this condition could always evaluate to false, which would cause the reusable workflow to be skipped.

My understanding is that when a workflow is invoked through workflow_call, the event name inside the called workflow becomes workflow_call, not pull_request.

If that is the case, then:

if: github.event_name == 'pull_request'

would evaluate to false, and the build job would be skipped whenever the reusable workflow is invoked.

Even when the caller workflow itself is triggered by on: pull_request, I believe the called workflow still sees:

github.event_name == 'workflow_call'

so the condition above would remain false.

Could we confirm this behavior? If it is correct, it might be better to remove the condition and let the caller workflow decide when to invoke the reusable workflow.

runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Checkout PR code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- name: Setup Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod

- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: '22'
cache: npm

- name: Setup Hugo
uses: peaceiris/actions-hugo@2752ce1d29631191ea3f27c23495fa06139a5b78 # v3.2.1
with:
hugo-version: '0.158.0'
extended: true

- name: Install dependencies
run: npm ci

- name: Build preview
env:
BASE_URL: ${{ inputs.deployment-url }}/pr-preview/pr-${{ github.event.pull_request.number }}/
run: |
set -euo pipefail
hugo \
--cleanDestinationDir \
--environment dev \
--buildDrafts \
--buildFuture \
--buildExpired \
--minify \
--baseURL "$BASE_URL"

- name: Upload preview artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: preview-site
path: public
retention-days: 1
if-no-files-found: error
Loading
Loading