Git Product home page Git Product logo

ghpages's Introduction

GitHub Action to Deploy Static Assets to GitHub Pages

This action has been deprecated. There's now "native" support for publishing to GitHub Pages using an official GitHub action by GitHub. It is much better than this approach.

Actions Status

This action simply lets you deploy arbitrary folders of static content from your workflow's working directory (/github/workspace) to GitHub pages. This works by having your action instance git push your chosen asset folder (BUILD_DIR) to the gh-pages branch of your GitHub repository for the gh-pages branch to be served. If you are running this action inside an organization or user repository (named username/username.github.io) it will deploy to the master branch instead.

Remember that you may also have to adjust your repository settings.

Because this action deploys to separate, "deploy-only" branches, you can not use it if you want to deploy from a repo subdirectory such as docs/. In those cases you really don't need a GitHub Action, because you would be committing the build artifacts yourself. For details see the GitHub Pages Documentation.

There are already great GitHub actions to use static site generators and then deploy to GitHub Pages (for jekyll, jekyll, zola and surely many more to come). This action isn't that, though I've borrowed much of the git action from these works.

This action will not build anything, it just deploys.

Inputs

None.

Outputs

None.

Secrets

Deployment to GitHub pages happens by git pushing to the gh-pages (or master) branch. To authorise this, the GitHub action needs a secret. For now, somewhat confusingly, the GITHUB_TOKEN available for every repo does suffice to push to gh-pages, but does not suffice to trigger a page build on GitHub, or even propagate the content to the GitHub content-delivery network.

You therefore have to create a custom Personal Access Token (PAT) much like you'd do for external services (say, Travis). This token must be created with repo permissions in order to deploy to Github Pages. You then have to paste this token into the GitHub UI as a secret under the name GH_PAT (repository settings/secrets) and call it in the action as in the below.

I've asked GitHub to streamline this process. The discussion is documented here.

Environment Variables

Just BUILD_DIR, the build directory relative to your repository root. You can also pass . if you want to push your repository root.

Example Usage

name: Deployment

"on":
  - push
  - pull_request

jobs:
  deploy_ghpages:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v1
      - run: echo $GITHUB_SHA >> public/index.html
      - uses: maxheld83/[email protected]
        env:
          BUILD_DIR: public/
          GH_PAT: ${{ secrets.GH_PAT }}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.