diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..77edefc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: Prepare Release + +on: + push: + tags: + - '*' + +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 + env: + CODE_JAR: ${{ vars.CODE_JAR }} + RPC_URL: ${{ vars.SEPOLIA_RPC_URL }} + + - uses: ncipollo/release-action@v1 + with: + ref: "${{ github.sha }}" + artifacts: "release/Sleuth.json,release/Sleuth.sol,release/sleuth@*" + bodyFile: "release/RELEASE.md" + allowUpdates: true 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 <