Skip to content

Instantly share code, notes, and snippets.

@davedash
Created March 15, 2021 05:45
Show Gist options
  • Save davedash/5a901e778a56ec54382ee47fc7f233a4 to your computer and use it in GitHub Desktop.
Save davedash/5a901e778a56ec54382ee47fc7f233a4 to your computer and use it in GitHub Desktop.
Vercel Alias Github Action
name: Vercel Alias
on: [deployment_status]
jobs:
alias:
if: |
github.event.deployment_status.state == 'success' &&
endsWith( github.event.deployment_status.target_url, '.vercel.app')
runs-on: ubuntu-latest
steps:
- uses: octokit/request-action@v2.x
name: Find Author
id: get_author
with:
route: GET /repos/${{ github.repository }}/commits/${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: emregency/vercel-preview-alias@v1.5
name: Make Alias
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
vercel-preview-url: ${{ github.event.deployment_status.target_url }} #Required
vercel-target-url: ${{ fromJson(steps.get_author.outputs.data).author.login }}.myapp.dev #Required
vercel-scope: ${{ secrets.VERCEL_TEAM_ID }} #Optional
- uses: octokit/request-action@v2.x
name: Create Deployment
id: deployment
with:
route: POST /repos/${{ github.repository }}/deployments
ref: ${{ github.sha }}
environment: Preview
auto_merge: false
description: Deploy to ${{ fromJson(steps.get_author.outputs.data).author.login }}.myapp.dev
required_contexts: '[]'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: octokit/request-action@v2.x
name: Set Deployment Status
id: deployment_status
with:
route: POST /repos/${{ github.repository }}/deployments/${{ fromJSON(steps.deployment.outputs.data).id }}/statuses
state: success
target_url: https://${{ fromJson(steps.get_author.outputs.data).author.login }}.myapp.dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment