Skip to content

Commit

Permalink
Add Release Flow
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hayesgm committed Mar 16, 2024
1 parent cc25771 commit 140d5a8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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
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"
bodyFile: "release/RELEASE.md"
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: test

on: workflow_dispatch
on:
push:

env:
FOUNDRY_PROFILE: ci
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Compiler files
cache/
out/
release/

# Ignores development broadcast logs
!/broadcast
Expand Down
22 changes: 18 additions & 4 deletions script/Sleuth.s.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
51 changes: 51 additions & 0 deletions script/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
## $title
Sleuth Address: $sleuth_address
$body
EOF

0 comments on commit 140d5a8

Please sign in to comment.