ci: set custom mcraft aliases for PRs! (#99)
This commit is contained in:
parent
b89aab72d0
commit
ac3448c745
3 changed files with 19 additions and 8 deletions
5
.github/workflows/next-deploy.yml
vendored
5
.github/workflows/next-deploy.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
7
.github/workflows/preview.yml
vendored
7
.github/workflows/preview.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue