Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions .github/workflows/update-snarkvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Update snarkVM dependency

on:
schedule:
# Run every hour to check for new commits in snarkVM staging
- cron: '0 * * * *'
push:
branches:
- 'ci/snarkvm-update'

env:
RUST_BACKTRACE: 1

jobs:
update-snarkvm-staging:
name: Update snarkVM to latest staging
runs-on: ubuntu-22.04
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout SDK
uses: actions/checkout@v5
with:
ref: staging
token: ${{ secrets.GITHUB_TOKEN }}

- name: Get latest snarkVM staging commit
id: snarkvm-commit
uses: actions/github-script@v7
with:
script: |
// Get the latest commit hash from snarkVM staging branch
const { data: branch } = await github.rest.repos.getBranch({
owner: 'ProvableHQ',
repo: 'snarkVM',
branch: 'staging'
});

const latestCommit = branch.commit.sha;
console.log('Latest snarkVM staging commit:', latestCommit);
core.setOutput('latest_commit', latestCommit);
core.setOutput('update_needed', 'true');

Comment on lines +42 to +44
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update_needed output is hardcoded to 'true', which means the workflow will always attempt to update regardless of whether there are actual changes. Consider implementing logic to compare the current commit with the latest commit to determine if an update is actually needed.

Suggested change
core.setOutput('latest_commit', latestCommit);
core.setOutput('update_needed', 'true');
// Read the currently used snarkVM commit hash from Cargo.lock
const fs = require('fs');
let currentCommit = null;
try {
const lockFile = fs.readFileSync('Cargo.lock', 'utf8');
const match = lockFile.match(/name = "snarkVM"[^\n]*\n(?:[^\n]*\n)*?source = "git\+https:\/\/github\.com\/ProvableHQ\/snarkVM\.git\?rev=([a-f0-9]+)"/);
if (match && match[1]) {
currentCommit = match[1];
}
} catch (e) {
console.log('Could not read current snarkVM commit from Cargo.lock:', e);
}
console.log('Current snarkVM commit in Cargo.lock:', currentCommit);
core.setOutput('latest_commit', latestCommit);
if (currentCommit && currentCommit === latestCommit) {
core.setOutput('update_needed', 'false');
} else {
core.setOutput('update_needed', 'true');
}

Copilot uses AI. Check for mistakes.

- name: Setup Git
if: steps.snarkvm-commit.outputs.update_needed == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Create new update-snarkvm-staging branch from staging
if: steps.snarkvm-commit.outputs.update_needed == 'true'
run: |
# Always create a fresh branch from staging
echo "Creating new update-snarkvm-staging branch from staging"
git checkout -B update-snarkvm-staging staging
echo "Created fresh update-snarkvm-staging branch from staging"

- name: Update snarkVM dependency
if: steps.snarkvm-commit.outputs.update_needed == 'true'
run: |
# Validate the commit hash format (should be 40 chars hex or 7+ chars)
LATEST_COMMIT="${{ steps.snarkvm-commit.outputs.latest_commit }}"
if [[ ! "$LATEST_COMMIT" =~ ^[a-f0-9]{7,40}$ ]]; then
echo "Error: Invalid commit hash format: $LATEST_COMMIT"
exit 1
fi

# First, update the rev in Cargo.toml to point to the new commit
cd wasm
cargo add snarkvm-algorithms --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-circuit-network --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-console --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-ledger-block --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-ledger-query --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-ledger-store --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-parameters --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-synthesizer-program --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-synthesizer --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT
cargo add snarkvm-wasm --git https://github.com/ProvableHQ/snarkVM --rev $LATEST_COMMIT

echo "✅ Successfully updated snarkVM dependency to $LATEST_COMMIT"

- name: Commit and push changes
if: steps.snarkvm-commit.outputs.update_needed == 'true'
run: |
git add wasm/Cargo.toml wasm/Cargo.lock
git commit --no-verify -m "Update snarkVM to latest staging commit ${{ steps.snarkvm-commit.outputs.latest_commit }}

Previous commit: ${{ steps.snarkvm-commit.outputs.current_commit }}
Latest commit: ${{ steps.snarkvm-commit.outputs.latest_commit }}

This update was performed automatically by the snarkVM update workflow."
Comment on lines +88 to +93
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message references current_commit on line 90, but this output variable is never set in the snarkvm-commit step. Only latest_commit is defined on line 42. This will result in an empty value being displayed in the commit message.

Copilot uses AI. Check for mistakes.

git push --force-with-lease origin update-snarkvm-staging

- name: Create or update PR
if: steps.snarkvm-commit.outputs.update_needed == 'true'
uses: actions/github-script@v7
with:
script: |
// Check if a PR already exists from update-snarkvm-staging to staging
const { data: prs } = await github.rest.pulls.list({
owner: 'ProvableHQ',
repo: 'sdk',
head: 'ProvableHQ:update-snarkvm-staging',
base: 'staging',
state: 'open'
});

if (prs.length === 0) {
// No PR exists, create one
const { data: pr } = await github.rest.pulls.create({
owner: 'ProvableHQ',
repo: 'sdk',
title: 'Update snarkVM to latest staging commit',
head: 'update-snarkvm-staging',
base: 'staging',
body: 'This PR updates the snarkVM dependency to track the latest staging commit.\n\nLatest commit: ${{ steps.snarkvm-commit.outputs.latest_commit }}\nPrevious commit: ${{ steps.snarkvm-commit.outputs.current_commit }}\n\nThis PR was created automatically by the snarkVM update workflow.'
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR body references current_commit which is not defined in the snarkvm-commit step outputs. This will result in an empty value being displayed in the pull request description.

Copilot uses AI. Check for mistakes.

});
console.log(`Created PR #${pr.number}: ${pr.html_url}`);
} else {
console.log(`PR already exists: ${prs[0].html_url}`);
}

- name: Summary
if: always()
run: |
echo "## Workflow Summary (staging)" >> $GITHUB_STEP_SUMMARY
echo "- Current snarkVM commit: ${{ steps.snarkvm-commit.outputs.current_commit }}" >> $GITHUB_STEP_SUMMARY
Copy link
Preview

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The summary step references current_commit output which doesn't exist. Only latest_commit and update_needed are set as outputs in the snarkvm-commit step.

Suggested change
echo "- Current snarkVM commit: ${{ steps.snarkvm-commit.outputs.current_commit }}" >> $GITHUB_STEP_SUMMARY

Copilot uses AI. Check for mistakes.

echo "- Latest snarkVM commit: ${{ steps.snarkvm-commit.outputs.latest_commit }}" >> $GITHUB_STEP_SUMMARY
echo "- Update needed: ${{ steps.snarkvm-commit.outputs.update_needed }}" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.snarkvm-commit.outputs.update_needed }}" = "true" ]; then
echo "- ✅ snarkVM dependency updated successfully" >> $GITHUB_STEP_SUMMARY
else
echo "- ℹ️ No update required" >> $GITHUB_STEP_SUMMARY
fi
Loading