diff --git a/.github/workflows/next-deploy.yml b/.github/workflows/next-deploy.yml index 93c46aebc..d7d4d322e 100644 --- a/.github/workflows/next-deploy.yml +++ b/.github/workflows/next-deploy.yml @@ -2,6 +2,7 @@ name: Vercel Deploy Next env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + ALIASES: ${{ vars.ALIASES }} on: push: branches: @@ -30,8 +31,13 @@ jobs: with: run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} id: deploy + - name: Get deployment alias + run: node scripts/githubActions.mjs getAlias + - run: echo $OUTPUT + env: + OUTPUT: ${{ steps.repos.outputs.alias }} - name: Set deployment alias - run: vercel alias set ${{ steps.deploy.outputs.stdout }} ${{ secrets.TEST_PREVIEW_DOMAIN }} --token=${{ secrets.VERCEL_TOKEN }} + run: vercel alias set ${{ steps.deploy.outputs.stdout }} ${{ secrets.TEST_PREVIEW_DOMAIN }} --token=${{ secrets.VERCEL_TOKEN }} --scope=zaro # - uses: mshick/add-pr-comment@v2 # with: # message: | diff --git a/scripts/githubActions.mjs b/scripts/githubActions.mjs new file mode 100644 index 000000000..f392da559 --- /dev/null +++ b/scripts/githubActions.mjs @@ -0,0 +1,23 @@ +const fns = { + async getAlias () { + const aliasesRaw = process.env.ALIASES + if (!aliasesRaw) throw new Error('No aliases found') + const aliases = aliasesRaw.split('\n').map((x) => x.search('=')) + const githubActionsPull = process.env.GITHUB_REF.match(/refs\/pull\/(\d+)\/merge/) + if (!githubActionsPull) throw new Error(`Not a pull request, got ${process.env.GITHUB_REF}`) + const prNumber = githubActionsPull[1] + const alias = aliases.find((x) => x[0] === prNumber) + if (alias) { + console.log('Found alias', alias[1]) + // set github output + console.log(`::set-output name=alias::${alias[1]}`) + } + } +} + +const fn = fns[process.argv[2]] +if (fn) { + fn() +} else { + console.error('Function not found') +}