name: Build and Deploy on: push: branches: ["main"] pull_request: branches: ["main"] workflow_dispatch: env: EDGEONE_PROJECT_NAME: blog1 ESA_PROJECT_NAME: cloud-blog CLOUDFLARE_PROJECT_NAME: cloud-blog GIT_DATE: ${{ github.event.head_commit.timestamp || github.event.pusher.date }} GIT_SHA: ${{ github.event.head_commit.id || github.sha }} jobs: build: runs-on: ubuntu-latest steps: - id: commit-hash uses: prompt/actions-commit-hash@v3 - name: Checkout uses: actions/checkout@v4 - name: Set build env run: | echo "BUILD_SHA=${{ github.sha }}" >> $GITHUB_ENV echo "BUILD_SHORT=${{ steps.commit-hash.outputs.short }}" >> $GITHUB_ENV echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV echo "BUILD_MESSAGE=${{ github.event.head_commit.message || '' }}" >> $GITHUB_ENV - 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-esa: 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 Node.js uses: actions/setup-node@v4 with: node-version: 24 # - name: Install Bun # uses: oven-sh/setup-bun@v2 - name: Download generate artifact uses: actions/download-artifact@v4 with: name: generate-output-${{ steps.commit-hash.outputs.short }} path: dist - name: Install ESA CLI run: | npm install -g esa-cli - name: Deploy to ESA run: | esa-cli login --access-key-id ${{ secrets.ESA_ACCESS_KEY_ID }} --access-key-secret ${{ secrets.ESA_ACCESS_KEY_SECRET }} esa-cli deploy --assets ./dist --name ${{ env.ESA_PROJECT_NAME }} --minify 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 Node.js uses: actions/setup-node@v4 with: node-version: 24 - name: Install Bun uses: oven-sh/setup-bun@v2 - name: Install Vercel CLI run: | bun install -g vercel - name: Deploy to Vercel run: | vercel build --prod --yes vercel --token ${{ secrets.VERCEL_TOKEN }} --prebuilt --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: Install Node.js uses: actions/setup-node@v4 with: node-version: 24 - name: Install Bun uses: oven-sh/setup-bun@v2 - 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' }} 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: Download generate artifact uses: actions/download-artifact@v4 with: name: generate-output-${{ steps.commit-hash.outputs.short }} path: dist - name: Install Cloudflare CLI run: | npm install -g wrangler - name: Deploy to Cloudflare Pages uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy ./dist --project-name="${{ env.CLOUDFLARE_PROJECT_NAME }}" # run: | # wrangler login --api-token ${{ secrets.CLOUDFLARE_API_TOKEN }} # wrangler deploy --name ${{ env.CLOUDFLARE_PROJECT_NAME }} --assets ./dist