Skip to content

Commit 826b6bf

Browse files
committed
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.
1 parent cc25771 commit 826b6bf

File tree

5 files changed

+118
-5
lines changed

5 files changed

+118
-5
lines changed

.github/workflows/release.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Prepare Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
env:
9+
FOUNDRY_PROFILE: ci
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
check:
16+
strategy:
17+
fail-fast: true
18+
19+
name: Foundry project
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
submodules: recursive
25+
26+
- name: Install Foundry
27+
uses: foundry-rs/foundry-toolchain@v1
28+
with:
29+
version: nightly
30+
31+
- name: Run Forge build
32+
run: |
33+
forge build
34+
35+
- name: Prepare Release
36+
run: |
37+
script/prepare-release.sh
38+
env:
39+
CODE_JAR: ${{ vars.CODE_JAR }}
40+
RPC_URL: ${{ vars.SEPOLIA_RPC_URL }}
41+
42+
- uses: ncipollo/release-action@v1
43+
with:
44+
ref: "${{ github.sha }}"
45+
artifacts: "release/Sleuth.json,release/Sleuth.sol,release/sleuth@*"
46+
bodyFile: "release/RELEASE.md"

.github/workflows/test.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: test
22

3-
on: workflow_dispatch
3+
on:
4+
push:
45

56
env:
67
FOUNDRY_PROFILE: ci

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Compiler files
22
cache/
33
out/
4+
release/
45

56
# Ignores development broadcast logs
67
!/broadcast

script/Sleuth.s.sol

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity ^0.8.13;
2+
pragma solidity ^0.8.23;
33

44
import "forge-std/Script.sol";
5+
import "../src/Sleuth.sol";
56

6-
contract SleuthScript is Script {
7+
interface CodeJar {
8+
function saveCode(bytes memory code) external returns (address);
9+
}
10+
11+
contract Prepare is Script {
712
function setUp() public {}
813

9-
function run() public {
10-
vm.broadcast();
14+
function run() public returns (address) {
15+
CodeJar codeJar = CodeJar(vm.envAddress("CODE_JAR"));
16+
console.log("Code Jar Address:", address(codeJar));
17+
console.log("Chain ID:", block.chainid);
18+
console.logBytes(address(codeJar).code);
19+
20+
address sleuthAddress = codeJar.saveCode(type(Sleuth).creationCode);
21+
22+
console.log("Sleuth Address:", sleuthAddress);
23+
24+
return sleuthAddress;
1125
}
1226
}

script/prepare-release.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
if [ -z "$CODE_JAR" ]; then
6+
echo "Missing CODE_JAR env var"
7+
exit 1
8+
fi
9+
10+
if [ -z "$RPC_URL" ]; then
11+
echo "Missing RPC_URL env var"
12+
exit 1
13+
fi
14+
15+
if ! command -v jq &> /dev/null; then
16+
echo "jq could not be found"
17+
exit 1
18+
fi
19+
20+
forge build
21+
mkdir -p release/
22+
cp out/Sleuth.sol/Sleuth.json release/
23+
cp src/Sleuth.sol release/
24+
title="$(git log -1 --pretty="%s")"
25+
body="$(git log -1 --pretty="%b")"
26+
27+
if [ -z "$title" ]; then
28+
echo "must include git commit title"
29+
exit 1
30+
fi
31+
32+
if [ -z "$body" ]; then
33+
echo "must include git commit body"
34+
exit 1
35+
fi
36+
37+
sleuth_address="$(forge script --rpc-url="$RPC_URL" --json --silent script/Sleuth.s.sol:Prepare | tee | jq -r '.returns."0".value')"
38+
39+
echo "title=$title"
40+
echo "body=$body"
41+
echo "sleuth_address=$sleuth_address"
42+
43+
echo "$sleuth_address" > "release/sleuth@$sleuth_address"
44+
45+
cat > release/RELEASE.md <<EOF
46+
## $title
47+
48+
Sleuth Address: $sleuth_address
49+
50+
$body
51+
EOF

0 commit comments

Comments
 (0)