Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #51 from gamue/target_branch
Browse files Browse the repository at this point in the history
Add option to configure target branch
  • Loading branch information
helaili authored Aug 24, 2020
2 parents 80930f2 + c60fd53 commit 57a6a26
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
gem_src: sample_site_gemfiles
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
- name: Run with target_branch
uses: ./
with:
target_branch: my_gh_pages_branch
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
- name: Basic run
uses: ./
env:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ A GitHub Action to build and publish Jekyll sites to GitHub Pages
Out-of-the-box Jekyll with GitHub Pages allows you to leverage a limited, white-listed, set of gems. Complex sites requiring custom ones or non white-listed ones (AsciiDoc for intstance) used to require a continuous integration build in order to pre-process the site.

Remember that GitHub is serving your built static site, not it's sources. So when configuring GitHub Pages in your project settings, use **gh-pages branch** as a Source for GitHub Pages. If you are setting up *username*.github.io repository, you'll have to use **master branch**, so sources can be located in another orphaned branch in the repo (which you can safely mark as default after the first publication).
In addition to that default behaviour, you can configure the branch this plugin pushes into with the `target_branch`-option. Keep in mind to set the source branch accordingly at the GitHub Pages Settings page.

Note that this is a rather simple (naive maybe) Docker based action. @limjh16 has created [a JS based version of this action](https://github.com/limjh16/jekyll-action-ts) which saves the container download time and might help with non default use cases.

Expand Down Expand Up @@ -80,6 +81,13 @@ jobs:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
with:
jekyll_src: 'sample_site'
# Specify the target branch (optional)
- uses: helaili/jekyll-action@2.0.3
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
with:
target_branch: 'gh-pages'
```

Upon successful execution, the GitHub Pages publishing will happen automatically and will be listed on the *_environment_* tab of your repository.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
gem_src:
description: 'The Jekyll Gemfile directory'
required: false
target_branch:
description: 'The target branch name the sources get pushed to'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
16 changes: 11 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ cd build
# No need to have GitHub Pages to run Jekyll
touch .nojekyll

# Is this a regular repo or an org.github.io type of repo
case "${GITHUB_REPOSITORY}" in
*.github.io) remote_branch="master" ;;
*) remote_branch="gh-pages" ;;
esac

if [ -n "${INPUT_TARGET_BRANCH}" ]; then
remote_branch="${INPUT_TARGET_BRANCH}"
echo "::debug::target branch is set via input parameter"
else
# Is this a regular repo or an org.github.io type of repo
case "${GITHUB_REPOSITORY}" in
*.github.io) remote_branch="master" ;;
*) remote_branch="gh-pages" ;;
esac
fi

if [ "${GITHUB_REF}" = "refs/heads/${remote_branch}" ]; then
echo "::error::Cannot publish on branch ${remote_branch}"
Expand Down

0 comments on commit 57a6a26

Please sign in to comment.