Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github action: add deploy workflow #163

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy

on:
push:
branches:
- master
- source
pull_request:
branches:
- master
- source

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Ruby
uses: actions/setup-ruby@v1
- name: Enable bundler cache
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install deps
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Setup deploy options
id: setup
run: |
git config --global user.name "GitHub Action"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
alshedivat marked this conversation as resolved.
Show resolved Hide resolved
if [[ ${GITHUB_REF} = refs/pull/*/merge ]]; then # pull request
echo "::set-output name=SRC_BRANCH::${GITHUB_BASE_REF}"
echo "::set-output name=DRY_RUN::--dry-run"
elif [[ ${GITHUB_REF} = refs/heads/* ]]; then # branch, e.g. master, source etc
echo "::set-output name=SRC_BRANCH::${GITHUB_REF#refs/heads/}"
fi
junghans marked this conversation as resolved.
Show resolved Hide resolved
if [[ ${{ github.repository }} = *.github.io ]]; then # user/org repo
echo "::set-output name=DEPLOY_BRANCH::master"
else
echo "::set-output name=DEPLOY_BRANCH::gh-pages"
fi
- name: Deploy website
run: yes | bin/deploy --verbose ${{ steps.setup.outputs.DRY_RUN }}
--src ${{ steps.setup.outputs.SRC_BRANCH }}
--deploy ${{ steps.setup.outputs.DEPLOY_BRANCH }}
17 changes: 11 additions & 6 deletions bin/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
SRC_BRANCH="master"
DEPLOY_BRANCH="gh-pages"

USAGE_MSG="usage: deploy [-h|--help] [-u|--user] [-s|--src SRC_BRANCH] [-d|--deploy DEPLOY_BRANCH]"
USAGE_MSG="usage: deploy [-h|--help] [-u|--user] [-s|--src SRC_BRANCH] [-d|--deploy DEPLOY_BRANCH] [--verbose] [--dry-run]"

while [[ $# > 0 ]]; do
key="$1"
Expand All @@ -20,7 +20,6 @@ while [[ $# > 0 ]]; do
-u|--user)
SRC_BRANCH="source"
DEPLOY_BRANCH="master"
shift
alshedivat marked this conversation as resolved.
Show resolved Hide resolved
;;
-s|--src)
SRC_BRANCH="$2"
Expand All @@ -30,10 +29,16 @@ while [[ $# > 0 ]]; do
DEPLOY_BRANCH="$2"
shift
;;
--verbose)
set -x
;;
alshedivat marked this conversation as resolved.
Show resolved Hide resolved
--dry-run)
DRY_RUN="--dry-run"
;;
*)
echo "Option $1 is unknown."
echo $USAGE_MSG
exit 0
echo "Option $1 is unknown." >&2
echo $USAGE_MSG >&2
exit 1
;;
esac
shift
alshedivat marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -88,7 +93,7 @@ rm -R _site/
# Push to DEPLOY_BRANCH
git add -fA
git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]"
git push -f -q origin $DEPLOY_BRANCH
git push ${DRY_RUN} -f -q origin $DEPLOY_BRANCH

# Move back to SRC_BRANCH
git checkout $SRC_BRANCH
Expand Down