Skip to content

Commit b389bef

Browse files
committed
feat(toolkit): add compact-0.31.108 toolkit-js variant (compact-js 2.5.3)
Add a toolkit-js variant for ledger 9 / compactc 0.31.108, pinning @midnight-ntwrk/compact-js* 2.5.3. Since 2.5.3 and its matching compact-runtime are unpublished, the variant consumes five npm-pack tarballs via file: references (compact-js{,-command,-node}, compact-runtime, ledger-v9); everything else resolves from public npm, so the consume path needs no registry token. The blobs are built in CI from the new midnight-sdk submodule (pinned to 49f45a76) by the +compact-js-bundle Earthly target (scripts/build-compact-js-bundle.sh) and committed to the PR branch by the rebuild-compact-js-bundle-bot workflow (/bot rebuild-compact-js-bundle). The vendor/ dir ships only a placeholder README until the bot populates it. Also regenerates COMPACTC_VERSION from the bumped compact/ submodule (0.31.108-0eb1677c6f54) and registers the variant in the resolver, root package.json, the compat test script, README, and AGENTS. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
1 parent 4fcf424 commit b389bef

17 files changed

Lines changed: 587 additions & 7 deletions

File tree

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
name: Rebuild Compact-JS Bundle (Bot Action)
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
pr_number:
9+
description: 'PR number to rebuild the compact-js bundle for'
10+
required: true
11+
12+
jobs:
13+
rebuild-compact-js-bundle:
14+
if: |
15+
github.event_name == 'workflow_dispatch' ||
16+
(github.event.issue.pull_request && contains(github.event.comment.body, '/bot rebuild-compact-js-bundle'))
17+
runs-on: [self-hosted, "tier:medium"]
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
steps:
22+
- name: Check user permission
23+
if: github.event_name == 'issue_comment'
24+
id: check_permission
25+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
26+
with:
27+
script: |
28+
const association = context.payload.comment.author_association;
29+
if (!['MEMBER', 'OWNER'].includes(association)) {
30+
core.setFailed(`User ${context.actor} is not an org member or owner (association: ${association})`);
31+
return;
32+
}
33+
const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
username: context.actor
37+
});
38+
const allowed = ['admin', 'write'].includes(permission.permission);
39+
if (!allowed) {
40+
core.setFailed(`User ${context.actor} does not have write permission`);
41+
}
42+
43+
- name: Add reaction to comment
44+
if: github.event_name == 'issue_comment'
45+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
46+
with:
47+
script: |
48+
github.rest.reactions.createForIssueComment({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
comment_id: context.payload.comment.id,
52+
content: 'rocket'
53+
})
54+
55+
- name: Get PR branch
56+
id: pr
57+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
58+
env:
59+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
60+
with:
61+
script: |
62+
const prNumber = context.eventName === 'workflow_dispatch'
63+
? process.env.PR_NUMBER
64+
: context.issue.number;
65+
const pr = await github.rest.pulls.get({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
pull_number: prNumber
69+
});
70+
if (pr.data.head.repo === null || pr.data.head.repo.fork) {
71+
core.setFailed('Bot commands are not allowed on fork PRs for security reasons');
72+
return;
73+
}
74+
core.setOutput('ref', pr.data.head.ref);
75+
core.setOutput('sha', pr.data.head.sha);
76+
core.setOutput('number', prNumber);
77+
78+
- name: Checkout PR branch
79+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
80+
with:
81+
submodules: recursive
82+
ref: ${{ steps.pr.outputs.sha }}
83+
token: ${{ secrets.GITHUB_TOKEN }}
84+
fetch-depth: 0
85+
86+
- name: Setup Earthly
87+
uses: EarthBuild/actions-setup@cae2d9ab68894d8402751fe42e07c7cca0272f7f
88+
with:
89+
version: v0.8.16
90+
github-token: ${{ github.token }}
91+
use-cache: false
92+
93+
- name: Login to GHCR
94+
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee #v4.2.0
95+
with:
96+
registry: ghcr.io
97+
username: MidnightCI
98+
password: ${{ secrets.MIDNIGHTCI_PACKAGES_READ }}
99+
100+
- name: Run compact-js-bundle
101+
env:
102+
EARTHLY_CONFIG: .earthly/config.yml
103+
MIDNIGHTCI_PACKAGES_READ: ${{ secrets.MIDNIGHTCI_PACKAGES_READ }}
104+
run: |
105+
mkdir -p "$HOME"/.cargo
106+
echo "[net]" >> "$HOME"/.cargo/config
107+
echo "git-fetch-with-cli = true" >> "$HOME"/.cargo/config
108+
earthly -P --secret MIDNIGHTCI_PACKAGES_READ="$MIDNIGHTCI_PACKAGES_READ" +compact-js-bundle
109+
110+
- name: Commit and push changes
111+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
112+
id: commit
113+
env:
114+
REPO: ${{ github.repository }}
115+
PR_REF: ${{ steps.pr.outputs.ref }}
116+
with:
117+
script: |
118+
const fs = require('fs');
119+
const { execSync } = require('child_process');
120+
121+
// Check if there are changes
122+
const status = execSync('git status --porcelain').toString();
123+
if (!status.trim()) {
124+
core.exportVariable('CHANGES_MADE', 'false');
125+
console.log('No changes to commit');
126+
return;
127+
}
128+
129+
// Get changed vendored tarballs
130+
const prefix = 'util/toolkit-js/compact-0.31.108/vendor/';
131+
const changedFiles = status.split('\n')
132+
.filter(line => line.trim())
133+
.map(line => line.substring(3))
134+
.filter(file => file.startsWith(prefix) && file.endsWith('.tgz'));
135+
136+
if (changedFiles.length === 0) {
137+
core.exportVariable('CHANGES_MADE', 'false');
138+
console.log('No vendored bundle changes to commit');
139+
return;
140+
}
141+
142+
// Prepare file additions (tarballs are binary; base64 handles them).
143+
const additions = changedFiles.map(filePath => ({
144+
path: filePath,
145+
contents: fs.readFileSync(filePath).toString('base64')
146+
}));
147+
148+
// Get current HEAD
149+
const headOid = execSync('git rev-parse HEAD').toString().trim();
150+
151+
// Create commit via GraphQL API (produces a verified github-actions[bot] commit). DCO is
152+
// enforced only by the local commit-msg hook, not server-side, but we add Signed-off-by
153+
// in the body by convention.
154+
const result = await github.graphql(`
155+
mutation($input: CreateCommitOnBranchInput!) {
156+
createCommitOnBranch(input: $input) {
157+
commit {
158+
oid
159+
}
160+
}
161+
}
162+
`, {
163+
input: {
164+
branch: {
165+
repositoryNameWithOwner: process.env.REPO,
166+
branchName: process.env.PR_REF
167+
},
168+
message: {
169+
headline: 'chore: rebuild compact-js vendored bundle',
170+
body: 'Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>'
171+
},
172+
expectedHeadOid: headOid,
173+
fileChanges: {
174+
additions: additions
175+
}
176+
}
177+
});
178+
179+
console.log('Commit created:', result.createCommitOnBranch.commit.oid);
180+
core.exportVariable('CHANGES_MADE', 'true');
181+
182+
- name: Post success comment
183+
if: env.CHANGES_MADE == 'true'
184+
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
185+
with:
186+
message: |
187+
:white_check_mark: Compact-JS bundle rebuild complete! Vendored tarballs have been committed. Remember to regenerate `util/toolkit-js/package-lock.json` (`npm install`) and commit it.
188+
pr-number: ${{ steps.pr.outputs.number }}
189+
190+
- name: Post no-changes comment
191+
if: env.CHANGES_MADE == 'false'
192+
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
193+
with:
194+
message: |
195+
:white_check_mark: Compact-JS bundle rebuild complete. No changes detected.
196+
pr-number: ${{ steps.pr.outputs.number }}
197+
198+
- name: Post failure comment
199+
if: failure()
200+
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
201+
with:
202+
message: |
203+
:x: Compact-JS bundle rebuild failed. Check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
204+
pr-number: ${{ steps.pr.outputs.number }}

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "compact"]
88
path = compact
99
url = https://github.com/LFDT-Minokawa/compact.git
10+
[submodule "midnight-sdk"]
11+
path = midnight-sdk
12+
url = https://github.com/midnightntwrk/midnight-sdk

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ earthly doc # List all available targets
2828
- `/bot rebuild-metadata` - Rebuild runtime metadata
2929
- `/bot rebuild-chainspec <network1> <network2>` - Rebuild chainspecs for specified networks
3030
- `/bot cargo-fmt` - Run cargo fmt
31+
- `/bot rebuild-compact-js-bundle` - Rebuild the vendored `compact-js` tarballs for the `compact-0.31.108` toolkit-js variant (see `util/toolkit-js/README.md`)
3132

3233
**E2E tests (just):**
3334
```bash

COMPACTC_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.31.0-6587676a9bb2
1+
0.31.108-0eb1677c6f54

Earthfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,42 @@ compactc-fetch:
825825
rm /tmp/compactc.zip
826826
SAVE ARTIFACT /compact-home
827827

828+
# Builds the five vendored `.tgz` blobs the `compact-0.31.108` toolkit-js variant consumes via
829+
# `file:` references (compact-js{,-command,-node} 2.5.3, the matching compact-runtime, and ledger-v9),
830+
# from the pinned `midnight-sdk` submodule. Mirrors +compactc-bundle: runs nix inside the build with
831+
# the IOG cache enabled so the runtime's zkir/onchain-runtime are fetched prebuilt rather than
832+
# compiled. The GitHub Packages read token is consumed ONLY here (ledger-v9 + the SDK's install) —
833+
# the consume path (`npm ci` in util/toolkit-js) needs no token. See
834+
# util/toolkit-js/compact-0.31.108/vendor/README.md and scripts/build-compact-js-bundle.sh.
835+
compact-js-bundle:
836+
# TODO: pin to a digest/tag once first green CI confirms it works.
837+
FROM nixos/nix:latest
838+
# Append (don't clobber) so the base image's defaults (incl. cache.nixos.org) survive. sandbox=false
839+
# because buildkit/podman containers usually lack the user namespaces nix's sandbox needs.
840+
RUN mkdir -p /etc/nix && { \
841+
echo "extra-experimental-features = nix-command flakes"; \
842+
echo "sandbox = false"; \
843+
echo "extra-substituters = https://cache.iog.io"; \
844+
echo "extra-trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="; \
845+
} >> /etc/nix/nix.conf
846+
# The midnight-sdk submodule (with its nested compact-submodule checked out recursively by the
847+
# caller) and the build script. COPY brings the working-tree files; the COPY'd submodules have no
848+
# `.git`, so the script's nix invocations use `path:` refs.
849+
COPY midnight-sdk /work/midnight-sdk
850+
COPY scripts/build-compact-js-bundle.sh /work/scripts/build-compact-js-bundle.sh
851+
WORKDIR /work
852+
# node/yarn/git aren't in the base nixos/nix image; provide them via `nix shell` for the build.
853+
# The token is consumed only inside this RUN and never written into the produced tarballs.
854+
RUN --secret MIDNIGHTCI_PACKAGES_READ= \
855+
SDK_DIR=/work/midnight-sdk VENDOR_DIR=/work/vendor-out \
856+
nix shell nixpkgs#nodejs_22 nixpkgs#yarn nixpkgs#git \
857+
--command bash /work/scripts/build-compact-js-bundle.sh
858+
SAVE ARTIFACT /work/vendor-out/compact-js.tgz AS LOCAL util/toolkit-js/compact-0.31.108/vendor/compact-js.tgz
859+
SAVE ARTIFACT /work/vendor-out/compact-js-command.tgz AS LOCAL util/toolkit-js/compact-0.31.108/vendor/compact-js-command.tgz
860+
SAVE ARTIFACT /work/vendor-out/compact-js-node.tgz AS LOCAL util/toolkit-js/compact-0.31.108/vendor/compact-js-node.tgz
861+
SAVE ARTIFACT /work/vendor-out/compact-runtime.tgz AS LOCAL util/toolkit-js/compact-0.31.108/vendor/compact-runtime.tgz
862+
SAVE ARTIFACT /work/vendor-out/ledger-v9.tgz AS LOCAL util/toolkit-js/compact-0.31.108/vendor/ledger-v9.tgz
863+
828864
# compactc-build-local builds and exports compactc to .compact-home
829865
compactc-build-local:
830866
LOCALLY
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#toolkit
2+
# Add `compact-0.31.108` toolkit-js variant (compact-js 2.5.3, for ledger 9)
3+
4+
Adds a new `util/toolkit-js/compact-0.31.108/` variant workspace pinning `@midnight-ntwrk/compact-js*`
5+
2.5.3, selected when `COMPACTC_VERSION` resolves to `0.31.108`.
6+
7+
Because compact-js 2.5.3 and its matching `compact-runtime` are unpublished, the variant consumes five
8+
`npm pack` tarballs via `file:` references (`compact-js{,-command,-node}`, `compact-runtime`, `ledger-v9`).
9+
The blobs are built in CI from the pinned `midnight-sdk` submodule by the new `+compact-js-bundle` Earthly
10+
target (`scripts/build-compact-js-bundle.sh`) and committed to the PR branch by the
11+
`rebuild-compact-js-bundle-bot` workflow (`/bot rebuild-compact-js-bundle`). The consume path
12+
(`npm ci` in `util/toolkit-js`) needs no registry token — everything else resolves from public npm.
13+
14+
PR: <link to PR>

compact

Submodule compact updated 122 files

midnight-sdk

Submodule midnight-sdk added at 49f45a7

0 commit comments

Comments
 (0)