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

Migrate @kadena/docs to use Vercel CLI to deploy to preview environments. #2249

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
86679c5
Feat: Experiment with Vercel CLI to deploy apps
Ghislain89 Jun 7, 2024
d11e2f6
fix: add missing npx
Ghislain89 Jun 7, 2024
05e3764
add another missing npx
Ghislain89 Jun 7, 2024
4d186cd
pull env for docs
Ghislain89 Jun 7, 2024
7b3277b
remove npx
Ghislain89 Jun 7, 2024
aac29c7
fix: install vercel CLI first.
Ghislain89 Jun 7, 2024
1c01b76
link repo
Ghislain89 Jun 7, 2024
1341c7e
add token to link
Ghislain89 Jun 7, 2024
a5cdcb5
add scope
Ghislain89 Jun 7, 2024
ede75b6
add scope
Ghislain89 Jun 7, 2024
091e030
remove linking, should not be needed due to token
Ghislain89 Jun 7, 2024
54141f7
enable debugging
Ghislain89 Jun 7, 2024
81f51a0
remove --cwd
Ghislain89 Jun 7, 2024
a965e92
check if changed
Ghislain89 Jun 8, 2024
e008a66
fetch dept 0
Ghislain89 Jun 8, 2024
cfe0ba9
determine diff
Ghislain89 Jun 8, 2024
ca65369
remove explicit echo
Ghislain89 Jun 8, 2024
eab3f30
chore: formatting
Ghislain89 Jun 9, 2024
f49ade2
test turbo ignore script
Ghislain89 Jun 10, 2024
40844ef
should deploy now
Ghislain89 Jun 10, 2024
1d03218
formatting
Ghislain89 Jun 10, 2024
c0a56fd
add preview environment url to PR
Ghislain89 Jun 10, 2024
f8983ec
use Turbo ignore on the target branch
Ghislain89 Jun 10, 2024
9f5cd6b
fix setting the environment url
Ghislain89 Jun 10, 2024
f95259e
add environment url to PR
Ghislain89 Jun 10, 2024
40cd6fe
remove double tee.
Ghislain89 Jun 10, 2024
d79bf3a
Add name
Ghislain89 Jun 10, 2024
3ce105a
docs preview
Ghislain89 Jun 10, 2024
6b239a4
Make script executable
Ghislain89 Jun 10, 2024
1bd8282
Add delete-preview.yml
Ghislain89 Jun 10, 2024
fa66627
Update name for step
Ghislain89 Jun 10, 2024
91e97a4
Add PR number as metadata to deployment
Ghislain89 Jun 10, 2024
d492f62
filter pruneable deployments based on PR number
Ghislain89 Jun 10, 2024
e3753f3
add repo name to metadata
Ghislain89 Jun 10, 2024
96bfd2a
dont filter on project, this allows us to delete deployments for all …
Ghislain89 Jun 10, 2024
e414382
remove project id from delete job
Ghislain89 Jun 10, 2024
4a26835
convert to matrix build
Ghislain89 Jun 10, 2024
d7ec3b6
feat: make deployment a reusable workflow
Ghislain89 Jun 10, 2024
93a3eb7
explicitly pass secrets
Ghislain89 Jun 10, 2024
e2a0473
Try adding tools, how does this look
Ghislain89 Jun 10, 2024
63524ab
set up matrix
Ghislain89 Jun 10, 2024
d7e8d44
remove strategy from called workflow and fix caller workflow
Ghislain89 Jun 10, 2024
2d3da60
fix typo
Ghislain89 Jun 10, 2024
6bae711
enable debug building
Ghislain89 Jun 10, 2024
a9bc02d
Also deploy dev-wallet
Ghislain89 Jun 11, 2024
24be7d1
Disable automatic deployments by github vercel integration
Ghislain89 Jun 11, 2024
ce915a2
formatting
Ghislain89 Jun 11, 2024
507216c
attempt to split jobs
Ghislain89 Jun 11, 2024
ad28585
fix: lockfile
Ghislain89 Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/scripts/prune-deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# Set the pipefail option.
set -o pipefail

# Get the Vercel API endpoints.
GET_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v6/deployments"
DELETE_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v13/deployments"

# Create a list of deployments.
deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?teamId=$VERCEL_ORG_ID" -H "Authorization: Bearer $VERCEL_TOKEN ")

# Filter the deployments list by meta.pr_data === meta tag.
filtered_deployments=$(echo $deployments | jq --arg META_TAG "$META_TAG" '[.deployments[] | select(.meta.pr_data | type == "string" and contains($META_TAG)) | .uid] | join(",")')
filtered_deployments="${filtered_deployments//\"/}" # Remove double quotes

# Clears the values from filtered_deployments
IFS=',' read -ra values <<<"$filtered_deployments"

echo "META_TAG ${META_TAG}"
echo "Filtered deployments ${filtered_deployments}"

# Iterate over the filtered deployments list.
for uid in "${values[@]}"; do
echo "Deleting ${uid}"

delete_url=${DELETE_DEPLOYMENTS_ENDPOINT}/${uid}?teamId=${VERCEL_ORG_ID}
echo $delete_url

# Make DELETE a request to the /v13/deployments/{id} endpoint.
curl -X DELETE $delete_url -H "Authorization: Bearer $VERCEL_TOKEN"

echo "Deleted!"
done
31 changes: 31 additions & 0 deletions .github/workflows/delete-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

name: Remove deploy preview

permissions:
contents: read
statuses: write
pull-requests: write

env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}

on:
pull_request:
types:
- closed

jobs:
delete-deployments:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
show-progress: false

- name: Prune preview deployments associated with merged PR
env:
META_TAG: ${{ github.event.repository.name }}-${{ github.event.number }}
run: |
bash .github/scripts/prune-deployment.sh
100 changes: 100 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Deploy to Vercel Preview
on:
workflow_call:
# Introduced 'inputs' to define parameters that can be passed when calling this workflow
inputs:
app:
description: "App to Deploy"
required: true
type: string
secrets:
VERCEL_PROJECT_ID:
description: "Vercel Project ID"
required: true
VERCEL_ORG_ID:
description: "Vercel Organization ID"
required: true
VERCEL_TOKEN:
description: "Vercel Token"
required: true

env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}


jobs:
shouldDeploy:
name: ${{ inputs.app }}
if: ${{ github.repository_owner == 'kadena-community' }} // Prevents auto deploying forks.

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
show-progress: false

- name: Runner Setup
uses: ./.github/actions/runner-setup

- name: Detecting App Changes
id: detectChanges
run: |
echo "Detecting Changes"

# Enable Error Handling
set +e

npx turbo-ignore @kadena/${{ inputs.app }} -f origin/main
exit_code=$?

# Disable Error Handling
set -e

echo "exit_code: $exit_code"
if [ $exit_code -eq 0 ]; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
outputs:
changed: ${{ steps.detectChanges.outputs.changed }}
deploy:
name: ${{ inputs.app }}
needs: shouldDeploy
if: ${{ needs.shouldDeploy.outputs.changed == 'true' }}
environment:
name: ${{ inputs.app }} - Preview
url: ${{ steps.deployment.outputs.url }}

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
show-progress: false

- name: Runner Setup
uses: ./.github/actions/runner-setup

- name: Install Vercel CLI
if: steps.detectChanges.outputs.changed == 'true'
run: pnpm add --global vercel@34.2.5

- name: Pull environment variables
if: steps.detectChanges.outputs.changed == 'true'
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}

- name: Build App
if: steps.detectChanges.outputs.changed == 'true'
run: vercel build --token=${{ secrets.VERCEL_TOKEN }} --debug

- name: Deploy App
if: steps.detectChanges.outputs.changed == 'true'
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} --archive=tgz --meta pr_data=${{ github.event.repository.name }}-${{ github.event.number }} | tee deploy.log

- name: Set preview url
if: steps.detectChanges.outputs.changed == 'true'
id: deployment
run: echo "url=$(tail -1 deploy.log)">> $GITHUB_OUTPUT
23 changes: 23 additions & 0 deletions .github/workflows/vercel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Creating Preview environments
on:
pull_request:
jobs:
create-preview-env:
strategy:
fail-fast: false
matrix:
include:
- app: 'Docs'
projectToken: VERCEL_DOCS_ID
- app: 'Tools'
projectToken: VERCEL_TOOLS_ID
- app: 'dev-wallet'
projectToken: VERCEL_DEV_WALLET_ID
name: Preview Deployment
uses: ./.github/workflows/deploy-preview.yml
with:
app: ${{ matrix.app}}
secrets:
VERCEL_PROJECT_ID: ${{ secrets[matrix.projectToken] }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ temp
.cache-sh

# parcel
.parcel-cache
.parcel-cache
.vercel
2 changes: 2 additions & 0 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const ALLOWED_ROOT_DEPENDENCIES = [
'syncpack',
'tsx',
'turbo',
'vercel',
'turbo-ignore',
];

function readPackage(pkg, context) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"prettier-plugin-packagejson": "^2.4.6",
"syncpack": "^11.2.1",
"tsx": "^3.12.10",
"turbo": "^1.10.15"
"turbo": "^1.10.15",
"turbo-ignore": "^2.0.3",
"vercel": "34.2.5"
},
"engines": {
"node": ">=18 <21",
Expand Down
Loading
Loading