Skip to content

Commit

Permalink
ci: text aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Apr 9, 2024
1 parent f2803b9 commit b89aab7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/next-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: |
Expand Down
23 changes: 23 additions & 0 deletions scripts/githubActions.mjs
Original file line number Diff line number Diff line change
@@ -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')
}

0 comments on commit b89aab7

Please sign in to comment.