#!/usr/bin/env bash set -euo pipefail itemuid="${GITHUB_DEPLOY_ITEMUID:-pvct2lcpjspsvgwbh2wk3riq3m}" usage() { cat <&2 exit 1 fi if [[ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]]; then echo "ERROR: Please run this script from the 'main' branch" 1>&2 exit 1 fi if [[ -n "$(git status --porcelain)" ]]; then echo "ERROR: Dirty Git index, please commit all changes before continuing" 1>&2 exit 1 fi if ! command -v gh &> /dev/null; then echo "ERROR: Please install the 'gh' GitHub CLI" 1>&2 exit 1 fi issue=0 case $# in 0) gh issue list --label ready-to-deploy \ --json number,title,closedByPullRequestsReferences \ --jq '.[] | .pr = (.closedByPullRequestsReferences.[0].number | if (.) then " {✓ #\(.)}" else "" end) | "• #\(.number): \(.title)\(.pr)"' exit 0 ;; 1) if ! [[ $1 =~ ^[0-9]+$ ]]; then echo "ERROR: $1 is not a valid GitHub issue number" 1>&2 usage exit 1 fi issue=$1 ;; *) usage exit 1 ;; esac echo "### Fetching RPC URL" rpc="$(gh issue view $issue | grep -E -o 'https?://[^ ]+' -m 1 | head -1)" echo "=> $rpc" echo "### Building Deployment Transaction" RPC="$rpc" npm run -s estimate-compile commit=1 if [[ -n "$(git status --untracked-files=no --porcelain -- artifacts/)" ]]; then echo "WARN: Modified an existing deployment" 1>&2 commit=0 fi echo "### Submitting Transaction" if [[ $commit -eq 1 ]]; then RPC="$rpc" npm run -s submit else echo "WARN: Cannot automatically submit, to manually submit run:" 1>&2 echo " RPC='$rpc' npm run submit" 1>&2 fi echo "### Creating PR" git checkout -b "$issue-github-deployment" git add artifacts/ git commit -m "$(cat <&2 fi