Zack
Zack

Reputation: 6586

Instructions for custom GitHub Pages deploy

Can someone point me to the instructions for setting up a custom deploy for GitHub pages? (My Google skills are failing me.)

I have a site that needs only one modification when I deploy it on GitHub Pages: I want to replace all occurrences of foo.com with bar.com. I know that the first two steps are

  1. Add the .nojekyll file
  2. Configure GitHub Actions to check out the repo then run a simple search/replace script on all the .html files.

At this point, do I need to do anything else? Will adding my own, custom .github directory shadow/overwrite any necessary actions for deploying the web site?


(For those who are curious: I know that I can write a simple Jekyll plug-in to do this; but, I'd rather not add the Jekyl front matter to my files. Plus, Jekyll seems like overkill for the one, simple transformation I need.)

Upvotes: 3

Views: 2156

Answers (2)

Zack
Zack

Reputation: 6586

This is the workflow I created based on @VonC's suggestion:

The only difference between the example below and GitHub's static.yml is that I inserted lines 33-38 (the addition of the search-and-replace step using jacobtomlinson/gha-find-replace@v2).

# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ["main"]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow one concurrent deployment
concurrency:
  group: "pages"
  cancel-in-progress: true

jobs:
  # Single deploy job since we're just deploying
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Replace URL
        uses: jacobtomlinson/gha-find-replace@v2
        with:
          find: "http://localhost:8000"
          replace: "https://myPage.github.io"
          regex: false  
      - name: Setup Pages
        uses: actions/configure-pages@v1
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v1
        with:
          # Upload entire repository
          path: '.'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@main

Upvotes: 1

VonC
VonC

Reputation: 1324023

Considering JamesIves/github-pages-deploy-action can be configured to push your production-ready code into any branch you'd like, an alternative would be for your action to:

  • include a steps: - name: Replace which would replace the text in what was checked out
  • deploy the current checked out (and modified) folder

For the first point, you can use for instance a find-and-replace action, to find foo.com and replace it with bar.com.


Note: since you are using a GitHub Action, you can specify said action as publishing source

You can now deploy to a GitHub Pages site directly from a repository using GitHub Actions, without needing to set up a publishing source.

Using Actions to orchestrate Pages publishing provides many more options for choosing your authoring framework (Next.js, Hugo, Gatsby, Jekyll, NuxtJS or other technologies, and the associated versions thereof) as well as giving you finer control over the publishing process, such as leveraging deployment gates.

We have written several starter workflows for the most common frameworks but also have a “Static“ option if you want to deploy the contents of your repository with no build step.

https://i0.wp.com/user-images.githubusercontent.com/14911070/178842638-51b834d3-6c54-423e-95fa-822f734fa98a.png?ssl=1

Upvotes: 1

Related Questions