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 #76 from helaili/use_github_token
Browse files Browse the repository at this point in the history
Use GitHub token
  • Loading branch information
helaili authored Jan 16, 2021
2 parents 08b1b45 + 8873eb5 commit a48b8b3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
jekyll_env: development
build_only: false
pre_build_commands: apk --update add imagemagick nodejs
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
token: ${{ secrets.GITHUB_TOKEN }}

basic-test:
runs-on: ubuntu-latest
Expand All @@ -34,7 +33,7 @@ jobs:
- name: Set the GH Pages branch
uses: actions/github-script@v3
with:
github-token: ${{secrets.JEKYLL_PAT}}
github-token: ${{secrets.JEKYLL_PAT}} # Need a PAT to switch the branch
script: |
await github.repos.updateInformationAboutPagesSite({
owner: context.repo.owner,
Expand Down Expand Up @@ -94,7 +93,7 @@ jobs:
target_branch: jekyll_src_test_pages_branch
jekyll_env: production
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
JEKYLL_PAT: ${{ secrets.GITHUB_TOKEN }}
JEKYLL_DEBUG: true

jekyll-src-test:
Expand All @@ -104,7 +103,7 @@ jobs:
- name: Set the GH Pages branch
uses: actions/github-script@v3
with:
github-token: ${{secrets.JEKYLL_PAT}}
github-token: ${{secrets.JEKYLL_PAT}} # Need a PAT to switch the branch
script: |
await github.repos.updateInformationAboutPagesSite({
owner: context.repo.owner,
Expand Down Expand Up @@ -162,8 +161,7 @@ jobs:
jekyll_src: sample_site
gem_src: sample_site_gemfiles
target_branch: jekyll_gem_src_test_pages_branch
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
token: ${{ secrets.GITHUB_TOKEN }}

jekyll-gem-src-test:
runs-on: ubuntu-latest
Expand All @@ -172,7 +170,7 @@ jobs:
- name: Set the GH Pages branch
uses: actions/github-script@v3
with:
github-token: ${{secrets.JEKYLL_PAT}}
github-token: ${{secrets.JEKYLL_PAT}} # Need a PAT to switch the branch
script: |
await github.repos.updateInformationAboutPagesSite({
owner: context.repo.owner,
Expand Down Expand Up @@ -229,8 +227,6 @@ jobs:
jekyll_build_options: "--config ../sample_site/_config.yml,../sample_site/_config_build_only.yml"
jekyll_env: development
build_only: true
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}

build-only-test:
runs-on: ubuntu-latest
Expand All @@ -239,7 +235,7 @@ jobs:
- name: Set the GH Pages branch
uses: actions/github-script@v3
with:
github-token: ${{secrets.JEKYLL_PAT}}
github-token: ${{secrets.JEKYLL_PAT}} # Need a PAT to switch the branch
script: |
await github.repos.updateInformationAboutPagesSite({
owner: context.repo.owner,
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ asciidoctor:
Note that we also renamed `index.html` to `index.adoc` and modified this file accordingly in order to leverage AsciiDoc.

### Use the action
Use the `helaili/jekyll-action@master` action in your workflow file. It needs access to a `JEKYLL_PAT` secret set with a Personal Access Token (needs ` public_repo` scope). The directory where the Jekyll site lives will be detected (based on the location of `_config.yml`) but you can also explicitly set this directory by setting the `jekyll_src` parameter (`sample_site` for us). The `SRC` environment variable is also supported for backward compatibilty but it is deprecated.
Use the `helaili/jekyll-action@master` action in your workflow file. It needs access to the out-of-the-box `GITHUB_TOKEN` secret. The directory where the Jekyll site lives will be detected (based on the location of `_config.yml`) but you can also explicitly set this directory by setting the `jekyll_src` parameter (`sample_site` for us). The `SRC` environment variable is also supported for backward compatibilty but it is deprecated.
The action will search for Gemfile location. If your want to specify it explicitly (e.g. if you have multiple Gemfiles per project), you should update `gem_src` input parameter accordingly.

Use the `actions/cache` action in the workflow as well, to shorten build times and decrease load on GitHub's servers
Expand All @@ -72,21 +72,19 @@ jobs:
# Standard usage
- uses: helaili/jekyll-action@v2
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Specify the Jekyll source location as a parameter
- uses: helaili/jekyll-action@v2
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
jekyll_src: 'sample_site'
# Specify the target branch (optional)
- uses: helaili/jekyll-action@v2
env:
JEKYLL_PAT: ${{ secrets.JEKYLL_PAT }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
target_branch: 'gh-pages'
```

Expand All @@ -100,6 +98,9 @@ Just click on the *_View deployment_* button of the `github-pages` environment t

## Inputs

### token
The `GITHUB_TOKEN` secret. This is mandatory unless `build_only` is set to `true`.

### jekyll_env
The Jekyll environment to build (default to `production`)

Expand All @@ -121,8 +122,8 @@ When set to `true`, the Jekyll site will be built but not published
### pre_build_commands
Commands to run prior to build and deploy. Useful for ensuring build dependencies are up to date or installing new dependencies. For example, use `apk --update add imagemagick` to install ImageMagick.

## Known Limitation
Publishing of the GitHub pages can fail when using the `GITHUB_TOKEN` secret as the value of the `JEKYLL_PAT` env variable, as opposed to a Personal Access Token set as a secret. But it might work too :smile:
## Deprecation
This action previously used a `JEKYLL_PAT` environment variable instead of the `token` parameter. This is now depreacted.

## I have a problem
Create a `ACTIONS_STEP_DEBUG` secret with value `true` and run the workflow again.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: 'Jekyll Actions'
description: 'A GitHub Action to build and publish Jekyll sites to GitHub Pages'
inputs:
token:
description: 'The GITHUB_TOKEN secret'
required: false
jekyll_env:
description: 'The Jekyll environment to build'
required: false
Expand Down
13 changes: 9 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ if [ -n "$INPUT_PRE_BUILD_COMMANDS" ]; then
eval "$INPUT_PRE_BUILD_COMMANDS"
fi

if [ -z "${JEKYLL_PAT}" ]; then
echo "::error::No token provided. Please set the JEKYLL_PAT environment variable."
if [ -z "${INPUT_TOKEN}" ] && [ -n "${JEKYLL_PAT}" ]; then
echo "::warning::The JEKYLL_PAT environment variable is deprecated. Please use the token parameter"
INPUT_TOKEN=${JEKYLL_PAT}
fi

if [ -z "${INPUT_TOKEN}" ] && [ "${INPUT_BUILD_ONLY}" != true ]; then
echo "::error::No token provided. Please set the token parameter."
exit 1
fi

Expand Down Expand Up @@ -106,9 +111,9 @@ if [ "${GITHUB_REF}" = "refs/heads/${remote_branch}" ]; then
fi

echo "Publishing to ${GITHUB_REPOSITORY} on branch ${remote_branch}"
echo "::debug::Pushing to https://${JEKYLL_PAT}@github.com/${GITHUB_REPOSITORY}.git"
echo "::debug::Pushing to https://${GITHUB_ACTOR}:${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

remote_repo="https://${JEKYLL_PAT}@github.com/${GITHUB_REPOSITORY}.git" && \
remote_repo="https://${GITHUB_ACTOR}:${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \
git init && \
git config user.name "${GITHUB_ACTOR}" && \
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" && \
Expand Down

0 comments on commit a48b8b3

Please sign in to comment.