Skip to content

ci: deploy-vitepress.yml #10

ci: deploy-vitepress.yml

ci: deploy-vitepress.yml #10

name: Deploy to Vercel
on:
push:
branches: [ master ]
pull_request_target:
branches: [ master ]
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
jobs:
check-if-need-deploy:
runs-on: ubuntu-latest
outputs:
doc-changed: ${{ steps.diff.outputs.DIFF }}
steps:
- uses: actions/checkout@v4
- name: get diff
id: diff
run:
echo $(git diff --name-only HEAD master docs)
echo $(git diff --name-only HEAD master docs) | wc -w | xargs -I {} echo "DIFF={}" >> "$GITHUB_OUTPUT"
echo ${{ steps.diff.outputs.DIFF }}
build-and-deploy:
runs-on: ubuntu-latest
needs: [ check-if-need-deploy ]
if: ${{ needs.check-if-need-deploy.outputs.doc-changed != '0' }}
steps:
- uses: actions/checkout@v4
with:
ref: 'vitepress'
- uses: actions/setup-node@v4
- name: install deps
run: npm install
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Determine Deployment Environment
id: get-deploy-env
run: |
if [[ (echo $(git diff --name-only HEAD origin/fetch/60 docs) | grep doc | wc -l) == '0' ]]; then
echo $(git diff --name-only HEAD origin/fetch/60 docs) | grep doc | wc -l >> "DIFF=$0" >> $GITHUB_OUTPUT
else
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
echo "TARGET_ENV=preview" >> $GITHUB_OUTPUT
else
echo "TARGET_ENV=production" >> $GITHUB_OUTPUT
fi
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=${{ steps.get-deploy-env.outputs.TARGET_ENV }} --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --target=${{ steps.get-deploy-env.outputs.TARGET_ENV }} --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} --target=${{ steps.get-deploy-env.outputs.TARGET_ENV }}