Skip to content

fix the Vercel aliasing issue #32

fix the Vercel aliasing issue

fix the Vercel aliasing issue #32

Workflow file for this run

name: Increment Build Number, Deploy and Vercel Production Deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
branches:
- main
- '*' # This wildcard matches all branches except 'main' due to the job-level 'if' conditions
jobs:
build-deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Increment build number
run: |
# Read the current build number
build_number=$(cat build-number.txt)
# Increment the build number
echo $(($build_number + 1)) > build-number.txt
# Commit and push the change
git config user.name "GitHub Action"
git config user.email "[email protected]"
git add build-number.txt
git commit -m "Increment build number"
git push
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run:
vercel pull --yes --environment=production --token=${{
secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
build-preview:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Deploy to Vercel Preview
id: deploy
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: |
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/[^a-zA-Z0-9]/-/g')
DEPLOYMENT_URL=$(vercel --token=$VERCEL_TOKEN --scope my-vercel-team --confirm --name "my-app-$BRANCH_NAME" | tail -n 1)
echo "Deployment URL: $DEPLOYMENT_URL"
echo "::set-output name=preview_url::$DEPLOYMENT_URL"
- name: Alias Deployment
if: steps.deploy.outputs.preview_url
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: |
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/[^a-zA-Z0-9]/-/g')
ALIAS_URL="crypto-stdev-${BRANCH_NAME}.nushydude.vercel.app"
vercel alias set ${{ steps.deploy.outputs.preview_url }} $ALIAS_URL --token=$VERCEL_TOKEN
echo "Preview deployment is aliased to $ALIAS_URL"