Skip to content

Deployments

Deployments #8

Workflow file for this run

name: Deployments
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy'
type: environment
required: true
jobs:
perpare-deployment:
environment: ${{ inputs.environment }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Prepare parameters
id: prepare_parameters
run: |
BASE=$(node -p "require('./packages/starknet-snap/package.json').version")
HASH=$(git rev-parse --short HEAD)
DATE=$(date +%Y%m%d)
ENV=${{ inputs.environment }}
if [[ $ENV == "dev" ]]; then
{
echo "VERSION=${BASE}-dev-${HASH}-${DATE}"
echo "TAG=dev"
echo "ENV=dev"
} >> "$GITHUB_OUTPUT"
elif [[ $ENV == "staging" ]]; then
{
echo "VERSION=${BASE}-staging"
echo "TAG=staging"
echo "ENV=staging"
} >> "$GITHUB_OUTPUT"
elif [[ $ENV == "production" ]]; then
{
echo "VERSION=${BASE}"
echo "TAG=latest"
echo "ENV=prod"
} >> "$GITHUB_OUTPUT"
else
echo "Invalid environment"
exit 1
fi
outputs:
VERSION: ${{ steps.prepare_parameters.outputs.VERSION }}
TAG: ${{ steps.prepare_parameters.outputs.TAG }}
ENV: ${{ steps.prepare_parameters.outputs.ENV }}
install-build:
needs:
- perpare-deployment
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Install
run: |
yarn install --no-immutable
- name: Build Snap
run: |
npm --prefix ./packages/starknet-snap version --new-version "$VERSION" --no-git-tag-version --allow-same-version
yarn workspace @consensys/starknet-snap build
BUILD_VERSION=$(node -p "require('./packages/starknet-snap/package.json').version")
if [[ "$VERSION" != "$BUILD_VERSION" ]]; then
echo "Version mismatch"
exit 1
fi
ls -al ./packages/starknet-snap/dist
env:
SNAP_ENV: ${{ needs.perpare-deployment.outputs.ENV }}
VERSION: ${{ needs.perpare-deployment.outputs.VERSION }}
VOYAGER_API_KEY: ${{ secrets.VOYAGER_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
- name: Build UI
run: |
REACT_APP_SNAP_VERSION="$VERSION" yarn workspace wallet-ui build
ls -al ./packages/starknet-snap/dist
env:
VERSION: ${{ needs.perpare-deployment.outputs.VERSION }}
- uses: actions/cache@v3
id: restore-build
with:
path: |
./packages/wallet-ui/build/*
./packages/starknet-snap/dist/*
./packages/starknet-snap/snap.manifest.json
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
publish-npm-dry-run:
runs-on: ubuntu-latest
needs:
- perpare-deployment
- install-build
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- uses: actions/cache@v3
id: restore-build
with:
# add /packages/snap/snap.manifest.json to include an updated shasum from build due to version update in auto PR
path: |
./packages/starknet-snap/dist/*
./packages/starknet-snap/snap.manifest.json
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Dry Run Publish
run: |
ls -al ./packages/starknet-snap/dist
npm pack ./packages/starknet-snap --tag "$TAG" --access public
env:
TAG: ${{ needs.perpare-deployment.outputs.TAG }}
publish-npm:
runs-on: ubuntu-latest
needs:
- publish-npm-dry-run
- perpare-deployment
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- uses: actions/cache@v3
id: restore-build
with:
# add /packages/snap/snap.manifest.json to include an updated shasum from build due to version update in auto PR
path: |
./packages/starknet-snap/dist/bundle.js
./packages/starknet-snap/snap.manifest.json
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Run Publish
run: |
npm pack ./packages/starknet-snap --tag "$TAG" --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
TAG: ${{ needs.perpare-deployment.outputs.TAG }}
deploy-wallet-ui:
runs-on: ubuntu-latest
needs:
- perpare-deployment
- publish-npm
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
- uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- uses: actions/cache@v3
id: restore-build
with:
path: |
./packages/wallet-ui/build/*
./node_modules/.yarn-state.yml
key: ${{ github.sha }}
- name: Deploy to AWS
run: |
echo "Deployed Dapp to : $AWS_S3_URL"
env:
AWS_S3_URL: ${{ secrets.AWS_S3_URL }}
- name: Invalid aws cloudfront cache
run: |
echo "Distribution ID : $AWS_CLOUDFRONT_DISTRIBUTIONS_ID"
echo "$AWS_CLOUDFRONT_DISTRIBUTIONS_ID" | tr ',' '\n' | while read -r DISTRIBUTIONS_ID
do
echo "Processing Distribution ID : $DISTRIBUTIONS_ID"
done
env:
AWS_CLOUDFRONT_DISTRIBUTIONS_ID: ${{ vars.AWS_CLOUDFRONT_DISTRIBUTIONS_ID }}
AWS_S3_URL: ${{ vars.AWS_S3_URL }}