Skip to content

Commit

Permalink
ci: set custom mcraft aliases for PRs! (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Apr 9, 2024
1 parent b89aab7 commit ac3448c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/next-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
15 changes: 12 additions & 3 deletions scripts/githubActions.mjs
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit ac3448c

Please sign in to comment.