@@ -77,10 +77,84 @@ jobs:
7777 retention-days : 7
7878
7979 # ============================================================================
80- # Job 2: Build Frontend Artifacts in Parallel
80+ # Job 2: Generate TypeScript Bindings from Candid
81+ # ============================================================================
82+ generate-declarations :
83+ runs-on : ubuntu-latest
84+ needs : [build-canisters]
85+
86+ steps :
87+ - name : Checkout repository
88+ uses : actions/checkout@v4
89+
90+ - name : Download canister artifacts
91+ uses : actions/download-artifact@v4
92+ with :
93+ name : ic-canisters
94+ path : artifacts/canisters
95+
96+ - name : Install dfx
97+ run : |
98+ DFX_VERSION=0.29.1 sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
99+
100+ - name : Setup Node.js
101+ uses : actions/setup-node@v4
102+ with :
103+ node-version : ' 20'
104+
105+ - name : Install didc (Candid compiler)
106+ run : |
107+ cargo install didc
108+
109+ - name : Generate TypeScript declarations
110+ run : |
111+ echo "📝 Generating TypeScript bindings from Candid files..."
112+
113+ # Create declarations output directory
114+ mkdir -p src/declarations
115+
116+ # Generate declarations for each canister
117+ for canister in btc_vault_backend mock_unlock ethereum_vault_unlock bitcoin_price_threshold; do
118+ if [ -f "artifacts/canisters/${canister}.did" ]; then
119+ echo "Generating declarations for $canister..."
120+ mkdir -p "src/declarations/$canister"
121+
122+ # Generate TypeScript declarations using didc
123+ didc bind "artifacts/canisters/${canister}.did" -t ts > "src/declarations/$canister/index.d.ts"
124+ didc bind "artifacts/canisters/${canister}.did" -t js > "src/declarations/$canister/index.js"
125+
126+ # Copy the .did file
127+ cp "artifacts/canisters/${canister}.did" "src/declarations/$canister/"
128+ fi
129+ done
130+
131+ # Download external canister declarations (evm_rpc, xrc, ic_siwb_provider)
132+ mkdir -p src/declarations/evm_rpc
133+ mkdir -p src/declarations/xrc
134+ mkdir -p src/declarations/ic_siwb_provider
135+
136+ curl -fsSL https://github.com/internet-computer-protocol/evm-rpc-canister/releases/latest/download/evm_rpc.did -o src/declarations/evm_rpc/evm_rpc.did
137+ curl -fsSL https://raw.githubusercontent.com/dfinity/exchange-rate-canister/refs/heads/main/src/xrc/xrc.did -o src/declarations/xrc/xrc.did
138+
139+ # Generate TypeScript for external canisters
140+ didc bind src/declarations/evm_rpc/evm_rpc.did -t ts > src/declarations/evm_rpc/index.d.ts
141+ didc bind src/declarations/evm_rpc/evm_rpc.did -t js > src/declarations/evm_rpc/index.js
142+ didc bind src/declarations/xrc/xrc.did -t ts > src/declarations/xrc/index.d.ts
143+ didc bind src/declarations/xrc/xrc.did -t js > src/declarations/xrc/index.js
144+
145+ - name : Upload declarations
146+ uses : actions/upload-artifact@v4
147+ with :
148+ name : ic-declarations
149+ path : src/declarations/
150+ retention-days : 7
151+
152+ # ============================================================================
153+ # Job 3: Build Frontend Artifacts (depends on declarations)
81154 # ============================================================================
82155 build-frontends :
83156 runs-on : ubuntu-latest
157+ needs : [generate-declarations]
84158 strategy :
85159 matrix :
86160 frontend :
@@ -101,6 +175,20 @@ jobs:
101175 - name : Checkout repository
102176 uses : actions/checkout@v4
103177
178+ - name : Download IC declarations (if needed)
179+ if : matrix.frontend.needs_ic == true
180+ uses : actions/download-artifact@v4
181+ with :
182+ name : ic-declarations
183+ path : src/declarations
184+
185+ - name : Copy declarations to frontend (if needed)
186+ if : matrix.frontend.needs_ic == true
187+ run : |
188+ echo "📋 Copying IC declarations to ${{ matrix.frontend.dir }}/src/declarations"
189+ mkdir -p ${{ matrix.frontend.dir }}/src/declarations
190+ cp -r src/declarations/* ${{ matrix.frontend.dir }}/src/declarations/
191+
104192 - name : Setup Node.js
105193 uses : actions/setup-node@v4
106194 with :
@@ -141,11 +229,11 @@ jobs:
141229 retention-days : 7
142230
143231 # ============================================================================
144- # Job 3 : Build and Push Docker Image
232+ # Job 4 : Build and Push Docker Image
145233 # ============================================================================
146234 build-image :
147235 runs-on : ubuntu-latest
148- needs : [build-canisters, build-frontends]
236+ needs : [build-canisters, generate-declarations, build-frontends]
149237 permissions :
150238 contents : read
151239 packages : write
0 commit comments