From 0663c391afb2c201649bb340487b1fb601721a97 Mon Sep 17 00:00:00 2001 From: Geoffrey Hayes Date: Sat, 16 Mar 2024 06:08:45 -0700 Subject: [PATCH] Add Release Flow This patch adds a release flow that let's us build releases and then deploy them separately. Since deploys are deterministic, this "release first, deploy later" flow should be quite appealing. e.g. it means you can always redeploy older releases to new chains, etc. --- .github/workflows/release.yml | 44 ++++++++++++++++++++++++++++++ .github/workflows/test.yml | 3 ++- .gitignore | 1 + script/Sleuth.s.sol | 22 ++++++++++++--- script/prepare-release.sh | 51 +++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 script/prepare-release.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fa33b52 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,44 @@ +name: Prepare Release + +on: + - workflow_dispatch + - push + +env: + FOUNDRY_PROFILE: ci + +permissions: + contents: write + +jobs: + check: + strategy: + fail-fast: true + + name: Foundry project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Run Forge build + run: | + forge build + + - name: Prepare Release + run: | + script/prepare-release.sh + with: + CODE_JAR: ${{ secrets.CODE_JAR }} + RPC_URL: ${{ secrets.SEPOLIA_RPC_URL }} + + - uses: ncipollo/release-action@v1 + with: + artifacts: "release/Sleuth.json,release/Sleuth.sol" + bodyFile: "release/RELEASE.md" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09880b1..2c8600a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,7 @@ name: test -on: workflow_dispatch +on: + push: env: FOUNDRY_PROFILE: ci diff --git a/.gitignore b/.gitignore index 88a580b..8898035 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Compiler files cache/ out/ +release/ # Ignores development broadcast logs !/broadcast diff --git a/script/Sleuth.s.sol b/script/Sleuth.s.sol index 202f6a9..ac42998 100644 --- a/script/Sleuth.s.sol +++ b/script/Sleuth.s.sol @@ -1,12 +1,26 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; +pragma solidity ^0.8.23; import "forge-std/Script.sol"; +import "../src/Sleuth.sol"; -contract SleuthScript is Script { +interface CodeJar { + function saveCode(bytes memory code) external returns (address); +} + +contract Prepare is Script { function setUp() public {} - function run() public { - vm.broadcast(); + function run() public returns (address) { + CodeJar codeJar = CodeJar(vm.envAddress("CODE_JAR")); + console.log("Code Jar Address:", address(codeJar)); + console.log("Chain ID:", block.chainid); + console.logBytes(address(codeJar).code); + + address sleuthAddress = codeJar.saveCode(type(Sleuth).creationCode); + + console.log("Sleuth Address:", sleuthAddress); + + return sleuthAddress; } } diff --git a/script/prepare-release.sh b/script/prepare-release.sh new file mode 100755 index 0000000..085820c --- /dev/null +++ b/script/prepare-release.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -eo pipefail + +if [ -z "$CODE_JAR" ]; then + echo "Missing CODE_JAR env var" + exit 1 +fi + +if [ -z "$RPC_URL" ]; then + echo "Missing RPC_URL env var" + exit 1 +fi + +if ! command -v jq &> /dev/null; then + echo "jq could not be found" + exit 1 +fi + +forge build +mkdir -p release/ +cp out/Sleuth.sol/Sleuth.json release/ +cp src/Sleuth.sol release/ +title="$(git log -1 --pretty="%s")" +body="$(git log -1 --pretty="%b")" + +if [ -z "$title" ]; then + echo "must include git commit title" + exit 1 +fi + +if [ -z "$body" ]; then + echo "must include git commit body" + exit 1 +fi + +sleuth_address="$(forge script --rpc-url="$RPC_URL" --json --silent script/Sleuth.s.sol:Prepare | tee | jq -r '.returns."0".value')" + +echo "title=$title" +echo "body=$body" +echo "sleuth_address=$sleuth_address" + +echo "$sleuth_address" > "release/sleuth@$sleuth_address" + +cat > release/RELEASE.md <