Skip to content

crazy-max/ghaction-github-pages

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

GitHub release GitHub marketplace CI workflow Become a sponsor Paypal Donate

About

A GitHub Action to deploy to GitHub Pages

GitHub Pages


Usage

Workflow

Below is a simple snippet to deploy to GitHub Pages with a dummy HTML page.

A workflow is also available for this repository and deploys every day to GitHub Pages.

name: website

on: push

permissions: 
  contents: write

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Gen dummy page
        run: |
          mkdir public
          cat > public/index.html <<EOL
          <!doctype html>
          <html>
            <head>
              <title>GitHub Pages deployed!</title>
            </head>
            <body>
              <p>GitHub Pages with <strong>${{ github.sha }}</strong> commit ID has been deployed through <a href="https://github.com/marketplace/actions/github-pages">GitHub Pages action</a> successfully.</p>
            </body>
          </html>
          EOL
      -
        name: Deploy to GitHub Pages
        uses: crazy-max/ghaction-github-pages@v4
        with:
          target_branch: gh-pages
          build_dir: public
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Sign commits

You can use the Import GPG action along with this one to sign commits:

      -
        name: Import GPG key
        uses: crazy-max/ghaction-import-gpg@v6
        with:
          gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
          passphrase: ${{ secrets.PASSPHRASE }}
          git_user_signingkey: true
          git_commit_gpgsign: true
      -
        name: Deploy to GitHub Pages
        uses: crazy-max/ghaction-github-pages@v4
        with:
          target_branch: gh-pages
          build_dir: public
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Check availability of GitHub Pages

You can use the GitHub Status action along with this one to check the availability of GitHub Pages before deploying:

      -
        name: Check GitHub Pages status
        uses: crazy-max/ghaction-github-status@v3
        with:
          pages_threshold: major_outage
      -
        name: Deploy to GitHub Pages
        uses: crazy-max/ghaction-github-pages@v4
        with:
          target_branch: gh-pages
          build_dir: public
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Customizing

inputs

Following inputs can be used as step.with keys

Name Type Description
domain String Git domain (default github.com)
repo String GitHub repository where assets will be deployed (default $GITHUB_REPOSITORY)
target_branch String Git branch where assets will be deployed (default gh-pages)
keep_history Bool Create incremental commit instead of doing push force (default false)
allow_empty_commit Bool Allow an empty commit to be created (default true)
build_dir String Build directory to deploy (required)
absolute_build_dir Bool Whether to treat build_dir as an absolute path (defaults to false, making it relative to the working directory)
follow_symlinks Bool If enabled, the content of symbolic links will be copied (default false)
committer String Committer name and email address as Display Name <[email protected]> (defaults to the GitHub Actions bot user)
author String Author name and email address as Display Name <[email protected]> (defaults to the GitHub Actions bot user)
commit_message String Commit message (default Deploy to GitHub pages)
fqdn String Write the given domain name to the CNAME file
jekyll Bool Allow Jekyll to build your site (default true)
dry_run Bool If enabled, nothing will be pushed (default false)
verbose Bool Enable verbose output (default false)

environment variables

Following environment variables can be used as step.env keys

Name Description
GITHUB_TOKEN GITHUB_TOKEN as provided by secrets
GH_PAT Use a Personal Access Token if you want to deploy to another repo

Contributing

Want to contribute? Awesome! The most basic way to show your support is to star the project, or to raise issues. You can also support this project by becoming a sponsor on GitHub or by making a PayPal donation to ensure this journey continues indefinitely!

Thanks again for your support, it is much appreciated! 🙏

License

MIT. See LICENSE for more details.