-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automate Vercel alias #2658
base: main
Are you sure you want to change the base?
Automate Vercel alias #2658
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
14eb9c7
to
30d9249
Compare
30d9249
to
ef81c32
Compare
6dd219f
to
f034d0c
Compare
f034d0c
to
d8225bd
Compare
a2e092f
to
2541d3e
Compare
- name: Extract Current Version | ||
id: extract_version | ||
run: echo "VERSION=$(jq -r .version packages/components/package.json | sed 's/\./-/g')" >> $GITHUB_ENV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grab the version from package.json
and change format from dot-separator to dash-separator (e.g. 4.15.0
becomes 4-15-0
)
- name: Get Latest Vercel Deployment | ||
id: get_vercel_deployment | ||
run: | | ||
DEPLOYMENT_ID=$(curl -s -H "Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}" \ | ||
"https://api.vercel.com/v6/deployments?teamId=${{ secrets.VERCEL_TEAM_ID }}&projectId=${{ secrets.VERCEL_WEBSITE_PROJECT_ID }}" \ | ||
| jq -r --arg branch "${{ github.head_ref }}" '.deployments[] | select(.meta.githubCommitRef == $branch) | .uid' | head -n 1) | ||
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_ENV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get the latest deployment id for the current branch (the branch on which the workflow is run) using Vercel's REST API.
- name: Alias Vercel Deployment | ||
id: alias_vercel_deployment | ||
run: | | ||
curl -X POST "https://api.vercel.com/v2/deployments/${{ env.DEPLOYMENT_ID }}/aliases?slug=hashicorp&teamId=${{ secrets.VERCEL_TEAM_ID }}" \ | ||
-H "Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{\"alias\": \"hds-website-${{ env.VERSION }}.vercel.app\", \"teamId\": \"${{ secrets.VERCEL_TEAM_ID }}\", \"slug\": \"hashicorp\"}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create the alias for the latest deployment on the current branch. Note that the alias can only be created if the latest deployment is completed. If not completed, this step will fail and you'd need to re-run the action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! The test looks like it worked from the log.
I like the idea of having it run after each update to changeset-release/main
to keep things automated. My one thought is we may have to be careful about the order of how we merge in docs updates.
There could be a situation where a feature gets merged to main
and then the alias would get updated, but new docs are held off from being merged until closer to the release. Then when the docs branch gets merged the alias wouldn't automatically get updated because the docs branches don't cause updates to changeset-release/main
.
📌 Summary
GitHub Action to automate the creation of an alias link.
🛠️ Detailed description
This Action can be dispatched manually on the
changeset-release/main
branch right before merging theVersion Packages
PR, or on themain
branch after merging theVersion Packages
PR.It takes the latest Vercel deployment of a the branch it's being run on and creates an
hds-website-[version].vercel.app
alias, where[version]
follows themajor-minor-patch
format (e.g.hds-website-4-16-0.vercel.app
).If this PR gets merged the Release Procedure docs will be updated.
Testing
Was tested the Action in this PR, successfully generating the
https://hds-website-4-15-0-test.vercel.app
alias as instructed in 663943d. Note that we used a-test
suffix for testing purposes.In 2541d3e we moved the script as a standalone dispatched workflow and adjusted the alias format.
Future improvements
If we're satisfied with how this script performs we can automatically dispatch it on pushes to
changeset-release/main
. This will result in multiple deployments having the same alias, but according to Vercel's docs, the latest aliased deployment should be the one responding when the alias URL is invoked. The main challenge here is to wait for the latest deployment to complete before attempting to alias it.🔗 External links
Jira ticket: HDS-4300
💬 Please consider using conventional comments when reviewing this PR.