Trigger the docs deploy
job only when GH_PAGES_DEPLOY
secret is set.
#39
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
name: docs | ||
on: | ||
pull_request: | ||
branches: [main] | ||
paths: | ||
- docs/** | ||
- **/docs.yml | ||
push: | ||
branches: [main] | ||
paths: | ||
- docs/** | ||
workflow_dispatch: | ||
permissions: | ||
contents: write | ||
jobs: | ||
test-deploy: | ||
if: github.event_name != 'push' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
sparse-checkout: docs | ||
path: src-staging | ||
- name: Move docs | ||
run: | | ||
shopt -s dotglob | ||
mv src-staging/docs/* . | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache: yarn | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Test build website | ||
run: yarn build | ||
deploy: | ||
if: ${{ github.event_name != 'pull_request' && github.secrets.GH_PAGES_DEPLOY != '' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
sparse-checkout: docs | ||
path: src-staging | ||
- name: Move docs | ||
run: | | ||
shopt -s dotglob | ||
mv src-staging/docs/* . | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache: yarn | ||
- uses: webfactory/ssh-agent@v0.5.0 | ||
with: | ||
ssh-private-key: ${{ secrets.GH_PAGES_DEPLOY }} | ||
- name: Deploy to GitHub Pages | ||
env: | ||
USE_SSH: true | ||
run: | | ||
export COCOINDEX_DOCS_POSTHOG_API_KEY=${{ secrets.COCOINDEX_DOCS_POSTHOG_API_KEY }} | ||
export COCOINDEX_DOCS_MIXPANEL_API_KEY=${{ secrets.COCOINDEX_DOCS_MIXPANEL_API_KEY }} | ||
git config --global user.email "cocoindex.io@gmail.com" | ||
git config --global user.name "CocoIndex" | ||
yarn install --frozen-lockfile | ||
yarn deploy |