diff --git a/.github/actions/build-site/action.yaml b/.github/actions/build-site/action.yaml new file mode 100644 index 0000000..4b2586c --- /dev/null +++ b/.github/actions/build-site/action.yaml @@ -0,0 +1,23 @@ +name: "Build Hugo Site" +description: "Shared Hugo build logic" + +runs: + using: "composite" + steps: + - name: Install Hugo CLI + shell: bash + env: + HUGO_VERSION: "0.152.2" + run: | + wget -O ${{ runner.temp }}/hugo.deb \ + https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ + && sudo dpkg -i ${{ runner.temp }}/hugo.deb + - name: Build with Hugo + shell: bash + env: + # For backward compatibility with Hugo modules + HUGO_ENVIRONMENT: production + HUGO_ENV: production + run: | + hugo --gc --minify --baseURL "$BASE_URL" + diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..b5468f4 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,21 @@ +# Builds but does not deploy, for pull request validation. + +name: build + +on: + # Runs on pull requests + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + submodules: recursive + fetch-depth: 0 + - name: Build site + uses: ./.github/actions/build-site + env: + BASE_URL: "https://example.com/" diff --git a/.github/workflows/hugo.yaml b/.github/workflows/deploy.yaml similarity index 52% rename from .github/workflows/hugo.yaml rename to .github/workflows/deploy.yaml index e720053..495e99b 100644 --- a/.github/workflows/hugo.yaml +++ b/.github/workflows/deploy.yaml @@ -1,3 +1,6 @@ +# Builds and deploys the site to GitHub Pages. +# Does NOT run on pull requests. + name: build-and-deploy on: @@ -6,9 +9,6 @@ on: branches: - master - # Runs on pull requests - pull_request: - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -24,56 +24,28 @@ concurrency: group: "pages" cancel-in-progress: false -# Default to bash -defaults: - run: - shell: bash - jobs: - # Build job - build: + # Deployment job + build-and-deploy: runs-on: ubuntu-latest - env: - HUGO_VERSION: 0.152.2 + permissions: + contents: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} steps: - - name: Install Hugo CLI - run: | - wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ - && sudo dpkg -i ${{ runner.temp }}/hugo.deb - name: Checkout uses: actions/checkout@v6 with: submodules: recursive fetch-depth: 0 - - name: Build with Hugo + - name: Build site + uses: ./.github/actions/build-site env: - # For maximum backward compatibility with Hugo modules - HUGO_ENVIRONMENT: production - HUGO_ENV: production - run: | - hugo \ - --gc \ - --minify \ - --baseURL "${{ steps.pages.outputs.base_url }}/" - - name: Upload artifact - uses: actions/upload-pages-artifact@v4 - with: - path: ./public - - # Deployment job - deploy: - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - permissions: - contents: write - needs: build - steps: - - name: Deploy to GitHub Pages + BASE_URL: "${{ steps.pages.outputs.base_url }}/" + - name: Deploy id: deployment uses: peaceiris/actions-gh-pages@v4 with: - github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./public + github_token: ${{ secrets.GITHUB_TOKEN }}