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 }}

ghpages's People

Contributors

alexlafroscia avatar landonschropp avatar leny avatar maxheld83 avatar verenaheld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ghpages's Issues

Does not work with the root directory (BUILD_DIR = /.)

It seems that the command add . from your script does not work correctly for the root dir in BUILD_DIR.

Here is the output I get with BUILD_DIR = /..
If I change the value, for example, to dist/ everything will work fine.

#################################################
Changing directory to 'BUILD_DIR' /. ...
#################################################
Now deploying to GitHub Pages...
warning: adding embedded git repository: github/workspace
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint: 	git submodule add <url> github/workspace
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint: 	git rm --cached github/workspace
hint: 
hint: See "git help submodule" for more information.
error: open("proc/1/mem"): Permission denied
error: unable to index file proc/1/mem
fatal: adding files failed
Initialized empty Git repository in /.git/

### FAILED GitHub Pages Deploy 17:24:08Z (10.705s)

alloy deploy to master branch /docs/

to fully cover the possibilities for GitHub pages sources, as per the docs, I guess we'd need this to.

(this is an extension of #3)

I'm a little cautious about this one, because deploying to docs/ you might:

  • overwrite something unintentionally using this action
  • pollute the commit history (I guess this is part of the docs/ logic)
  • bloat your repo size (see below)

We'd need to be quite careful with the git command as well; currently we can just write to some branch and delete all of its history and be done with it.

So this seems to add a lot of complexity.

Also, I just think docs/, if used at all, should be used by directly committing to it, not through some CI/CD.

deployment overwrites my master branch with the build

Sorry for coming with such a specific problem, but I'm trying to use the script for deploying a mkdocs website.

For some reason, the result is a brand new commit on master that totally overwrites the repo.

Does anyone have an idea of what happens here?

My .yml :

name: Publication

on:
  push:
    branches:
    - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout on Current Commit
      uses: actions/checkout@master
    - name: Setup python
      uses: actions/setup-python@v1
      with:
        python-version: '3.x'
        architecture: 'x64'
    - name: Install requirements
      run: python -m pip install -r py-requirements.txt
    - name: Build with mkdocs
      run: python -m mkdocs build --clean
    - name: Say that this is not Jekyll
      run: cat > site/.nojekyll
    - name: Publish site
      uses: maxheld83/[email protected]
      env:
        BUILD_DIR: "site/"
        GH_PAT: ${{ secrets.GH_PAT }}

Full code can be seen on gitlab (not on github since repo is reinitialized with each deploy ;-) :
https://gitlab.com/know-rmandie/know-rmandie.gitlab.io/blob/master/.github/workflows/mkdocs.yml

Return neutral code when nothing to commit

Hi, I use this great action to deploy my website after building the assets with npm scripts.

The fact is that this action also trigger the workflow (as it creates a commit/push on master), so it re-run the workflow... and crash with this (logical) message, as there's noting new to commit.

#################################################
Changing directory to 'BUILD_DIR' . ...
#################################################
Now deploying to GitHub Pages...
Reinitialized existing Git repository in /github/workspace/.git/
On branch master
nothing to commit, working tree clean

### FAILED deploy: gh-pages 10:37:26Z (601ms)

Maybe, in that specific case, it should be great to return a 78 exit code, indicating a neutral stop.

automatically prevent infinite loops

currently we're relying on people setting sensible filter actions before, but it'd be nice to avoid infinite loop armageddon out of the box.

Might happen if people deploy to gh-pages, and that deploy itself (which happens via PAT, not the usual GITHUB_TOKEN which prevents that sort of thing!) might trigger other builds, and so forth.

In simpler projects there shouldn't be any diff to commit on the >1st round, but if there is random stuff in the build such as the build time or something, this might get ugly.

run integration test

right now, the testing is kinda informal: you can just go to http://www.maxheld.de/ghpages/, and ideally, you should see the last commit sha there if things worked out.

I'd like to have a more fully programmatic way of testing this action, especially as more people rely on it, but I haven't quite figured out an elegant way to do this.

I'd probably involve talking with the GitHub API somehow, to check that the action (given some boilerplate setup) works as intended.

I am also developing this as part of the R package ghactions where I have good unit/integration testing tooling, and I'm not quite sure how that would work here.

Maybe postpone this to a later date, maybe github comes up with something.

GitHub default branch name is main

The Entrypoint.sh script currently has the master branch hardcoded, but the default github branch is now main. Suggest setting that as a parameter or updating to use the new default.

git push --force $REMOTE_REPO master:$REMOTE_BRANCH && \

Consider creating a `.nojekyll` file

If you're using this action with a documentation built with sphinx, you'll get 404 errors because no .nojekyll file is present in the generated commit.

Maybe this action should be configurable with a jekyll boolean input?

CNAME file

If you have a CNAME file, it will need to be added before deploy each time, otherwise your custom domain will be reset.

It would be great to have a GH_CNAME env var.

Choose gh-pages and master branch

Github can choose gh-pages and master branch for publishing github pages in non username.github.io repository.

I want to push master branch on repository that selected master branch to publish github pages.
but, ghpages action couldn't choose branch.

Can you update for it?

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.