Files
Cloud-Blog/.github/workflows/build.yml
2026-01-17 15:40:23 +08:00

169 lines
4.5 KiB
YAML

name: Build and Deploy
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
EDGEONE_PROJECT_NAME: cloud-blog
jobs:
build:
runs-on: ubuntu-latest
steps:
- id: commit-hash
uses: prompt/actions-commit-hash@v3
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 24
- name: Install Bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install
- name: Check Linting
run: bun run lint
- name: Check Format
run: bun run format
- name: Run Unit Tests
run: bun run test
- name: Playgroud build check
run: bun run build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build-output-${{ steps.commit-hash.outputs.short }}
path: .output/public
retention-days: 7
- name: Playgroud generate check
run: bun run generate
- name: Upload generate artifact
uses: actions/upload-artifact@v4
with:
name: generate-output-${{ steps.commit-hash.outputs.short }}
path: dist
retention-days: 7
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
node_modules
~/.bun/install/cache
key: ${{ runner.os }}-build-${{ hashFiles('**/bun.lock') }}
deploy-vercel:
needs: build
if: ${{ github.event_name == 'push'}}
runs-on: ubuntu-latest
steps:
- id: commit-hash
uses: prompt/actions-commit-hash@v3
- name: Checkout
uses: actions/checkout@v4
- name: Install Vercel CLI
run: |
bun install -g vercel
- name: Deploy to Vercel
run: |
vercel --token ${{ secrets.VERCEL_TOKEN }} --prod --yes
deploy-edgeone:
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
steps:
- id: commit-hash
uses: prompt/actions-commit-hash@v3
- name: Checkout
uses: actions/checkout@v4
- name: Download generate artifact
uses: actions/download-artifact@v4
with:
name: generate-output-${{ steps.commit-hash.outputs.short }}
path: dist
- name: Install EdgeOne CLI
run: |
bun install -g edgeone || true
- name: Deploy to EdgeOne
run: |
if [ -z "${{ secrets.EDGEONE_TOKEN }}" ] || [ -z "${{ env.EDGEONE_PROJECT_NAME }}" ]; then
echo "Skipping EdgeOne deploy: missing EDGEONE_TOKEN or EDGEONE_PROJECT_NAME" && exit 0
fi
edgeone pages deploy ./dist --token ${{ secrets.EDGEONE_TOKEN }} --name "${{ env.EDGEONE_PROJECT_NAME }}"
# deploy-cloudflare:
# needs: build
# runs-on: ubuntu-latest
# if: ${{ github.event_name == 'push' && secrets.CLOUDFLARE_API_TOKEN != '' && secrets.CLOUDFLARE_ACCOUNT_ID != '' && secrets.CLOUDFLARE_PROJECT_NAME != '' }}
# steps:
# - id: commit-hash
# uses: prompt/actions-commit-hash@v3
# - name: Checkout
# uses: actions/checkout@v4
# - name: Download generate artifact
# uses: actions/download-artifact@v4
# with:
# name: generate-output-${{ steps.commit-hash.outputs.short }}
# path: dist
# - name: Deploy to Cloudflare Pages
# uses: cloudflare/pages-action@v1
# with:
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }}
# directory: dist
# deploy-aliyun:
# needs: build
# runs-on: ubuntu-latest
# if: ${{ github.event_name == 'push' && secrets.ALIYUN_ESA_DEPLOY_URL != '' && secrets.ALIYUN_ESA_TOKEN != '' }}
# steps:
# - id: commit-hash
# uses: prompt/actions-commit-hash@v3
# - name: Checkout
# uses: actions/checkout@v4
# - name: Download generate artifact
# uses: actions/download-artifact@v4
# with:
# name: generate-output-${{ steps.commit-hash.outputs.short }}
# path: dist
# - name: Package and Deploy to Aliyun ESA
# run: |
# cd dist || exit 1
# zip -r ../dist-deploy.zip .
# curl -v -X POST -H "Authorization: Bearer ${{ secrets.ALIYUN_ESA_TOKEN }}" -F "file=@../dist-deploy.zip" ${{ secrets.ALIYUN_ESA_DEPLOY_URL }}