From c5ae0f05e330829418ea55309e49837f10baf798 Mon Sep 17 00:00:00 2001 From: Last2014 Date: Sun, 16 Nov 2025 12:38:41 +0900 Subject: [PATCH] =?UTF-8?q?.gitea/workflows/deploy.yml=20=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .gitea/workflows/deploy.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..45c0afa --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,78 @@ +name: Build and Deploy to Cloudflare Pages + +on: + pull_request: {} + push: + branches: ["main"] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + run_install: false + + - name: Install deps + run: pnpm install --frozen-lockfile + + - name: Build Astro + run: pnpm build + + - name: Zip dist + run: | + cd dist + zip -r ../dist.zip . + + - name: Deploy to Cloudflare Pages via API + id: deploy + env: + CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} + CF_PROJECT_NAME: ${{ secrets.CF_PROJECT_NAME }} + run: | + RESPONSE=$(curl -s -X POST \ + "https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/pages/projects/${CF_PROJECT_NAME}/deployments" \ + -H "Authorization: Bearer ${CF_API_TOKEN}" \ + -F "artifact=@dist.zip" \ + -F "branch=${GITHUB_REF_NAME}") + + echo "$RESPONSE" > cf_response.json + + DEPLOY_ID=$(jq -r '.result.id' cf_response.json) + echo "deploy_id=$DEPLOY_ID" >> $GITHUB_OUTPUT + + PREVIEW_URL=$(jq -r '.result.url' cf_response.json) + echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT + + - name: Comment to PR (only on PR) + if: ${{ github.event_name == 'pull_request' }} + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GITEA_SERVER_URL: ${{ secrets.GITEA_SERVER_URL }} + run: | + PR_NUMBER="${{ github.event.pull_request.number }}" + REPO="${{ github.repository }}" + URL="${{ steps.deploy.outputs.preview_url }}" + DEPLOY_ID="${{ steps.deploy.outputs.deploy_id }}" + + COMMENT="🚀 **Cloudflare Pages Preview** + URL: ${URL} + Deployment ID: \`${DEPLOY_ID}\`" + + curl -X POST \ + -H "Content-Type: application/json" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -d "{\"body\": \"${COMMENT}\"}" \ + "${GITEA_SERVER_URL}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/comments"