Skip to content

Commit ed37ded

Browse files
committed
chore: add new rust release flow
fix ci
1 parent 5211994 commit ed37ded

5 files changed

Lines changed: 450 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Release PR Validation
2+
3+
permissions:
4+
contents: read
5+
issues: write
6+
7+
on:
8+
pull_request:
9+
types: [opened, synchronize, reopened]
10+
branches:
11+
- main
12+
13+
jobs:
14+
validate-release:
15+
# Only run on release PRs
16+
if: contains(github.event.pull_request.labels.*.name, 'release')
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Rust
24+
uses: actions-rust-lang/setup-rust-toolchain@v1
25+
with:
26+
toolchain: stable
27+
28+
- name: Detect release type
29+
id: detect_type
30+
env:
31+
BRANCH_NAME: ${{ github.head_ref }}
32+
run: |
33+
if [[ "$BRANCH_NAME" == release/program-libs-* ]]; then
34+
echo "type=program-libs" >> "$GITHUB_OUTPUT"
35+
elif [[ "$BRANCH_NAME" == release/sdk-libs-* ]]; then
36+
echo "type=sdk-libs" >> "$GITHUB_OUTPUT"
37+
else
38+
echo "type=unknown" >> "$GITHUB_OUTPUT"
39+
fi
40+
41+
- name: Dry-run publish (program-libs)
42+
if: steps.detect_type.outputs.type == 'program-libs'
43+
run: |
44+
PROGRAM_LIBS=(
45+
"light-account-checks" "aligned-sized" "light-batched-merkle-tree"
46+
"light-bloom-filter" "light-compressed-account" "light-concurrent-merkle-tree"
47+
"light-hash-set" "light-hasher" "light-heap" "light-indexed-array"
48+
"light-indexed-merkle-tree" "light-macros" "light-merkle-tree-metadata"
49+
"light-verifier" "light-zero-copy-derive" "light-zero-copy"
50+
)
51+
52+
PACKAGE_ARGS=()
53+
for pkg in "${PROGRAM_LIBS[@]}"; do
54+
PACKAGE_ARGS+=("-p" "$pkg")
55+
done
56+
57+
echo "Running dry-run publish for program-libs..."
58+
cargo publish --dry-run "${PACKAGE_ARGS[@]}"
59+
60+
- name: Dry-run publish (sdk-libs)
61+
if: steps.detect_type.outputs.type == 'sdk-libs'
62+
run: |
63+
SDK_LIBS=(
64+
"light-sdk-macros" "light-sdk-types" "light-sdk-pinocchio"
65+
"light-sdk" "light-client" "photon-api" "light-program-test"
66+
)
67+
68+
PACKAGE_ARGS=()
69+
for pkg in "${SDK_LIBS[@]}"; do
70+
PACKAGE_ARGS+=("-p" "$pkg")
71+
done
72+
73+
echo "Running dry-run publish for sdk-libs..."
74+
cargo publish --dry-run "${PACKAGE_ARGS[@]}"
75+
76+
- name: Comment PR with validation result
77+
if: success()
78+
uses: actions/github-script@v7
79+
with:
80+
script: |
81+
github.rest.issues.createComment({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
issue_number: context.issue.number,
85+
body: '✅ **Release validation passed!**\n\nDry-run publish completed successfully. This PR is ready to merge.'
86+
});
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Publish Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
jobs:
10+
publish-release:
11+
# Only run on merged release PRs
12+
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Set up Rust
25+
uses: actions-rust-lang/setup-rust-toolchain@v1
26+
with:
27+
toolchain: stable
28+
29+
- name: Install cargo-release
30+
run: cargo install cargo-release
31+
32+
- name: Configure git
33+
run: |
34+
git config user.name "github-actions[bot]"
35+
git config user.email "github-actions[bot]@users.noreply.github.com"
36+
37+
- name: Detect release type from PR
38+
id: detect_type
39+
env:
40+
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
41+
run: |
42+
if [[ "$PR_BRANCH" == release/program-libs-* ]]; then
43+
echo "type=program-libs" >> "$GITHUB_OUTPUT"
44+
elif [[ "$PR_BRANCH" == release/sdk-libs-* ]]; then
45+
echo "type=sdk-libs" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "type=unknown" >> "$GITHUB_OUTPUT"
48+
echo "Error: Could not detect release type from branch: $PR_BRANCH"
49+
exit 1
50+
fi
51+
52+
- name: Get tags before publish
53+
id: tags_before
54+
run: |
55+
git fetch --tags
56+
git tag | sort > /tmp/tags_before.txt
57+
cat /tmp/tags_before.txt
58+
59+
- name: Publish to crates.io (program-libs)
60+
if: steps.detect_type.outputs.type == 'program-libs'
61+
env:
62+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
63+
run: |
64+
PROGRAM_LIBS=(
65+
"light-account-checks" "aligned-sized" "light-batched-merkle-tree"
66+
"light-bloom-filter" "light-compressed-account" "light-concurrent-merkle-tree"
67+
"light-hash-set" "light-hasher" "light-heap" "light-indexed-array"
68+
"light-indexed-merkle-tree" "light-macros" "light-merkle-tree-metadata"
69+
"light-verifier" "light-zero-copy-derive" "light-zero-copy"
70+
)
71+
72+
PACKAGE_ARGS=()
73+
for pkg in "${PROGRAM_LIBS[@]}"; do
74+
PACKAGE_ARGS+=("-p" "$pkg")
75+
done
76+
77+
echo "Publishing program-libs to crates.io and creating tags..."
78+
cargo release publish "${PACKAGE_ARGS[@]}" --execute --no-confirm
79+
80+
- name: Publish to crates.io (sdk-libs)
81+
if: steps.detect_type.outputs.type == 'sdk-libs'
82+
env:
83+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
84+
run: |
85+
SDK_LIBS=(
86+
"light-sdk-macros" "light-sdk-types" "light-sdk-pinocchio"
87+
"light-sdk" "light-client" "photon-api" "light-program-test"
88+
)
89+
90+
PACKAGE_ARGS=()
91+
for pkg in "${SDK_LIBS[@]}"; do
92+
PACKAGE_ARGS+=("-p" "$pkg")
93+
done
94+
95+
echo "Publishing sdk-libs to crates.io and creating tags..."
96+
cargo release publish "${PACKAGE_ARGS[@]}" --execute --no-confirm
97+
98+
- name: Get new tags
99+
id: new_tags
100+
run: |
101+
git fetch --tags
102+
git tag | sort > /tmp/tags_after.txt
103+
comm -13 /tmp/tags_before.txt /tmp/tags_after.txt > /tmp/new_tags.txt
104+
cat /tmp/new_tags.txt
105+
106+
- name: Create GitHub releases
107+
env:
108+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
run: |
110+
if [ -s /tmp/new_tags.txt ]; then
111+
echo "Creating GitHub releases for new tags..."
112+
while IFS= read -r tag; do
113+
if [[ -n "$tag" ]]; then
114+
echo "Creating release for $tag..."
115+
gh release create "$tag" --generate-notes --title "$tag" || echo "Warning: Failed to create release for $tag"
116+
fi
117+
done < /tmp/new_tags.txt
118+
echo "✓ GitHub releases created!"
119+
else
120+
echo "No new tags found"
121+
fi
122+
123+
- name: Comment on PR
124+
uses: actions/github-script@v7
125+
with:
126+
script: |
127+
const fs = require('fs');
128+
const newTags = fs.readFileSync('/tmp/new_tags.txt', 'utf8').trim().split('\n').filter(t => t);
129+
130+
let body = '🚀 **Release published successfully!**\n\n';
131+
132+
if (newTags.length > 0) {
133+
body += '**Published versions:**\n';
134+
newTags.forEach(tag => {
135+
body += `- [\`${tag}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/${tag})\n`;
136+
});
137+
}
138+
139+
body += '\n✅ Crates published to crates.io\n';
140+
body += '✅ Git tags created and pushed\n';
141+
body += '✅ GitHub releases created\n';
142+
143+
github.rest.issues.createComment({
144+
owner: context.repo.owner,
145+
repo: context.repo.repo,
146+
issue_number: context.issue.number,
147+
body: body
148+
});

Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,20 @@ solana-program-runtime = { git = "https://github.com/Lightprotocol/agave", rev =
232232
solana-bpf-loader-program = { git = "https://github.com/Lightprotocol/agave", rev = "35e7c295981a195e61b4f4039a5a6ef707d2210d" }
233233
# Patch solana-program-memory to use older version where is_nonoverlapping is public
234234
solana-program-memory = { git = "https://github.com/anza-xyz/solana-sdk", rev = "1c1d667f161666f12f5a43ebef8eda9470a8c6ee" }
235+
236+
[workspace.metadata.release]
237+
allow-branch = ["main", "release/*"]
238+
tag-name = "{{crate_name}}-v{{version}}"
239+
publish = true
240+
push = true
241+
shared-version = false
242+
sign-commit = false
243+
sign-tag = false
244+
# Update workspace dependencies when releasing
245+
dependent-version = "upgrade"
246+
# Don't consolidate commits - create one commit per package
247+
consolidate-commits = false
248+
# Don't verify (skip tests/build checks)
249+
verify = false
250+
# Add delay between publishes to avoid rate limits
251+
rate-limit = 5

scripts/release-program-libs.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Bump versions for all program-libs crates and create PR
5+
# Usage: ./scripts/release-program-libs.sh [patch|minor|major]
6+
#
7+
# This script:
8+
# 1. Bumps versions in Cargo.toml files
9+
# 2. Creates a branch and commits changes
10+
# 3. Pushes branch and creates PR
11+
# 4. PR triggers GitHub Actions for validation and actual release
12+
13+
PROGRAM_LIBS=(
14+
"light-account-checks"
15+
"aligned-sized"
16+
"light-batched-merkle-tree"
17+
"light-bloom-filter"
18+
"light-compressed-account"
19+
"light-concurrent-merkle-tree"
20+
"light-hash-set"
21+
"light-hasher"
22+
"light-heap"
23+
"light-indexed-array"
24+
"light-indexed-merkle-tree"
25+
"light-macros"
26+
"light-merkle-tree-metadata"
27+
"light-verifier"
28+
"light-zero-copy-derive"
29+
"light-zero-copy"
30+
)
31+
32+
# Parse arguments
33+
BUMP_LEVEL="${1:-patch}"
34+
35+
# Validate bump level
36+
if [[ "$BUMP_LEVEL" != "patch" && "$BUMP_LEVEL" != "minor" && "$BUMP_LEVEL" != "major" ]]; then
37+
echo "Error: Invalid bump level '$BUMP_LEVEL'"
38+
echo "Usage: $0 [patch|minor|major]"
39+
exit 1
40+
fi
41+
42+
# Build the package arguments
43+
PACKAGE_ARGS=""
44+
for pkg in "${PROGRAM_LIBS[@]}"; do
45+
PACKAGE_ARGS="$PACKAGE_ARGS -p $pkg"
46+
done
47+
48+
# Create release branch
49+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
50+
BRANCH_NAME="release/program-libs-${BUMP_LEVEL}-${TIMESTAMP}"
51+
52+
echo "Creating release branch: $BRANCH_NAME"
53+
git checkout -b "$BRANCH_NAME"
54+
55+
echo ""
56+
echo "Bumping versions for ${#PROGRAM_LIBS[@]} program-libs crates ($BUMP_LEVEL)..."
57+
echo "cargo-release will automatically handle dependency ordering and workspace dependencies"
58+
echo ""
59+
60+
# Run cargo-release to bump versions only (no publish, no tag, no push)
61+
cargo release version $BUMP_LEVEL $PACKAGE_ARGS --execute --no-confirm
62+
63+
echo ""
64+
echo "✓ Versions bumped successfully!"
65+
echo ""
66+
67+
# Commit changes
68+
git add -A
69+
git commit -m "chore(program-libs): bump versions ($BUMP_LEVEL)"
70+
71+
# Push branch
72+
echo "Pushing branch to origin..."
73+
git push -u origin "$BRANCH_NAME"
74+
75+
# Create PR
76+
echo ""
77+
echo "Creating pull request..."
78+
gh pr create \
79+
--title "chore(program-libs): Release $BUMP_LEVEL version bump" \
80+
--body "## Program Libs Release
81+
82+
This PR bumps versions for all program-libs crates.
83+
84+
**Bump level:** \`$BUMP_LEVEL\`
85+
86+
**Crates included:**
87+
$(printf '- %s\n' "${PROGRAM_LIBS[@]}")
88+
89+
### Release Process
90+
1. ✅ Versions bumped in Cargo.toml files
91+
2. ⏳ PR validation (dry-run) will run automatically
92+
3. ⏳ After merge, GitHub Action will publish to crates.io and create releases
93+
94+
---
95+
*Generated by \`scripts/release-program-libs.sh\`*" \
96+
--label "release"
97+
98+
echo ""
99+
echo "✓ Pull request created!"
100+
echo ""
101+
echo "Next steps:"
102+
echo "1. Wait for PR checks to pass (dry-run validation)"
103+
echo "2. Review and merge the PR"
104+
echo "3. GitHub Action will automatically publish to crates.io and create releases"

0 commit comments

Comments
 (0)