Merge pull request #10 from katomm/patch-1 #38
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: vercel-deploy | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
types: [ opened, synchronize ] | |
workflow_dispatch: | |
inputs: | |
pull-request-number: | |
required: true | |
type: integer | |
default: "" | |
env: | |
PRODUCTION_BRANCH: main | |
jobs: | |
vercel-deploy: | |
if: "! github.event.pull_request.head.repo.fork" | |
runs-on: ubuntu-latest | |
permissions: | |
deployments: write | |
pull-requests: write | |
steps: | |
- name: Checkout | |
if: "${{ github.event.inputs.pull-request-number == '' }}" | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive # Fetch private content | |
fetch-depth: 1 # Fetch all history for .GitInfo and .Lastmod | |
lfs: true | |
- name: Checkout workflow_dispatch input reference | |
if: "${{ github.event.inputs.pull-request-number != '' }}" | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive # Fetch private content | |
fetch-depth: 1 # Fetch all history for .GitInfo and .Lastmod | |
lfs: true | |
ref: "refs/pull/${{ github.event.inputs.pull-request-number }}/merge" | |
- name: ⛮ cf-gha-baseline | |
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: ⛮ Set vercel deploy metadata | |
id: metadata | |
run: | | |
if [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ] | |
then | |
PR_NUMBER=${{ github.event.inputs.pull-request-number }} | |
echo "PR_NUMBER=${PR_NUMBER}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}" | |
echo "DEPLOY_NAME=PR-${PR_NUMBER}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}" | |
else | |
if [ "${TRIGGERING_REF}" == "branch" ] | |
then | |
if [ "${BRANCH_NAME}" == "${PRODUCTION_BRANCH}" ] | |
then | |
echo "VERCEL_ARGS=--prod" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}" | |
fi | |
echo "DEPLOY_NAME=BRANCH-${BRANCH_NAME}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}" | |
elif [ "${TRIGGERING_REF}" == "pr" ] | |
then | |
echo "PR_NUMBER=${PR_NUMBER}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}" | |
echo "DEPLOY_NAME=PR-${PR_NUMBER}" | tee -a "$GITHUB_ENV" | tee -a "${GITHUB_OUTPUT}" | |
fi | |
fi | |
- name: Start Deployment | |
uses: bobheadxi/[email protected] | |
id: deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: vercel-deploy-${{ steps.metadata.outputs.DEPLOY_NAME }} | |
- name: Setup Node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '22' | |
- name: 🔨 Build project | |
env: | |
VITE_GITHUB_URL: https://github.com/cardano-foundation/cf-explorer-landing | |
VITE_CARDANO_URL: https://cardano.org/ | |
run: | | |
npm ci | |
npm run build | |
- name: Configure vercel.json | |
run: | | |
cat > dist/vercel.json <<EOF | |
{ | |
"rewrites": [ | |
{ | |
"source": "/((?!^/$).*)", | |
"destination": "/index.html" | |
} | |
] | |
} | |
EOF | |
# Push our generated site to Vercel | |
- name: Deploy to Vercel | |
uses: amondnet/vercel-action@v20 | |
id: vercel-action | |
with: | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required | |
#github-token: ${{ secrets.GITHUB_TOKEN }} #Optional | |
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} #Required | |
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} # Required | |
github-comment: false | |
vercel-args: ${{ steps.metadata.outputs.VERCEL_ARGS }} | |
working-directory: dist | |
- name: Comment PR | |
uses: thollander/actions-comment-pull-request@v1 | |
if: ${{ (github.event_name == 'pull_request') || (github.event_name == 'workflow_dispatch') }} | |
with: | |
message: 'Vercel PR (merge commit) deploy URL: ${{ steps.vercel-action.outputs.preview-url }}' | |
pr_number: ${{ steps.metadata.outputs.PR_NUMBER }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Update Deployment Status | |
uses: bobheadxi/[email protected] | |
if: always() | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
env_url: ${{ steps.vercel-action.outputs.preview-url }} |