Skip to content

Commit 628d4de

Browse files
committed
Merge branch 'feature/build-by-gh-actions' into develop
2 parents a71bade + 48b3df2 commit 628d4de

File tree

4 files changed

+235
-7
lines changed

4 files changed

+235
-7
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: 'Automatic build'
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths-ignore:
7+
- '.gitignore'
8+
- 'README.md'
9+
- 'LICENSE'
10+
11+
jobs:
12+
build-n-test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/setup-ruby@v1
17+
with:
18+
ruby-version: '2.6.x'
19+
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Bundle Caching
26+
id: bundle-cache
27+
uses: actions/cache@v1
28+
with:
29+
path: vendor/bundle
30+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile') }}
31+
restore-keys: |
32+
${{ runner.os }}-gems-
33+
34+
- name: Bundle config
35+
run: |
36+
bundle config path vendor/bundle
37+
38+
- name: Bundle Install
39+
if: steps.bundle-cache.outputs.cache-hit != 'true'
40+
run: |
41+
bundle install
42+
43+
- name: Bundle Install locally
44+
if: steps.bundle-cache.outputs.cache-hit == 'true'
45+
run: |
46+
bundle install --local
47+
48+
- name: Build Site
49+
run: |
50+
bash tools/build.sh -b ""
51+
52+
- name: Test Site
53+
run: |
54+
bash tools/test.sh
55+
56+
deploy:
57+
needs: build-n-test
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- uses: actions/setup-ruby@v1
62+
with:
63+
ruby-version: '2.6.x'
64+
65+
- name: Checkout
66+
uses: actions/checkout@v2
67+
with:
68+
fetch-depth: 0
69+
70+
- name: Bundle Caching
71+
id: bundle-cache
72+
uses: actions/cache@v1
73+
with:
74+
path: vendor/bundle
75+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile') }}
76+
restore-keys: |
77+
${{ runner.os }}-gems-
78+
79+
- name: Bundle config
80+
run: |
81+
bundle config path vendor/bundle
82+
83+
- name: Bundle Install
84+
if: steps.bundle-cache.outputs.cache-hit != 'true'
85+
run: |
86+
bundle install
87+
88+
- name: Bundle Install locally
89+
if: steps.bundle-cache.outputs.cache-hit == 'true'
90+
run: |
91+
bundle install --local
92+
93+
- name: Build site
94+
run: |
95+
bash tools/build.sh
96+
97+
- name: Deploy
98+
run: |
99+
bash tools/deploy.sh

tools/build.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,11 @@ main() {
8686
opt="$1"
8787
case $opt in
8888
-b|--baseurl)
89-
_check_unset $2
90-
if [[ $2 == \/* ]]
91-
then
92-
CMD+=" -b $2"
93-
else
94-
_help
95-
exit 1
89+
local _baseurl="$2"
90+
if [[ -z "$_baseurl" ]]; then
91+
_baseurl='""'
9692
fi
93+
CMD+=" -b $_baseurl"
9794
shift
9895
shift
9996
;;

tools/deploy.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
#
3+
# Deploy the content of _site to 'origin/<pages_branch>'
4+
#
5+
# v2.5
6+
# https://github.com/cotes2020/jekyll-theme-chirpy
7+
# © 2020 Cotes Chung
8+
# Published under MIT License
9+
10+
11+
set -eu
12+
13+
PAGES_BRANCH="gh-pages"
14+
15+
_no_branch=false
16+
17+
if [[ -z `git branch -av | grep $PAGES_BRANCH` ]]; then
18+
_no_branch=true
19+
git checkout -b $PAGES_BRANCH
20+
else
21+
git checkout $PAGES_BRANCH
22+
fi
23+
24+
mv _site ../
25+
mv .git ../
26+
27+
rm -rf * && rm -rf .[^.] .??*
28+
29+
mv ../_site/* .
30+
mv ../.git .
31+
32+
git config --global user.name "GitHub Actions"
33+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
34+
35+
git update-ref -d HEAD
36+
git add -A
37+
git commit -m "[Automation] Site update No.${GITHUB_RUN_NUMBER}"
38+
39+
if [[ $_no_branch = true ]]; then
40+
git push -u origin $PAGES_BRANCH
41+
else
42+
git push -f
43+
fi

tools/init.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
#
3+
# Init the evrionment for new user.
4+
#
5+
# v2.5
6+
# https://github.com/cotes2020/jekyll-theme-chirpy
7+
# © 2020 Cotes Chung
8+
# Published under MIT License
9+
10+
set -eu
11+
12+
13+
ACTIONS_WORKFLOW=pages-deploy.yml
14+
15+
help() {
16+
echo "Usage:"
17+
echo
18+
echo " bash /path/to/init.sh [options]"
19+
echo
20+
echo "Options:"
21+
echo " --no-gh Do not deploy to Github."
22+
echo " -h, --help Print this help information."
23+
}
24+
25+
check_init() {
26+
local _has_inited=false
27+
28+
if [[ -d .github ]]; then
29+
if [[ -f .github/workflows/$ACTIONS_WORKFLOW
30+
&& $(find .github/workflows/ -type f -name "*.yml" | wc -l) == 1 ]]; then
31+
_has_inited=true
32+
fi
33+
else
34+
_has_inited=true
35+
fi
36+
37+
if [[ $_has_inited = true ]]; then
38+
echo "Already initialized."
39+
exit 0
40+
fi
41+
}
42+
43+
44+
init_files() {
45+
46+
if [[ $_no_gh = true ]]; then
47+
rm -rf .github
48+
else
49+
mv .github/workflows/$ACTIONS_WORKFLOW.hook .
50+
rm -rf .github
51+
mkdir -p .github/workflows
52+
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}
53+
fi
54+
55+
rm -f .travis.yml
56+
rm -rf _posts/* docs
57+
58+
git add -A && git add .github -f
59+
git commit -m "[Automation] Initialize the environment." -q
60+
61+
echo "[INFO] Initialization successful!"
62+
}
63+
64+
65+
check_init
66+
67+
_no_gh=false
68+
69+
while (( $# ))
70+
do
71+
opt="$1"
72+
case $opt in
73+
--no-gh)
74+
_no_gh=true
75+
shift
76+
;;
77+
-h|--help)
78+
help
79+
exit 0
80+
;;
81+
*)
82+
# unknown option
83+
help
84+
exit 1
85+
;;
86+
esac
87+
done
88+
89+
init_files

0 commit comments

Comments
 (0)