Skip to content

merico-dev/docs-cn/master-bd016e #144

merico-dev/docs-cn/master-bd016e

merico-dev/docs-cn/master-bd016e #144

Workflow file for this run

name: Incremental Build Triggered By Push Events
on: repository_dispatch
jobs:
build:
name: Retrieve docs and deploy the website
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# if there's a action without sha1, it will write a cahce
# in linux-gatsby-cache-2- and will be used everytime latter action being dispatched
- name: Bailout
if: ${{ !github.event.client_payload.sha }}
run: exit 1
# https://github.com/gatsbyjs/gatsby/issues/11406
- name: Increase file watchers
if: ${{ !env.ACT }}
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
# make sure there is only one workflow running
- name: Turnstyle
if: ${{ !env.ACT }}
uses: softprops/turnstyle@v1
- name: Set known_hosts
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' }}
id: known-hosts
run: |
echo "::set-output name=HK::$(ssh-keyscan -H ${{ secrets.HK_HOST }})"
- name: Install SSH Key
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' }}
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: |
${{ steps.known-hosts.outputs.HK }}
- uses: actions/setup-node@v2
if: ${{ !env.ACT }}
with:
node-version: "16"
cache: "yarn"
- name: Install yarn (ACT)
# Since actions/setup-node currently errors out when run locally, here is a manual installation
if: ${{ env.ACT }}
run: |
echo "node version:"
node -v
echo "npm version:"
npm -v
npm install -g yarn
- name: Install deps
run: yarn
# - name: Restore docs
# uses: actions/cache@v2
# id: docs-cache
# with:
# path: markdown-pages
# key: ${{ runner.os }}-docs-cache-4-${{ github.event.client_payload.sha }} # You can inc the version number to force cache rebuild
# restore-keys: |
# ${{ runner.os }}-docs-cache-4-
# if download_type is full, download all docs
- name: Download all docs
# if: github.event.client_payload.download_type == 'full'
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
yarn run download:ee:zh:all
- name: Download specific docs
if: github.event.client_payload.download_type == 'partial'
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: eval "${{ github.event.client_payload.command }}"
# incremental: get the base commit from cache for furthur use
- name: Get base commit cache
if: github.event.client_payload.download_type != 'full'
id: cache-commit
run: |
REPO=$(cut -d"/" -f2 <<< "${{ github.event.client_payload.repo }}")
HASH=${{ github.workspace }}/markdown-pages/$REPO-${{ github.event.client_payload.ref }}.hash
BASE=""
if [ -f "$HASH" ]; then
BASE=$(cat $HASH)
fi
echo "get base hash: $BASE"
echo "::set-output name=path::$HASH"
echo "::set-output name=base::$BASE"
# incremental: download changed files
- name: Sync docs
if: steps.cache-commit.outputs.base != ''
env:
GITHUB_AUTHORIZATION_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
ACT=${{ env.ACT }}
[[ "${ACT:-false}" = "true" ]] && dryRun="true" || dryRun="false"
yarn sync ${{ github.event.client_payload.repo }} --ref ${{ github.event.client_payload.ref }} ${{ steps.cache-commit.outputs.base }} ${{ github.event.client_payload.sha }} --dry-run $dryRun
# - name: Restore gatsby cache
# uses: actions/cache@v2
# id: gatsby-cache
# with:
# path: |
# .cache
# public
# key: ${{ runner.os }}-gatsby-cache-3-${{ github.event.client_payload.sha }} # You can inc the version number to force cache rebuild
# restore-keys: |
# ${{ runner.os }}-gatsby-cache-3-
# - name: Build website
# env:
# CI: true
# GATSBY_ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
# GATSBY_ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
# run: |
# yarn build --verbose
# mv public/sitemap/sitemap-0.xml public/sitemap.xml
# ---- STAGING --
- name: Put everything to HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'staging' }}
run: |
rsync -avz --delete -e 'ssh -o StrictHostKeyChecking=no' ./.* "root@${{ secrets.HK_HOST }}:/root/website-docs/"
- name: Mod scripts on HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'staging' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "chmod a+x /root/website-docs/*.sh"
- name: Restart Service on HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'staging' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "service website-docs restart"
- name: Print Service Status on HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'staging' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "service website-docs status"
# ---- PRODUCTION --
- name: Put everything to HK-prod
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
rsync -avz --delete -e 'ssh -o StrictHostKeyChecking=no' ./.* "root@${{ secrets.HK_HOST }}:/root/website-docs-prod/"
- name: Mod scripts on HK-prod
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "chmod a+x /root/website-docs-prod/*.sh"
- name: Restart Service on HK-prod
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "service website-docs-prod restart"
- name: Print Service Status on HK-staging
if: ${{ !env.ACT && github.repository_owner == 'merico-dev' && github.event.client_payload.env == 'prod' }}
run: |
ssh -o "StrictHostKeyChecking no" root@${{ secrets.HK_HOST }} "service website-docs-prod status"
- name: Update current commit sha to cache
if: github.event.client_payload.download_type != 'full'
run: |
echo ${{ github.event.client_payload.sha }} > ${{ steps.cache-commit.outputs.path }}
# if does full building, store latest commit sha of all docs repo
- name: Update all commit hashes
if: github.event.client_payload.download_type == 'full'
run: |
bash ./scripts/get-latest-commits.sh ${{ secrets.GH_TOKEN }}