猫猫 #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 当有改动推送到master分支时,启动Action | |
name: 自动部署 | |
on: | |
push: | |
branches: | |
- master #2020年10月后github新建仓库默认分支改为main,注意更改 | |
release: | |
types: | |
- published | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 检查分支 | |
uses: actions/checkout@v2 | |
with: | |
ref: master #2020年10月后github新建仓库默认分支改为main,注意更改 | |
- name: 安装 Node | |
uses: actions/setup-node@v1 | |
with: | |
node-version: "12.x" | |
- name: 安装 Hexo | |
run: | | |
export TZ='Asia/Shanghai' | |
npm install hexo-cli -g | |
- name: 缓存依赖 | |
id: cache-node-modules | |
uses: actions/cache@v2 | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-${{ matrix.node-version }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} | |
restore-keys: | | |
${{ runner.os }}-${{ matrix.node-version }}-nodeModules- | |
- name: 安装依赖 | |
if: steps.cache-node-modules.outputs.cache-hit != 'true' | |
run: npm install --save | |
- name: 生成静态文件 | |
run: | | |
hexo clean | |
hexo generate | |
- name: Deploy static site to S3 bucket | |
run: | | |
export AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} | |
export AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
export AWS_EC2_METADATA_DISABLED=true | |
aws s3 sync --endpoint-url https://s3.ladydaily.com ./public s3://ariasakablog | |
- name: 部署 #此处master:master 指从本地的master分支提交到远程仓库的master分支,若远程仓库没有对应分支则新建一个。如有其他需要,可以根据自己的需求更改。 | |
run: | | |
cd ./public | |
rm ./package.json | |
git init | |
git config --global user.name '${{ secrets.GITHUBUSERNAME }}' | |
git config --global user.email '${{ secrets.GITHUBEMAIL }}' | |
git add . | |
git commit -m "${{ github.event.head_commit.message }} $(date +"%Z %Y-%m-%d %A %H:%M:%S") Updated By Github Actions" | |
git push --force --quiet "https://${{ secrets.GITHUBUSERNAME }}:${{ secrets.GITHUBTOKEN }}@github.com/${{ secrets.GITHUBUSERNAME }}/${{ secrets.GITHUBUSERNAME }}.github.io.git" master:master | |
# - uses: aws-actions/configure-aws-credentials@v1 | |
# with: | |
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# aws-region: us-east-1 | |
# - name: NPM发布 | |
# run: | | |
# cd ./public | |
# npm publish | |
# env: | |
# NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN }} |