Github action: add deploy workflow (#163)
* Github action: add deploy workflow * Update .github/workflows/deploy.yml Co-authored-by: Maruan <alshedivat@users.noreply.github.com>
This commit is contained in:
parent
0369fe35e5
commit
625fb694d6
52
.github/workflows/deploy.yml
vendored
Normal file
52
.github/workflows/deploy.yml
vendored
Normal file
@ -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
bin/deploy
17
bin/deploy
@ -7,7 +7,7 @@
|
|||||||
SRC_BRANCH="master"
|
SRC_BRANCH="master"
|
||||||
DEPLOY_BRANCH="gh-pages"
|
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
|
while [[ $# > 0 ]]; do
|
||||||
key="$1"
|
key="$1"
|
||||||
@ -20,7 +20,6 @@ while [[ $# > 0 ]]; do
|
|||||||
-u|--user)
|
-u|--user)
|
||||||
SRC_BRANCH="source"
|
SRC_BRANCH="source"
|
||||||
DEPLOY_BRANCH="master"
|
DEPLOY_BRANCH="master"
|
||||||
shift
|
|
||||||
;;
|
;;
|
||||||
-s|--src)
|
-s|--src)
|
||||||
SRC_BRANCH="$2"
|
SRC_BRANCH="$2"
|
||||||
@ -30,10 +29,16 @@ while [[ $# > 0 ]]; do
|
|||||||
DEPLOY_BRANCH="$2"
|
DEPLOY_BRANCH="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--verbose)
|
||||||
|
set -x
|
||||||
|
;;
|
||||||
|
--dry-run)
|
||||||
|
DRY_RUN="--dry-run"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Option $1 is unknown."
|
echo "Option $1 is unknown." >&2
|
||||||
echo $USAGE_MSG
|
echo $USAGE_MSG >&2
|
||||||
exit 0
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
@ -88,7 +93,7 @@ rm -R _site/
|
|||||||
# Push to DEPLOY_BRANCH
|
# Push to DEPLOY_BRANCH
|
||||||
git add -fA
|
git add -fA
|
||||||
git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]"
|
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
|
# Move back to SRC_BRANCH
|
||||||
git checkout $SRC_BRANCH
|
git checkout $SRC_BRANCH
|
||||||
|
Loading…
Reference in New Issue
Block a user