From 470caac480096605624c8bc7ae28ea3498a3eef8 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Fri, 28 Jun 2024 11:34:00 +0800 Subject: [PATCH 1/4] ci: add vercel DR action --- .github/actions/vercel_DR_publish/action.yml | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/actions/vercel_DR_publish/action.yml diff --git a/.github/actions/vercel_DR_publish/action.yml b/.github/actions/vercel_DR_publish/action.yml new file mode 100644 index 0000000..b1ff566 --- /dev/null +++ b/.github/actions/vercel_DR_publish/action.yml @@ -0,0 +1,49 @@ +name: Deploy to Vercel +description: Deploy to Vercel +inputs: + VERCEL_ORG_ID: + description: Vercel organization ID + required: true + VERCEL_PROJECT_ID: + description: Vercel project ID + required: true + VERCEL_TOKEN: + description: Vercel token + required: true + ENVIRONMENT: + description: Environment + required: true + VERCEL_SCOPE: + description: Vercel scope + required: true + ALIAS_DOMAIN_PATH: + description: Alias domain + required: false + +runs: + using: composite + steps: + - name: Install Vercel CLI + run: npm install -g vercel + shell: bash + + - name: Pull Vercel project + shell: bash + run: | + vercel pull --yes --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} + + - name: Deploy to Vercel (Staging) + if: ${{ inputs.ENVIRONMENT == 'Staging' }} + shell: bash + run: | + vercel build --yes --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} + url="$(vercel deploy --prebuilt --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }})" + vercel alias "$url" ${{ inputs.ALIAS_DOMAIN_URL }} --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} + + - name: Deploy to Vercel (Production) + if: ${{ inputs.ENVIRONMENT == 'Production' }} + shell: bash + run: | + vercel build --yes --prod --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} + url="$(vercel deploy --prod --prebuilt --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }})" + vercel alias "$url" ${{ inputs.ALIAS_DOMAIN_URL }} --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} From 000582b28a81b264a7aefc1a1b67a250285dc866 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Fri, 28 Jun 2024 12:02:20 +0800 Subject: [PATCH 2/4] ci: pass inputs to envs --- .github/actions/vercel_DR_publish/action.yml | 33 ++++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/actions/vercel_DR_publish/action.yml b/.github/actions/vercel_DR_publish/action.yml index b1ff566..e704316 100644 --- a/.github/actions/vercel_DR_publish/action.yml +++ b/.github/actions/vercel_DR_publish/action.yml @@ -16,7 +16,7 @@ inputs: VERCEL_SCOPE: description: Vercel scope required: true - ALIAS_DOMAIN_PATH: + ALIAS_DOMAIN_URL: description: Alias domain required: false @@ -29,21 +29,34 @@ runs: - name: Pull Vercel project shell: bash + env: + VERCEL_TOKEN: ${{ inputs.VERCEL_TOKEN }} + VERCEL_SCOPE: ${{ inputs.VERCEL_SCOPE }} run: | - vercel pull --yes --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} + vercel pull --yes --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} - name: Deploy to Vercel (Staging) - if: ${{ inputs.ENVIRONMENT == 'Staging' }} + env: + VERCEL_TOKEN: ${{ inputs.VERCEL_TOKEN }} + VERCEL_SCOPE: ${{ inputs.VERCEL_SCOPE }} + ALIAS_DOMAIN_URL: ${{ inputs.ALIAS_DOMAIN_URL }} + ENVIRONMENT: ${{ inputs.ENVIRONMENT }} + if: ${{ env.ENVIRONMENT == 'Staging' }} shell: bash run: | - vercel build --yes --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} - url="$(vercel deploy --prebuilt --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }})" - vercel alias "$url" ${{ inputs.ALIAS_DOMAIN_URL }} --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} + vercel build --yes --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} + url="$(vercel deploy --prebuilt --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }})" + vercel alias "$url" ${{ env.ALIAS_DOMAIN_URL }} --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} - name: Deploy to Vercel (Production) - if: ${{ inputs.ENVIRONMENT == 'Production' }} + env: + VERCEL_TOKEN: ${{ inputs.VERCEL_TOKEN }} + VERCEL_SCOPE: ${{ inputs.VERCEL_SCOPE }} + ALIAS_DOMAIN_URL: ${{ inputs.ALIAS_DOMAIN_URL }} + ENVIRONMENT: ${{ inputs.ENVIRONMENT }} + if: ${{ env.ENVIRONMENT == 'Production' }} shell: bash run: | - vercel build --yes --prod --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} - url="$(vercel deploy --prod --prebuilt --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }})" - vercel alias "$url" ${{ inputs.ALIAS_DOMAIN_URL }} --token=${{ inputs.VERCEL_TOKEN }} --scope=${{ inputs.VERCEL_SCOPE }} + vercel build --yes --prod --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} + url="$(vercel deploy --prod --prebuilt --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }})" + vercel alias "$url" ${{ env.ALIAS_DOMAIN_URL }} --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} From 4356fde87d51dc6e6bc8fbee2c50af89651a14c8 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Fri, 28 Jun 2024 12:59:16 +0800 Subject: [PATCH 3/4] ci: remove curly braces --- .github/actions/vercel_DR_publish/action.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/actions/vercel_DR_publish/action.yml b/.github/actions/vercel_DR_publish/action.yml index e704316..fd9ea50 100644 --- a/.github/actions/vercel_DR_publish/action.yml +++ b/.github/actions/vercel_DR_publish/action.yml @@ -33,7 +33,7 @@ runs: VERCEL_TOKEN: ${{ inputs.VERCEL_TOKEN }} VERCEL_SCOPE: ${{ inputs.VERCEL_SCOPE }} run: | - vercel pull --yes --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} + vercel pull --yes --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE - name: Deploy to Vercel (Staging) env: @@ -41,12 +41,12 @@ runs: VERCEL_SCOPE: ${{ inputs.VERCEL_SCOPE }} ALIAS_DOMAIN_URL: ${{ inputs.ALIAS_DOMAIN_URL }} ENVIRONMENT: ${{ inputs.ENVIRONMENT }} - if: ${{ env.ENVIRONMENT == 'Staging' }} + if: $ENVIRONMENT == 'Staging' shell: bash run: | - vercel build --yes --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} - url="$(vercel deploy --prebuilt --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }})" - vercel alias "$url" ${{ env.ALIAS_DOMAIN_URL }} --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} + vercel build --yes --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE + url="$(vercel deploy --prebuilt --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE)" + vercel alias "$url" $ALIAS_DOMAIN_URL --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE - name: Deploy to Vercel (Production) env: @@ -54,9 +54,9 @@ runs: VERCEL_SCOPE: ${{ inputs.VERCEL_SCOPE }} ALIAS_DOMAIN_URL: ${{ inputs.ALIAS_DOMAIN_URL }} ENVIRONMENT: ${{ inputs.ENVIRONMENT }} - if: ${{ env.ENVIRONMENT == 'Production' }} + if: $ENVIRONMENT == 'Production' shell: bash run: | - vercel build --yes --prod --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} - url="$(vercel deploy --prod --prebuilt --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }})" - vercel alias "$url" ${{ env.ALIAS_DOMAIN_URL }} --token=${{ env.VERCEL_TOKEN }} --scope=${{ env.VERCEL_SCOPE }} + vercel build --yes --prod --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE + url="$(vercel deploy --prod --prebuilt --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE)" + vercel alias "$url" $ALIAS_DOMAIN_URL --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE From f8d2f92ea55ef6b3e0d0ba6a26bbe6eee3e65d7c Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Fri, 28 Jun 2024 13:01:46 +0800 Subject: [PATCH 4/4] ci: fix if condition --- .github/actions/vercel_DR_publish/action.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/actions/vercel_DR_publish/action.yml b/.github/actions/vercel_DR_publish/action.yml index fd9ea50..06dff71 100644 --- a/.github/actions/vercel_DR_publish/action.yml +++ b/.github/actions/vercel_DR_publish/action.yml @@ -40,8 +40,8 @@ runs: VERCEL_TOKEN: ${{ inputs.VERCEL_TOKEN }} VERCEL_SCOPE: ${{ inputs.VERCEL_SCOPE }} ALIAS_DOMAIN_URL: ${{ inputs.ALIAS_DOMAIN_URL }} - ENVIRONMENT: ${{ inputs.ENVIRONMENT }} - if: $ENVIRONMENT == 'Staging' + + if: ${{ inputs.ENVIRONMENT }} == 'Staging' shell: bash run: | vercel build --yes --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE @@ -53,8 +53,7 @@ runs: VERCEL_TOKEN: ${{ inputs.VERCEL_TOKEN }} VERCEL_SCOPE: ${{ inputs.VERCEL_SCOPE }} ALIAS_DOMAIN_URL: ${{ inputs.ALIAS_DOMAIN_URL }} - ENVIRONMENT: ${{ inputs.ENVIRONMENT }} - if: $ENVIRONMENT == 'Production' + if: ${{ inputs.ENVIRONMENT }} == 'Production' shell: bash run: | vercel build --yes --prod --token=$VERCEL_TOKEN --scope=$VERCEL_SCOPE