Skip to content

Commit

Permalink
feat: adds CDN deployments to gh pages (#1125)
Browse files Browse the repository at this point in the history
* feat: adds CDN deployments to gh pages

* feat: add versioning to the deploys

* feat: adds version cleanup to avoid bad pathing

* chore: renames cdn to static
  • Loading branch information
christopherferreira9 authored Nov 13, 2024
1 parent a954015 commit 744ab6d
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/deploy-cdn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy to CDN

on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to deploy'
required: true
default: ''

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.tag }}

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install Yarn 3
run: yarn set version 3.5.1

- name: Install Dependencies
run: yarn install --immutable

- name: Run deploy script
env:
tag: ${{ github.event.inputs.tag }}
run: bash ./scripts/deploy-cdn.sh

- name: Deploy dapps
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305
with:
personal_token: ${{ secrets.DEPLOY_TOKEN }}
# force_orphan: true # removing for now as it is incompatible with keep_files
keep_files: true # Important to keep the rest of the files deployed previously
publish_dir: ./deployments
43 changes: 43 additions & 0 deletions .github/workflows/deploy-static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy to CDN

on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to deploy'
required: true
default: ''

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.tag }}

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install Yarn 3
run: yarn set version 3.5.1

- name: Install Dependencies
run: yarn install --immutable

- name: Run deploy script
env:
tag: ${{ github.event.inputs.tag }}
run: bash ./scripts/deploy-static.sh

- name: Deploy dapps
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305
with:
personal_token: ${{ secrets.DEPLOY_TOKEN }}
# force_orphan: true # removing for now as it is incompatible with keep_files
keep_files: true # Important to keep the rest of the files deployed previously
publish_dir: ./deployments
41 changes: 41 additions & 0 deletions scripts/deploy-cdn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Stop on first error
set -e

# Make sure to start from base workspace folder
reldir="$( dirname -- "$0"; )";
cd "$reldir/..";

build_sdk() {
echo "\n---------- Building SDK -------------\n"
yarn build
echo "\n---------- Done building SDK -------------\n"
}

copy_to_deployment_dir() {
local deployment_dir=$1
echo "\n---------- Copying to deployment directory -------------\n"
cp -r packages/sdk/dist/browser/iife/metamask-sdk.js "$deployment_dir"
cp -r packages/sdk/dist/browser/iife/metamask-sdk.js.map "$deployment_dir"
echo "\n---------- Done copying to deployment directory -------------\n"
}

# ------ Start
deployment_folder="cdn"
gh_tag=$tag
gh_tag_version=$(echo "$gh_tag" | sed -E 's/@metamask\/sdk@([0-9]+\.[0-9]+\.[0-9]+).*/\1/')

# Sanitize tag version
deployment_dir="deployments/$deployment_folder/$gh_tag_version"

echo "Deployment folder: $deployment_folder"
echo "Deployment directory: $deployment_dir"

mkdir -p "$deployment_dir"

# Build SDK from root
build_sdk

# Copy to deployment directory
copy_to_deployment_dir "$deployment_dir"
41 changes: 41 additions & 0 deletions scripts/deploy-static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Stop on first error
set -e

# Make sure to start from base workspace folder
reldir="$( dirname -- "$0"; )";
cd "$reldir/..";

build_sdk() {
echo "\n---------- Building SDK -------------\n"
yarn build
echo "\n---------- Done building SDK -------------\n"
}

copy_to_deployment_dir() {
local deployment_dir=$1
echo "\n---------- Copying to deployment directory -------------\n"
cp -r packages/sdk/dist/browser/iife/metamask-sdk.js "$deployment_dir"
cp -r packages/sdk/dist/browser/iife/metamask-sdk.js.map "$deployment_dir"
echo "\n---------- Done copying to deployment directory -------------\n"
}

# ------ Start
deployment_folder="static"
gh_tag=$tag
gh_tag_version=$(echo "$gh_tag" | sed -E 's/@metamask\/sdk@([0-9]+\.[0-9]+\.[0-9]+).*/\1/')

# Sanitize tag version
deployment_dir="deployments/$deployment_folder/$gh_tag_version"

echo "Deployment folder: $deployment_folder"
echo "Deployment directory: $deployment_dir"

mkdir -p "$deployment_dir"

# Build SDK from root
build_sdk

# Copy to deployment directory
copy_to_deployment_dir "$deployment_dir"

0 comments on commit 744ab6d

Please sign in to comment.