.circleci/config.yml
配置文件
version: 2
jobs:
build:
docker:
- image: circleci/node:10
branches:
only:
- master
steps:
- add_ssh_keys:
fingerprints:
- "c5:20:8e:79:81:19:fd:c1:6c:c4:fb:41:58:92:9d:4f"
- checkout
- restore_cache:
keys:
# fallback to using the latest cache if no exact match is found
- dependencies-
- run:
name: Install
command: yarn install
- save_cache:
paths:
- node_modules
key: dependencies-
- run:
name: build github pages
command: yarn build
- run:
name: Prepare shell commands
command: chmod +x scripts/deploy.sh
- run:
name: Run deploy scripts
command: ./scripts/deploy.sh
这里以发布到github page为示例:
#!/bin/sh
# ideas used from https://gist.github.com/motemen/8595451
# Based on https://github.com/eldarlabs/ghpages-deploy-script/blob/master/scripts/deploy-ghpages.sh
# Used with their MIT license https://github.com/eldarlabs/ghpages-deploy-script/blob/master/LICENSE
# abort the script if there is a non-zero error
set -e
# show where we are on the machine
pwd
remote=$(git config remote.origin.url)
echo 'remote is: '$remote
# make a directory to put the gp-pages branch
mkdir gh-pages-branch
cd gh-pages-branch
# now lets setup a new repo so we can update the gh-pages branch
git config --global user.email "$GH_EMAIL" > /dev/null 2>&1
git config --global user.name "$GH_NAME" > /dev/null 2>&1
git init
git remote add --fetch origin "$remote"
echo 'email is: '$GH_EMAIL
echo 'name is: '$GH_NAME
echo 'sitesource is: '$siteSource
# switch into the the gh-pages branch
if git rev-parse --verify origin/gh-pages > /dev/null 2>&1
then
git checkout gh-pages
# delete any old site as we are going to replace it
# Note: this explodes if there aren't any, so moving it here for now
git rm -rf .
else
git checkout --orphan gh-pages
fi
# copy over or recompile the new site
cp -a "../${siteSource}/." .
ls -la
# stage any changes and new files
git add -A
# now commit, ignoring branch gh-pages doesn't seem to work, so trying skip
git commit --allow-empty -m "Deploy to GitHub pages [ci skip]"
# and push, but send any output to /dev/null to hide anything sensitive
git push --force --quiet origin gh-pages
# go back to where we started and remove the gh-pages git repo we made and used
# for deployment
cd ..
rm -rf gh-pages-branch
echo "Finished Deployment!"
说明:
>/dev/null 2>&1的含义
文件描述符
当执行shell命令时,会默认打开3个文件,每个文件有对应的文件描述符来方便我们使用:
类型 | 文件描述符 | 默认情况 | 对应文件句柄位置 |
---|---|---|---|
标准输入(standard input) | 0 | 从键盘获得输入 | /proc/slef/fd/0 |
标准输出(standard output) | 1 | 输出到屏幕(即控制台) | /proc/slef/fd/1 |
错误输出(error output) | 2 | 输出到屏幕(即控制台) | /proc/slef/fd/2 |
>
代表重定向到哪里?
例如:echo "123" > /home/123.txt
1
表示stdout
标准输出,系统默认值是1
,所以>/dev/null
等同于1>/dev/null
2
表示stderr
标准错误
&
表示等同于的意思,2>&1
,表示2
的输出重定向等同于1
参考资料: