Skip to content

Commit

Permalink
Github action: add deploy workflow (alshedivat#163)
Browse files Browse the repository at this point in the history
* Github action: add deploy workflow

* Update .github/workflows/deploy.yml

Co-authored-by: Maruan <[email protected]>
  • Loading branch information
2 people authored and abojchevski committed May 16, 2021
1 parent 37646c2 commit c76b710
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
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"
if [[ ${GITHUB_REF} = refs/pull/*/merge ]]; then # pull request
echo "::set-output name=SRC_BRANCH::${GITHUB_HEAD_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
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
;;
-s|--src)
SRC_BRANCH="$2"
Expand All @@ -30,10 +29,16 @@ while [[ $# > 0 ]]; do
DEPLOY_BRANCH="$2"
shift
;;
--verbose)
set -x
;;
--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
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

0 comments on commit c76b710

Please sign in to comment.