-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: FRON-71 vercel deploy workflow with CORS support in heroku
- Loading branch information
1 parent
eb3b30e
commit 2eb48c5
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Deploy to Vercel | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Lint", "CodeQL"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
deploy: | ||
# This condition checks if the workflow run was successful and if the branch is 'dev'. | ||
if: ${{ github.event.workflow_run.conclusion == 'success' && github.ref == 'refs/heads/dev' }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: ⬇️ Checkout code | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | ||
|
||
- name: ⎔ Setup node | ||
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d | ||
with: | ||
version: 9 | ||
run_install: true | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Install Vercel CLI | ||
run: npm install -g vercel@latest | ||
|
||
- name: Deploy to Vercel | ||
run: vercel --token ${{ secrets.VERCEL_TOKEN }} | ||
env: | ||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | ||
|
||
- name: Set CORS origin on Heroku | ||
if: github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' | ||
run: | | ||
PR_NUMBER=${{ github.event.number }} | ||
DEPLOYMENT_URL=$(vercel --token ${{ secrets.VERCEL_TOKEN }} --confirm) | ||
CURRENT_ORIGINS=$(heroku config:get ORIGINS --app ${{ secrets.HEROKU_APP_NAME }}) | ||
NEW_ORIGINS="${CURRENT_ORIGINS},${DEPLOYMENT_URL}" | ||
heroku config:set ORIGINS=$NEW_ORIGINS --app ${{ secrets.HEROKU_APP_NAME }} | ||
heroku config:set PR_${PR_NUMBER}_DEPLOYMENT_URL=$DEPLOYMENT_URL --app ${{ secrets.HEROKU_APP_NAME }} | ||
env: | ||
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} | ||
|
||
- name: Remove CORS origin from Heroku | ||
if: github.event.action == 'closed' | ||
run: | | ||
PR_NUMBER=${{ github.event.number }} | ||
DEPLOYMENT_URL=$(heroku config:get PR_${PR_NUMBER}_DEPLOYMENT_URL --app ${{ secrets.HEROKU_APP_NAME }}) | ||
CURRENT_ORIGINS=$(heroku config:get ORIGINS --app ${{ secrets.HEROKU_APP_NAME }}) | ||
NEW_ORIGINS=$(echo $CURRENT_ORIGINS | sed "s|,$DEPLOYMENT_URL||g" | sed "s|$DEPLOYMENT_URL,||g" | sed "s|$DEPLOYMENT_URL||g") | ||
heroku config:set ORIGINS=$NEW_ORIGINS --app ${{ secrets.HEROKU_APP_NAME }} | ||
heroku config:unset PR_${PR_NUMBER}_DEPLOYMENT_URL --app ${{ secrets.HEROKU_APP_NAME }} | ||
env: | ||
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} |