Skip to content

Commit 625fb69

Browse files
junghansalshedivat
andauthored
Github action: add deploy workflow (alshedivat#163)
* Github action: add deploy workflow * Update .github/workflows/deploy.yml Co-authored-by: Maruan <alshedivat@users.noreply.github.com>
1 parent 0369fe3 commit 625fb69

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

.github/workflows/deploy.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- source
8+
pull_request:
9+
branches:
10+
- master
11+
- source
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
- name: Setup Ruby
20+
uses: actions/setup-ruby@v1
21+
- name: Enable bundler cache
22+
uses: actions/cache@v2
23+
with:
24+
path: vendor/bundle
25+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
26+
restore-keys: |
27+
${{ runner.os }}-gems-
28+
- name: Install deps
29+
run: |
30+
gem install bundler
31+
bundle config path vendor/bundle
32+
bundle install --jobs 4 --retry 3
33+
- name: Setup deploy options
34+
id: setup
35+
run: |
36+
git config --global user.name "GitHub Action"
37+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
38+
if [[ ${GITHUB_REF} = refs/pull/*/merge ]]; then # pull request
39+
echo "::set-output name=SRC_BRANCH::${GITHUB_HEAD_REF}"
40+
echo "::set-output name=DRY_RUN::--dry-run"
41+
elif [[ ${GITHUB_REF} = refs/heads/* ]]; then # branch, e.g. master, source etc
42+
echo "::set-output name=SRC_BRANCH::${GITHUB_REF#refs/heads/}"
43+
fi
44+
if [[ ${{ github.repository }} = *.github.io ]]; then # user/org repo
45+
echo "::set-output name=DEPLOY_BRANCH::master"
46+
else
47+
echo "::set-output name=DEPLOY_BRANCH::gh-pages"
48+
fi
49+
- name: Deploy website
50+
run: yes | bin/deploy --verbose ${{ steps.setup.outputs.DRY_RUN }}
51+
--src ${{ steps.setup.outputs.SRC_BRANCH }}
52+
--deploy ${{ steps.setup.outputs.DEPLOY_BRANCH }}

bin/deploy

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
SRC_BRANCH="master"
88
DEPLOY_BRANCH="gh-pages"
99

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

1212
while [[ $# > 0 ]]; do
1313
key="$1"
@@ -20,7 +20,6 @@ while [[ $# > 0 ]]; do
2020
-u|--user)
2121
SRC_BRANCH="source"
2222
DEPLOY_BRANCH="master"
23-
shift
2423
;;
2524
-s|--src)
2625
SRC_BRANCH="$2"
@@ -30,10 +29,16 @@ while [[ $# > 0 ]]; do
3029
DEPLOY_BRANCH="$2"
3130
shift
3231
;;
32+
--verbose)
33+
set -x
34+
;;
35+
--dry-run)
36+
DRY_RUN="--dry-run"
37+
;;
3338
*)
34-
echo "Option $1 is unknown."
35-
echo $USAGE_MSG
36-
exit 0
39+
echo "Option $1 is unknown." >&2
40+
echo $USAGE_MSG >&2
41+
exit 1
3742
;;
3843
esac
3944
shift
@@ -88,7 +93,7 @@ rm -R _site/
8893
# Push to DEPLOY_BRANCH
8994
git add -fA
9095
git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]"
91-
git push -f -q origin $DEPLOY_BRANCH
96+
git push ${DRY_RUN} -f -q origin $DEPLOY_BRANCH
9297

9398
# Move back to SRC_BRANCH
9499
git checkout $SRC_BRANCH

0 commit comments

Comments
 (0)