Skip to content

Commit 1c22c6f

Browse files
committed
Merge branch 'main' into remove-old-docs
2 parents f5bc4c7 + a51da33 commit 1c22c6f

File tree

21 files changed

+528
-195
lines changed

21 files changed

+528
-195
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"dockerfile": "Dockerfile"
55
},
66
"postCreateCommand": "code --install-extension /tmp/compact.vsix && compact update 0.26.0"
7-
}
7+
}

.github/actions/setup/action.yml

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
name: "Setup Environment"
2-
description: "Sets up the environment with yarn, Node.js, and turbo"
2+
description: "Sets up the environment with yarn, Node.js, turbo, and Compact compiler"
3+
4+
inputs:
5+
skip-compact:
6+
description: "Skip Compact compiler installation"
7+
required: false
8+
default: "false"
9+
10+
outputs:
11+
compact-home:
12+
description: "Path to Compact compiler installation"
13+
value: ${{ steps.compact-outputs.outputs.compact-home }}
14+
compact-version:
15+
description: "Installed Compact compiler version"
16+
value: ${{ steps.compact-outputs.outputs.version }}
317

418
runs:
519
using: "composite"
620
steps:
7-
- name: Enable Corepack
21+
- name: Set shared environment variables
22+
shell: bash
23+
run: |
24+
echo "COMPILER_VERSION=0.26.0" >> $GITHUB_ENV
25+
echo "LANGUAGE_VERSION=0.18.0" >> $GITHUB_ENV
26+
27+
- name: Get yarn cache directory path
828
shell: bash
929
run: corepack enable
1030

@@ -16,8 +36,17 @@ runs:
1636
restore-keys: |
1737
${{ runner.os }}-turbo-${{ hashFiles('.turbo/*') }}
1838
39+
- name: Cache Compact compiler
40+
if: inputs.skip-compact != 'true'
41+
uses: actions/cache@v4
42+
id: compact-cache
43+
with:
44+
path: |
45+
~/.local/bin/compact
46+
key: compact-compiler-${{ env.COMPILER_VERSION }}-${{ runner.os }}
47+
1948
- name: Setup Node.js
20-
uses: actions/setup-node@v4
49+
uses: actions/setup-node@v6
2150
with:
2251
node-version-file: ".nvmrc"
2352
cache: "yarn"
@@ -31,5 +60,80 @@ runs:
3160
env:
3261
TURBO_MAJOR_VERSION: 2
3362
TURBO_TELEMETRY_DISABLED: 1
63+
run: npm install turbo@${{ env.TURBO_MAJOR_VERSION }} -g
64+
65+
- name: Install Compact compiler
66+
if: inputs.skip-compact != 'true' && steps.compact-cache.outputs.cache-hit != 'true'
67+
shell: bash
3468
run: |
35-
npm install turbo@${{ env.TURBO_MAJOR_VERSION }} -g
69+
set -euo pipefail
70+
COMPACT_HOME="$HOME/.local/bin"
71+
mkdir -p "$COMPACT_HOME"
72+
73+
# Require COMPACT_INSTALLER_URL to be provided by the caller
74+
if [ -z "${COMPACT_INSTALLER_URL:-}" ]; then
75+
echo "::error::COMPACT_INSTALLER_URL is required but not set. Provide it via env or secrets."
76+
exit 1
77+
fi
78+
79+
echo "🔧 Installing Compact compiler from $COMPACT_INSTALLER_URL ..."
80+
curl --proto '=https' --tlsv1.2 -LsSf "$COMPACT_INSTALLER_URL" | sh
81+
82+
echo "🔧 Updating Compact compiler to $COMPILER_VERSION..."
83+
"$COMPACT_HOME/compact" update "$COMPILER_VERSION"
84+
85+
echo "✅ Compact compiler installed"
86+
87+
- name: Setup Compact environment
88+
if: inputs.skip-compact != 'true'
89+
shell: bash
90+
run: |
91+
COMPACT_HOME="$HOME/.local/bin"
92+
echo "📁 Setting Compact environment variables..."
93+
echo "COMPACT_HOME=$COMPACT_HOME" >> "$GITHUB_ENV"
94+
echo "$COMPACT_HOME" >> "$GITHUB_PATH"
95+
96+
if [ -f "$COMPACT_HOME/compact" ]; then
97+
echo "✅ Compact compiler is installed at $COMPACT_HOME"
98+
else
99+
echo "::error::❌ Compact compiler not found in $COMPACT_HOME"
100+
exit 1
101+
fi
102+
103+
- name: Set Compact outputs
104+
if: inputs.skip-compact != 'true'
105+
id: compact-outputs
106+
shell: bash
107+
run: |
108+
echo "compact-home=$HOME/.local/bin" >> $GITHUB_OUTPUT
109+
echo "version=$COMPILER_VERSION" >> $GITHUB_OUTPUT
110+
111+
- name: Check compiler and language version
112+
if: inputs.skip-compact != 'true'
113+
shell: bash
114+
run: |
115+
set -euo pipefail
116+
117+
echo "🔧 Updating Compact compiler to $COMPILER_VERSION..."
118+
"$COMPACT_HOME/compact" update "$COMPILER_VERSION"
119+
120+
echo "🔍 Checking Compact compiler version..."
121+
COMPILER_OUTPUT=$("$COMPACT_HOME/compact" compile --version)
122+
COMPUTED_COMPILER_VERSION=$(echo "$COMPILER_OUTPUT" | grep -oP '\b0\.[0-9]+\.[0-9]+\b' | head -n 1)
123+
124+
if [ "$COMPUTED_COMPILER_VERSION" != "$COMPILER_VERSION" ]; then
125+
echo "::error::❌ Compiler version mismatch!%0AExpected: $COMPILER_VERSION%0AGot: $COMPUTED_COMPILER_VERSION"
126+
exit 1
127+
fi
128+
echo "✅ Compiler version matches: $COMPUTED_COMPILER_VERSION"
129+
130+
echo "🔍 Checking Compact language version..."
131+
LANGUAGE_OUTPUT=$("$COMPACT_HOME/compact" compile --language-version)
132+
COMPUTED_LANGUAGE_VERSION=$(echo "$LANGUAGE_OUTPUT" | grep -oP '\b0\.[0-9]+\.[0-9]+\b' | tail -n 1)
133+
134+
if [ "$COMPUTED_LANGUAGE_VERSION" != "$LANGUAGE_VERSION" ]; then
135+
echo "::error::❌ Language version mismatch!%0AExpected: $LANGUAGE_VERSION%0AGot: $COMPUTED_LANGUAGE_VERSION"
136+
exit 1
137+
fi
138+
echo "✅ Language version matches: $COMPUTED_LANGUAGE_VERSION"
139+

.github/workflows/checks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
name: Run Checks
1515
runs-on: ubuntu-24.04
1616

17+
env:
18+
COMPACT_INSTALLER_URL: ${{ vars.COMPACT_INSTALLER_URL }}
19+
1720
steps:
1821
- name: Check out code
1922
uses: actions/checkout@v5

.github/workflows/codeql.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
matrix:
2323
language: ["javascript", "typescript"]
2424

25+
env:
26+
COMPACT_INSTALLER_URL: ${{ vars.COMPACT_INSTALLER_URL }}
27+
2528
steps:
2629
- name: Check out code
2730
uses: actions/checkout@v5
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Update version on new release branch
2+
3+
on:
4+
create:
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
10+
jobs:
11+
update_version:
12+
if: github.ref_type == 'branch' && startsWith(github.ref, 'refs/heads/release-v')
13+
runs-on: ubuntu-24.04
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v5
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v6
21+
with:
22+
node-version-file: ".nvmrc"
23+
cache: "yarn"
24+
25+
- name: Extract current version
26+
run: |
27+
CURRENT_VERSION=$(node -p "require('./contracts/package.json').version")
28+
echo "CURRENT_VERSION=$CURRENT_VERSION" >> "$GITHUB_ENV"
29+
30+
- name: Extract new version number
31+
run: echo "NEW_VERSION=${GITHUB_REF#refs/heads/release-v}" >> "$GITHUB_ENV"
32+
33+
- name: Validate new version
34+
run: |
35+
BRANCH="${GITHUB_REF#refs/heads/}"
36+
echo "Branch: $BRANCH"
37+
echo "Current version: $CURRENT_VERSION"
38+
echo "New version: $NEW_VERSION"
39+
40+
# 1) Branch must match release-v<semver>
41+
if ! echo "$BRANCH" | grep -Eq '^release-v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$'; then
42+
echo "Error: Branch '$BRANCH' must match 'release-v<semver>' (e.g., release-v1.2.3)." >&2
43+
exit 1
44+
fi
45+
46+
# 2) NEW_VERSION must be valid semver
47+
node -e "const v=process.env.NEW_VERSION; const semver=/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$/; if(!semver.test(v)){ console.error('Error: NEW_VERSION is not valid semver:', v); process.exit(1); }"
48+
if [ $? -ne 0 ]; then
49+
exit 1
50+
fi
51+
52+
# 3) NEW_VERSION must differ from CURRENT_VERSION
53+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
54+
echo "Error: NEW_VERSION equals CURRENT_VERSION ($CURRENT_VERSION). Nothing to release." >&2
55+
exit 1
56+
fi
57+
58+
- name: Replace version in files
59+
env:
60+
NEW_VERSION: ${{ env.NEW_VERSION }}
61+
run: |
62+
echo "Current version: $CURRENT_VERSION"
63+
echo "New version: $NEW_VERSION"
64+
65+
# Update package.json version field manually
66+
yarn workspace @openzeppelin-compact/contracts version "$NEW_VERSION"
67+
68+
# Escape special characters for sed
69+
ESCAPED_CURRENT=$(printf '%s' "$CURRENT_VERSION" | sed -e 's/[\/&]/\\&/g')
70+
ESCAPED_NEW=$(printf '%s' "$NEW_VERSION" | sed -e 's/[\/&]/\\&/g')
71+
72+
# Replace version in contracts/src/
73+
find ./contracts/src/ -type d -name '.*' -prune -o \
74+
-type f -exec sed -i "s#$ESCAPED_CURRENT#$ESCAPED_NEW#g" {} +
75+
76+
# Replace version in docs/, excluding package-lock.json
77+
find ./docs/ -type d -name '.*' -prune -o \
78+
-type f ! -name 'package-lock.json' -exec sed -i "s#$ESCAPED_CURRENT#$ESCAPED_NEW#g" {} +
79+
80+
- name: Auto-commit changes
81+
uses: stefanzweifel/git-auto-commit-action@778341af668090896ca464160c2def5d1d1a3eb0 #v6.0.1
82+
with:
83+
commit_message: Bump version to ${{ env.NEW_VERSION }}

.github/workflows/release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Publish Package on Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-24.04
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
env:
15+
COMPACT_INSTALLER_URL: ${{ vars.COMPACT_INSTALLER_URL }}
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v5
20+
21+
- name: Setup Environment
22+
uses: ./.github/actions/setup
23+
24+
- name: Build contracts
25+
run: turbo build --filter=!'docs'
26+
27+
- name: Validate version consistency
28+
run: |
29+
RELEASE_VERSION=${GITHUB_REF#refs/tags/v}
30+
PACKAGE_VERSION=$(node -p "require('./contracts/package.json').version")
31+
if [ "$RELEASE_VERSION" != "$PACKAGE_VERSION" ]; then
32+
echo "❌ Version mismatch: Release $RELEASE_VERSION vs Package $PACKAGE_VERSION"
33+
exit 1
34+
fi
35+
echo "✅ Version consistency validated: $RELEASE_VERSION"
36+
37+
- name: Setup npm registry
38+
uses: actions/setup-node@v6
39+
with:
40+
registry-url: "https://registry.npmjs.org"
41+
42+
- name: Pack tarball
43+
id: pack
44+
run: |
45+
cd contracts/dist
46+
TARBALL=$(npm pack | tail -1)
47+
echo "tarball_name=$TARBALL" >> $GITHUB_OUTPUT
48+
echo "tarball=$(pwd)/$TARBALL" >> $GITHUB_OUTPUT
49+
50+
# Determine dist-tag based on semver prerelease
51+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
52+
if [[ "$PACKAGE_VERSION" =~ -.*$ ]]; then
53+
# Has prerelease suffix (anything after -)
54+
if [[ "$PACKAGE_VERSION" =~ -(alpha|beta|rc) ]]; then
55+
echo "tag=beta" >> $GITHUB_OUTPUT
56+
else
57+
echo "tag=next" >> $GITHUB_OUTPUT
58+
fi
59+
else
60+
# Stable release
61+
echo "tag=latest" >> $GITHUB_OUTPUT
62+
fi
63+
64+
- name: Verify tarball integrity
65+
run: |
66+
echo "=== Verifying tarball contents ==="
67+
PACKAGE_NAME=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r .name)
68+
PACKAGE_VERSION=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r .version)
69+
PRIVATE_FIELD=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r '.private // "not found"')
70+
71+
echo "📦 Package: $PACKAGE_NAME@$PACKAGE_VERSION"
72+
echo "🏷️ Tag: ${{ steps.pack.outputs.tag }}"
73+
echo "🔒 Private field: $PRIVATE_FIELD"
74+
75+
# Ensure no private field
76+
if [ "$PRIVATE_FIELD" = "true" ]; then
77+
echo "❌ Tarball contains private: true - cannot publish"
78+
exit 1
79+
fi
80+
81+
- name: Publish to npm
82+
run: |
83+
# Publish the tarball with appropriate tag
84+
npm publish "${{ steps.pack.outputs.tarball }}" --tag "${{ steps.pack.outputs.tag }}" --access public --provenance
85+
env:
86+
NPM_CONFIG_PROVENANCE: true
87+
88+
- name: Log success
89+
run: |
90+
PACKAGE_NAME=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r .name)
91+
PACKAGE_VERSION=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r .version)
92+
echo "✅ Successfully published $PACKAGE_NAME@$PACKAGE_VERSION to npm with tag ${{ steps.pack.outputs.tag }}"
93+
echo "📦 Install with: npm install $PACKAGE_NAME@${{ steps.pack.outputs.tag }}"

0 commit comments

Comments
 (0)