From ac3448c74502e6e23c357c1614bc81dab3beb354 Mon Sep 17 00:00:00 2001 From: Vitaly Date: Tue, 9 Apr 2024 03:47:03 +0300 Subject: [PATCH] ci: set custom mcraft aliases for PRs! (#99) --- .github/workflows/next-deploy.yml | 5 ----- .github/workflows/preview.yml | 7 +++++++ scripts/githubActions.mjs | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/next-deploy.yml b/.github/workflows/next-deploy.yml index d7d4d322..7ee33ac0 100644 --- a/.github/workflows/next-deploy.yml +++ b/.github/workflows/next-deploy.yml @@ -31,11 +31,6 @@ 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 }} --scope=zaro # - uses: mshick/add-pr-comment@v2 diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 02598446..44c55480 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -2,6 +2,7 @@ name: Vercel Deploy Preview env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + ALIASES: ${{ vars.ALIASES }} on: issue_comment: types: [created] @@ -48,3 +49,9 @@ jobs: Deployed to Vercel Preview: ${{ steps.deploy.outputs.stdout }} [Playground](${{ steps.deploy.outputs.stdout }}/playground.html) [Storybook](${{ steps.deploy.outputs.stdout }}/storybook/) + - name: Get deployment alias + run: node scripts/githubActions.mjs getAlias + id: alias + - name: Set deployment alias + if: ${{ steps.alias.outputs.alias != '' }} + run: vercel alias set ${{ steps.deploy.outputs.stdout }} ${{ steps.alias.outputs.alias }} --token=${{ secrets.VERCEL_TOKEN }} --scope=zaro diff --git a/scripts/githubActions.mjs b/scripts/githubActions.mjs index f392da55..ac218f56 100644 --- a/scripts/githubActions.mjs +++ b/scripts/githubActions.mjs @@ -1,20 +1,29 @@ +//@ts-check +import fs from 'fs' +import os from 'os' + 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 aliases = aliasesRaw.split('\n').map((x) => x.split('=')) 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]}`) + setOutput('alias', alias[1]) } } } +function setOutput(key, value) { + // Temporary hack until core actions library catches up with github new recommendations + const output = process.env['GITHUB_OUTPUT'] + fs.appendFileSync(output, `${key}=${value}${os.EOL}`) +} + const fn = fns[process.argv[2]] if (fn) { fn()