From db716da1aea5046dbee87e711e3e3e22b74b7147 Mon Sep 17 00:00:00 2001 From: Kohei Asai Date: Wed, 31 Jan 2024 23:19:50 -0800 Subject: [PATCH] chore: modify gha --- .github/actions/vercel-deploy/action.yml | 13 ++++++- .github/actions/vercel-prebuild/action.yml | 44 ++++++++++++++++++++-- .github/workflows/on-pull-request.yml | 3 ++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/.github/actions/vercel-deploy/action.yml b/.github/actions/vercel-deploy/action.yml index a9ab8de..3330412 100644 --- a/.github/actions/vercel-deploy/action.yml +++ b/.github/actions/vercel-deploy/action.yml @@ -20,9 +20,18 @@ runs: - name: Prepare for Vercel CLI run: | mkdir .vercel - echo "${{ "{" }} \"projectId\": \"${{ inputs.vercel-project-id }}\", \"orgId\": \"${{ inputs.vercel-org-id }}\" ${{ "}" }}" > .vercel/project.json + echo "{}" \ + | jq -c \ + '.projectId|="${{ inputs.vercel-project-id }}"' \ + '.orgId|="${{ inputs.vercel-org-id }}"' \ + > .vercel/project.json shell: bash - - name: Deploy + - name: Restore the Build from Artifacts + uses: actions/download-artifact@v4 + with: + name: vercel-build-${{ github.sha }} + path: .vercel/output + - name: Vercel Deploy id: deployment run: | npx vercel deploy \ diff --git a/.github/actions/vercel-prebuild/action.yml b/.github/actions/vercel-prebuild/action.yml index 55444ef..1f8ec4d 100644 --- a/.github/actions/vercel-prebuild/action.yml +++ b/.github/actions/vercel-prebuild/action.yml @@ -7,13 +7,51 @@ inputs: vercel-project-id: description: The project id at Vercel required: true + vercel-token: + description: The auth token for Vercel + required: true + build-command: + description: The shell command to build the application + default: npm run build + branch: + description: The Git branch. Keep empty for production deployments runs: using: "composite" steps: - - name: Prepare for Vercel CLI + - name: Prepare for Vercel Prebuild + if: ${{ inputs.branch == null }} + run: | + mkdir .vercel + echo "{}" \ + | jq -c \ + '.projectId|="${{ inputs.vercel-project-id }}"' \ + '.orgId|="${{ inputs.vercel-org-id }}"' \ + > .vercel/project.json + npx vercel pull \ + --token=${{ inputs.vercel-token }} \ + --environment=production + cat .vercel/project.json \ + | jq -c \ + '.buildCommand|="${{ inputs.build-command }}"' \ + > .vercel/project.json + shell: bash + - name: Prepare for Vercel Prebuild + if: ${{ inputs.branch != null }} run: | mkdir .vercel - echo "${{ "{" }} \"projectId\": \"${{ inputs.vercel-project-id }}\", \"orgId\": \"${{ inputs.vercel-org-id }}\", \"settings\": ${{ "{" }} \"createdAt\": 0, \"framework\": \"nextjs\", \"devCommand\": null, \"buildCommand\": \"next build\", \"outputDirectory\": null, \"rootDirectory\": null, \"directoryListing\": false, \"nodeVersion\": \"20.x\", \"analyticsId\": null ${{ "}" }} ${{ "}" }}" > .vercel/project.json + echo "{}" \ + | jq -c \ + '.projectId|="${{ inputs.vercel-project-id }}"' \ + '.orgId|="${{ inputs.vercel-org-id }}"' \ + > .vercel/project.json + npx vercel pull \ + --token=${{ inputs.vercel-token }} \ + --environment=preview \ + --git-branch=${{ inputs.branch }} + cat .vercel/project.json \ + | jq -c \ + '.buildCommand|="${{ inputs.build-command }}"' \ + > .vercel/project.json shell: bash - name: Build run: npx vercel build @@ -21,6 +59,6 @@ runs: - name: Store the Build as Artifacts uses: actions/upload-artifact@v4 with: - name: vercel-build + name: vercel-build-${{ github.sha }} path: .vercel/output if-no-files-found: error diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml index ac9acc1..07dfd21 100644 --- a/.github/workflows/on-pull-request.yml +++ b/.github/workflows/on-pull-request.yml @@ -47,6 +47,9 @@ jobs: with: vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} + vercel-token: ${{ secrets.VERCEL_TOKEN }} + branch: ${{ github.ref_name }} + build-command: npx next build deploy: name: Deploy needs: