Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Automate Vercel alias #2658

wants to merge 2 commits into from

Conversation

alex-ju
Copy link
Member

@alex-ju alex-ju commented Jan 21, 2025

📌 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 the Version Packages PR, or on the main branch after merging the Version 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 the major-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.

Copy link

vercel bot commented Jan 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
hds-showcase ✅ Ready (Inspect) Visit Preview Jan 21, 2025 8:27pm
hds-website ✅ Ready (Inspect) Visit Preview Jan 21, 2025 8:27pm

@alex-ju alex-ju force-pushed the alex-ju/automate-vercel-alias branch from 14eb9c7 to 30d9249 Compare January 21, 2025 18:20
@alex-ju alex-ju force-pushed the alex-ju/automate-vercel-alias branch from 30d9249 to ef81c32 Compare January 21, 2025 18:26
@alex-ju alex-ju force-pushed the alex-ju/automate-vercel-alias branch from 6dd219f to f034d0c Compare January 21, 2025 19:05
@alex-ju alex-ju force-pushed the alex-ju/automate-vercel-alias branch from f034d0c to d8225bd Compare January 21, 2025 19:13
Comment on lines +16 to +18
- name: Extract Current Version
id: extract_version
run: echo "VERSION=$(jq -r .version packages/components/package.json | sed 's/\./-/g')" >> $GITHUB_ENV
Copy link
Member Author

@alex-ju alex-ju Jan 22, 2025

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)

Comment on lines +19 to +25
- 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
Copy link
Member Author

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.

Comment on lines +26 to +32
- 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\"}"
Copy link
Member Author

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.

@alex-ju alex-ju marked this pull request as ready for review January 22, 2025 10:00
@alex-ju alex-ju requested a review from a team as a code owner January 22, 2025 10:00
Copy link
Contributor

@dchyun dchyun left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants