You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yours should look something like this where Source is Deploy from a branch. And the branch should be set to gh-pages.
Create your GitHub Actions file. I named mine .github/workflows/deploy-site.yml
Here's the contents:
# .github/workflows/deploy-site.ymlname: Deploy Siteon:
push:
branches:
- main # deploy main. If your branch is `master`, you'll have to replace that throughout this file.pull_request: # This will publish a site preview on every pull request, and also run the build command to test if the site is broken.# Allows you to run this workflow manually from the Actions tabworkflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-lateststrategy:
matrix:
node-version: [20]ruby-version: [3.1]env:
PR_PATH: pull/${{github.event.number}}steps:
- name: Comment on PRuses: hasura/[email protected]if: github.ref != 'refs/heads/main'with:
github-token: ${{ secrets.GITHUB_TOKEN }}repository: ${{ github.repository }}number: ${{ github.event.number }}id: deploy-previewmessage: "Starting deployment of preview ⏳..."
- name: Set domain# If you're using the default github pages url, use this instead:run: echo "DOMAIN=${{ github.actor }}.github.io" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}uses: actions/setup-node@v3with:
node-version: ${{ matrix.node-version }}# https://stackoverflow.com/questions/76107036/how-do-i-use-yarn-version-3-5-on-github-actions-error-cannot-find-module
- name: Install Yarn Stablerun: corepack prepare yarn@stable --activate
- name: Activate Yarn stablerun: yarn set version stable
- name: Install NPM dependenciesrun: yarn install --immutable --check-cache
- uses: ruby/setup-ruby@v1with:
ruby-version: ${{ matrix.ruby-version }}rubygems: latestbundler-cache: true
- name: Set production base URLrun: | echo "URL=https://${{ env.DOMAIN }}" >> $GITHUB_ENV echo "BASE_PATH=/${{ github.event.repository.name }}" >> $GITHUB_ENV
- name: Set base_path for preview if PRif: github.ref != 'refs/heads/main'run: echo "BASE_PATH=/${{ github.event.repository.name }}/${{ env.PR_PATH }}" >> $GITHUB_ENV
- name: Set base_urlrun: echo "BASE_URL=$URL/$BASE_PATH" >> $GITHUB_ENV
- name: Build siterun: yarn run build
- name: Set username + emailrun: | git config --global user.email "[email protected]" git config --global user.name "github-actions-bot"
- name: Deploy with gh-pagesif: github.ref == 'refs/heads/main'run: | git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git yarn exec gh-pages -d ./output --dotfiles -b gh-pages -- -u "github-actions-bot <[email protected]>"env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy preview with gh-pagesif: github.ref != 'refs/heads/main'run: | git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git yarn exec gh-pages -d ./output --dotfiles --dest "${{ env.PR_PATH }}" -b gh-pages -- -u "github-actions-bot <[email protected]>"env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update commentuses: hasura/[email protected]if: github.ref != 'refs/heads/main'with:
github-token: ${{ secrets.GITHUB_TOKEN }}repository: ${{ github.repository }}number: ${{ github.event.number }}id: deploy-previewmessage: "A preview of ${{ github.event.after }} is uploaded and can be seen here:\n\n ✨ ${{ env.BASE_URL }} ✨\n\nChanges may take a few minutes to propagate. Since this is a preview of production, content with `draft: true` will not be rendered. The source is here: https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/"
I know this was a lot, but this was me dumping what I did to deploy my last 3/4 sites with GH Pages. Sorry if it didn't make sense.
The text was updated successfully, but these errors were encountered:
Just making a note here we should either commit to updating docs to support GH Pages or make a note we don't offer support for GH Pages. Adding the 2.0 milestone.
Motivation
GitHub Pages is currently not the easiest to setup with a number of gotchas.
Suggestion
Add docs on how to deploy with GH pages!
Deploying to GitHub pages with Bridgetown + GitHub actions + preview deployments.
First step. Let's add the
gh-pages
packages to make deploys easier.yarn add -D gh-pages
build
command in your package.json"scripts"
key that looks like this:base_url
. I know Bridgetown deprecated thebase_url
options, but I really liked it. Modifyconfig/initializers.rb
to look like this:.env
or.envrc
at the root of your project so you can simulate "base_path" deployments.esbuild.config.js
// esbuild.config.js + const path = require("node:path") const build = require("./config/esbuild.defaults.js") // You can customize this as you wish, perhaps to add new esbuild plugins. // // ``` // const path = require("path") // const esbuildCopy = require('esbuild-plugin-copy').default // const esbuildOptions = { // plugins: [ // esbuildCopy({ // assets: { // from: [path.resolve(__dirname, 'node_modules/somepackage/files/*')], // to: [path.resolve(__dirname, 'output/_bridgetown/somepackage/files')], // }, // verbose: false // }), // ] // } // ``` // // You can also support custom base_path deployments via changing `publicPath`. // // ``` // const esbuildOptions = { // publicPath: "/my_subfolder/_bridgetown/static", // ... // } // ``` /** * @typedef { import("esbuild").BuildOptions } BuildOptions * @type {BuildOptions} */ const esbuildOptions = { + // If for some reason we need the `base_path` in the frontend. We could also add `base_url`. But its largely not needed. + define: { + "process.env.BASE_PATH": `"${process.env.BASE_PATH}"` + }, + // Adds `/<base_path>/_bridgetown/static` + publicPath: path.join(process.env.BASE_PATH, "_bridgetown", "static"), plugins: [ // add new plugins here... ], globOptions: { excludeFilter: /\.(dsd|lit)\.css$/ } } build(esbuildOptions)
Deploying from GitHub Actions
This gives your GitHub actions permissions to write to the
gh-pages
branch.Settings -> Pages
tab.https://github.com/{username}/{repo}/settings/pages
Yours should look something like this where
Source
isDeploy from a branch
. And thebranch
should be set togh-pages
..github/workflows/deploy-site.yml
Here's the contents:
I know this was a lot, but this was me dumping what I did to deploy my last 3/4 sites with GH Pages. Sorry if it didn't make sense.
The text was updated successfully, but these errors were encountered: