Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:hop-protocol/hop into production
Browse files Browse the repository at this point in the history
  • Loading branch information
shanefontaine committed May 18, 2024
2 parents e4ec434 + 2038699 commit b59541d
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 144 deletions.
47 changes: 0 additions & 47 deletions .github/actions/check-version/action.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# @DEV: The cache hangs when using PNPM on certain local environments. Comment it out
# when running locally. You only lose the cacheing of pnpm install.
# https://github.com/actions/setup-node/issues/824

name: Setup
description: Common setup steps used by our workflows
runs:
Expand All @@ -18,4 +14,3 @@ runs:
with:
node-version-file: '.nvmrc'
registry-url: https://registry.npmjs.org
# cache: 'pnpm'
35 changes: 23 additions & 12 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish Packages to Docker Hub
on:
push:
branches:
- develop
- staging
- production
paths:
- 'packages/hop-node/**'
Expand All @@ -11,24 +11,26 @@ on:
- 'packages/explorer-backend/**'
- 'packages/stats-worker/**'
env:
DOCKER_TAG: ${{ (github.ref_name == 'develop' && 'unstable') || (github.ref_name == 'production' && 'latest') }}
DOCKER_TAG: ${{ (github.ref_name == 'production' && 'latest') || 'unstable' }}

jobs:
publishable-packages:
name: Check for package that can be published
uses: ./.github/workflows/publishable-packages.yml
with:
package-names: 'hop-node:v2-explorer-backend:api:explorer-backend:stats-worker'

publish-docker:
name: Publish Docker
needs: publishable-packages
runs-on: ubuntu-latest
strategy:
matrix:
package-name: ['hop-node', 'v2-explorer-backend', 'api', 'explorer-backend', 'stats-worker']
package-name: ${{ fromJson(needs.publishable-packages.outputs.publishable-packages) }}
steps:
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b

- name: Check versions
id: check-versions
uses: ./.github/actions/check-version
with:
package-name: ${{ matrix.package-name }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb

Expand All @@ -38,11 +40,20 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set Docker Tags
id: set-docker-tag
run: |
# Modify any discrepancies in the package name vs the image name
if [ "${{ matrix.package-name }}" == "api" ]; then
echo "IMAGE_NAME=hopprotocol/hop-api" >> $GITHUB_OUTPUT
else
echo "IMAGE_NAME=hopprotocol/${{ matrix.package-name }}" >> $GITHUB_OUTPUT
fi
- name: Publish Docker Image (${{ env.DOCKER_TAG }})
if: steps.check-versions.outputs.package-version-changed == 'true' || github.ref_name != 'production'
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
with:
context: .
file: ./packages/${{ matrix.package-name }}/Dockerfile
tags: hopprotocol/${{ matrix.package-name }}:${{ env.DOCKER_TAG }}
tags: ${{ steps.set-docker-tag.outputs.IMAGE_NAME }}:${{ env.DOCKER_TAG }}
push: true

28 changes: 18 additions & 10 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,38 @@ on:
- 'packages/sdk/**'

jobs:
publishable-packages:
name: Check for package that can be published
uses: ./.github/workflows/publishable-packages.yml
with:
package-names: 'sdk'

publish-sdk:
name: Publish NPM
needs: publishable-packages
runs-on: ubuntu-latest
environment: ${{ github.ref_name }}
strategy:
matrix:
package-name: ${{ fromJson(needs.publishable-packages.outputs.publishable-packages) }}
steps:
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b

- name: Setup workflow
uses: ./.github/actions/setup

- name: Check versions
id: check-versions
uses: ./.github/actions/check-version
- name: Check Package Updates
id: check-package-updates
uses: ./.github/actions/check-package-updates
with:
package-name: sdk
package-name: ${{ matrix.package-name }}

- name: Install and build package
if: steps.check-versions.outputs.package-version-changed == 'true'
run: |
pnpm --filter-prod sdk... install
pnpm --filter sdk... build
pnpm --filter-prod ${{ matrix.package-name }}... install
pnpm --filter ${{ matrix.package-name }}... build
- name: Publish package
if: steps.check-versions.outputs.package-version-changed == 'true'
run: pnpm --filter sdk publish --publish-branch production --access public
run: pnpm --filter ${{ matrix.package-name }} publish --publish-branch production --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
76 changes: 76 additions & 0 deletions .github/workflows/publishable-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# A publishable package is a package that has been modified and, if the
# if the branch is production, has a new version.

name: Get packages that should be published
on:
workflow_call:
inputs:
package-names:
description: 'Package names to consider, separated by commas.'
required: true
type: string
outputs:
publishable-packages:
description: 'Returns the name of all packages that should be published.'
value: ${{ jobs.publishable-packages.outputs.publishable-packages }}

jobs:
publishable-packages:
runs-on: ubuntu-latest
outputs:
publishable-packages: ${{ steps.publishable-packages.outputs.modified_packages }}
steps:
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b

- name: Get modified dirs
id: modified-dirs
uses: tj-actions/changed-files@a29e8b565651ce417abb5db7164b4a2ad8b6155c
with:
since_last_remote_commit: true
dir_names: true
dir_names_max_depth: 2
separator: ','
files: ${{ github.event.inputs.paths }}

- name: Get publishable packages
id: publishable-packages
run: |
# Extract changed directories from output, removing the 'package/' prefix
# Example: packages/hop-node,packages/v2-explorer-backend,packages/frontend
modified_dirs="${{ steps.modified-dirs.outputs.all_changed_files }}"
# Read input package names, compare with modified directories
# Example: packages/hop-node,packages/v2-explorer-backend
IFS=":"
read -a input_packages <<< "${{ inputs.package-names }}"
modified_packages=""

for package in "${input_packages[@]}"; do
package_path="packages/$package"

# Skip packages not modified
if [[ $modified_dirs != *"$package_path"* ]]; then
continue
fi

# On the production branch, publish only if there's a version change
if [ "${{ github.head_ref }}" == "production" ]; then
version_changed=$(git diff HEAD^ HEAD -- "${package_path}/package.json" | grep '"version":' || true)
if [ "$version_changed" ]; then
continue
fi
fi

modified_packages+="$package,"
done

# Strip the trailing comma
# Example: packages/hop-node,packages/v2-explorer-backend
modified_packages="${modified_packages%,}"

# Convert from string with commas to array for consumption by matrix
# Example: ["hop-node", "v2-explorer-backend"]
modified_packages=$(echo $modified_packages | tr ',' '\n' | sed 's/^ *//;s/ *$//' | jq -R -s -c 'split("\n")[:-1]')

echo "modified_packages=$modified_packages" >> $GITHUB_OUTPUT
35 changes: 18 additions & 17 deletions .github/workflows/ui-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,43 @@ name: Build and Deploy Frontend UIs
on:
push:
branches:
- develop
- staging
- production
paths:
- 'packages/frontend/**'

# TODO: DRY if statements

jobs:
publishable-packages:
name: Check for package that can be published
uses: ./.github/workflows/publishable-packages.yml
with:
package-names: 'frontend'

build-ui:
name: Build and Deploy UI
needs: publishable-packages
runs-on: ubuntu-latest
# If the frontend hasn't been modified, skip
if: ${{ fromJson(needs.publishable-packages.outputs.publishable-packages)[0] != null }}
environment: ${{ matrix.env-name }}
strategy:
matrix:
env-name: ['production','mainnet','sepolia']
package-name: ${{ fromJson(needs.publishable-packages.outputs.publishable-packages) }}
env-name:
- production
- mainnet
- sepolia
steps:
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b

- name: Setup workflow
uses: ./.github/actions/setup

- name: Check versions
id: check-versions
uses: ./.github/actions/check-version
with:
package-name: frontend

- name: Install package
if: steps.check-versions.outputs.package-version-changed == 'true' || matrix.env-name != 'production'
run: pnpm --filter-prod frontend... install

- name: Build the app
if: steps.check-versions.outputs.package-version-changed == 'true' || matrix.env-name != 'production'
env:
REACT_APP_NETWORK: ${{ vars.REACT_APP_NETWORK }}
REACT_APP_ENABLED_CHAINS: ${{ vars.REACT_APP_ENABLED_CHAINS }}
Expand All @@ -48,15 +52,13 @@ jobs:
run: pnpm --filter frontend... build

- name: Write commit file
if: steps.check-versions.outputs.package-version-changed == 'true' || matrix.env-name != 'production'
uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42
with:
path: packages/frontend/dist/cachebust
write-mode: overwrite
contents: ${{ github.sha }}

- name: Pin to IPFS on Pinata
if: steps.check-versions.outputs.package-version-changed == 'true' || matrix.env-name != 'production'
id: upload
uses: anantaramdas/ipfs-pinata-deploy-action@9f9c3b42b5d360352c4b768d98aff1309d62faa0
with:
Expand All @@ -66,7 +68,6 @@ jobs:
pinata-secret-api-key: ${{ secrets.IPFS_DEPLOY_PINATA__SECRET_API_KEY }}

- name: Update CloudFlare DNS with new IPFS hash
if: steps.check-versions.outputs.package-version-changed == 'true' || matrix.env-name != 'production'
env:
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
RECORD_DOMAIN: 'hop.exchange'
Expand All @@ -77,14 +78,14 @@ jobs:
cid: ${{ steps.upload.outputs.hash }}

- name: Convert CIDv0 to CIDv1
if: steps.check-versions.outputs.package-version-changed == 'true' || matrix.env-name != 'production'
id: convert_cidv0
uses: uniswap/convert-cidv0-cidv1@c53a468c3602a85dd979c02ec4ddd9102849395e
with:
cidv0: ${{ steps.upload.outputs.hash }}

- name: Create GitHub Release
if: steps.check-versions.outputs.package-version-changed == 'true' || matrix.env-name != 'production'
# Only create a release on the production branch
if: matrix.env-name == 'production'
env:
CIDv0: ${{ steps.upload.outputs.hash }}
CIDv1: ${{ steps.convert_cidv0.outputs.cidv1 }}
Expand Down
3 changes: 3 additions & 0 deletions ops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ops

Various operational packages
17 changes: 17 additions & 0 deletions ops/webhooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Webhooks

Set up a webhook to auto-restart Docker processes on a server. The default script looks for the successful completion of a GitHub workflow that publishes a new Docker image with the `latest` tag.

# Instructions

### On GitHub

Set up a webhook [on GitHub](https://github.com/hop-protocol/hop/settings/hooks) to send a request to a webhook server.

### On the server

Ensure port `4665` can accept incoming requests.

- Set the `DOCKER_IMAGE_NAME` and `WEBHOOK_SECRET` envs in `~/.bashrc` and source it.
- Add the scripts in this repo to the server.
- Run the webhook server in the background with `./run_webhook_server.sh &`
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

/usr/local/bin/gws -port=4665 -method=POST -path=/postreceive -secret=$WEBHOOK_SECRET -command=$(pwd)/circleci_webhook_postreceive.sh
/usr/local/bin/gws -port=4665 -method=POST -path=/postreceive -secret=$WEBHOOK_SECRET -command=$(pwd)/webhook_postreceive.sh
File renamed without changes.
Loading

0 comments on commit b59541d

Please sign in to comment.