Skip to content

Commit 7086bcb

Browse files
committed
Add parallel build workflow for optimized CI
1 parent f188468 commit 7086bcb

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
name: Build Contracts
3+
4+
on:
5+
schedule:
6+
- cron: '0 5 * * 1-5'
7+
push:
8+
branches:
9+
- '**'
10+
workflow_dispatch:
11+
inputs:
12+
toolchain:
13+
description: 'Default Rust Toolchain'
14+
default: "1.78.0"
15+
required: true
16+
type: string
17+
target:
18+
description: 'Default Rust Target'
19+
default: "wasm32-unknown-unknown"
20+
required: true
21+
type: string
22+
branch:
23+
description: 'Default Branch or Commit hash to use'
24+
default: "main"
25+
required: true
26+
type: string
27+
id:
28+
description: 'Workflow ID (Optional)'
29+
default: "scheduled"
30+
required: false
31+
type: string
32+
33+
env:
34+
TOOLCHAIN: ${{ inputs.toolchain || '1.78.0' }}
35+
TARGET: ${{ inputs.target || 'wasm32-unknown-unknown' }}
36+
REF: ${{ github.event_name == 'push' && github.ref || inputs.branch || 'main' }}
37+
ID: ${{ inputs.id || 'scheduled' }}
38+
39+
jobs:
40+
# Check if artifacts already exist to skip unnecessary work
41+
check-artifacts:
42+
name: Check existing artifacts
43+
runs-on: ubicloud-standard-4
44+
outputs:
45+
artifacts_exist: ${{ steps.check.outputs.exists }}
46+
sha: ${{ steps.get-sha.outputs.sha }}
47+
branch: ${{ steps.get-branch.outputs.branch }}
48+
steps:
49+
- uses: actions/checkout@v4
50+
with:
51+
ref: ${{ env.REF }}
52+
fetch-depth: 0
53+
54+
- name: Get SHA
55+
id: get-sha
56+
run: echo "sha=$(/usr/bin/git log -1 --format='%H')" >> $GITHUB_OUTPUT
57+
58+
- name: Get branch name
59+
id: get-branch
60+
run: |
61+
if git show-ref --quiet --heads $REF; then
62+
BRANCH_NAME="${REF#refs/heads/}"
63+
else
64+
BRANCH_NAME="$(git show -s --pretty=%d "${REF}" | sed -n 's/^.*[(,]\s*origin\/\([^),]*\).*$/\1/p')"
65+
fi
66+
echo "branch=${BRANCH_NAME}" >> $GITHUB_OUTPUT
67+
env:
68+
REF: ${{ env.REF }}
69+
70+
- id: 'auth'
71+
uses: 'google-github-actions/auth@v2'
72+
with:
73+
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
74+
75+
- uses: 'google-github-actions/setup-gcloud@v2'
76+
77+
- name: Check artifacts in GCP
78+
id: check
79+
run: |
80+
if gsutil -q stat gs://neutron-contracts/${{ github.repository }}/${{ steps.get-sha.outputs.sha }}/*.wasm; then
81+
if [ "${{ env.ID }}" != 'scheduled' ]; then
82+
echo "Force build requested"
83+
echo "exists=false" >> $GITHUB_OUTPUT
84+
else
85+
echo "Artifacts exist, skipping build"
86+
echo "exists=true" >> $GITHUB_OUTPUT
87+
fi
88+
else
89+
echo "No artifacts found, will build"
90+
echo "exists=false" >> $GITHUB_OUTPUT
91+
fi
92+
93+
# Job 1: Compile contracts (the slow step - ~9 min)
94+
compile:
95+
name: Compile contracts
96+
needs: [check-artifacts]
97+
if: needs.check-artifacts.outputs.artifacts_exist == 'false'
98+
runs-on: ubicloud-standard-30
99+
steps:
100+
- uses: actions/checkout@v4
101+
with:
102+
ref: ${{ env.REF }}
103+
104+
- name: Compile contracts
105+
run: make compile
106+
107+
- name: Upload artifacts
108+
uses: actions/upload-artifact@v4
109+
with:
110+
name: wasm-artifacts
111+
path: artifacts/
112+
retention-days: 1
113+
114+
# Job 2: Lint and test (runs in parallel with compile - ~5 min)
115+
lint-test:
116+
name: Lint & Test
117+
needs: [check-artifacts]
118+
if: needs.check-artifacts.outputs.artifacts_exist == 'false'
119+
runs-on: ubicloud-standard-16
120+
steps:
121+
- uses: actions/checkout@v4
122+
with:
123+
ref: ${{ env.REF }}
124+
125+
- uses: dtolnay/rust-toolchain@master
126+
with:
127+
toolchain: ${{ env.TOOLCHAIN }}
128+
target: ${{ env.TARGET }}
129+
components: rustfmt, clippy
130+
131+
- run: make schema
132+
133+
- run: cargo fetch --verbose
134+
135+
- run: cargo clippy --all --all-targets -- -D warnings
136+
137+
- run: cargo test --verbose --all
138+
env:
139+
RUST_BACKTRACE: 1
140+
141+
- run: cargo fmt -- --check
142+
143+
# Job 3: Check and upload (needs both compile and lint-test - ~2 min)
144+
check-upload:
145+
name: Check & Upload
146+
needs: [check-artifacts, compile, lint-test]
147+
if: needs.check-artifacts.outputs.artifacts_exist == 'false'
148+
runs-on: ubicloud-standard-8
149+
env:
150+
SHA: ${{ needs.check-artifacts.outputs.sha }}
151+
BRANCH: ${{ needs.check-artifacts.outputs.branch }}
152+
steps:
153+
- uses: actions/checkout@v4
154+
with:
155+
ref: ${{ env.REF }}
156+
157+
- name: Download artifacts
158+
uses: actions/download-artifact@v4
159+
with:
160+
name: wasm-artifacts
161+
path: artifacts/
162+
163+
- uses: dtolnay/rust-toolchain@master
164+
with:
165+
toolchain: ${{ env.TOOLCHAIN }}
166+
target: ${{ env.TARGET }}
167+
168+
- name: Check contracts
169+
run: make -j$(nproc) check_contracts
170+
171+
- id: 'auth'
172+
uses: 'google-github-actions/auth@v2'
173+
with:
174+
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
175+
176+
- uses: 'google-github-actions/setup-gcloud@v2'
177+
178+
- name: Upload to GCS (repo/branch/sha)
179+
run: |
180+
gsutil -h "Cache-Control:no-cache, no-store, must-revalidate" cp -r artifacts/* gs://neutron-contracts/${{ github.repository }}/${{ env.BRANCH }}/${{ env.SHA }}/
181+
gsutil setmeta -r -h "x-goog-meta-Neutron-Repo: ${{ github.repository }}" -h "x-goog-meta-Neutron-Commit: ${{ env.SHA }}" gs://neutron-contracts/${{ github.repository }}/${{ env.BRANCH }}/${{ env.SHA }}/
182+
183+
- name: Upload to GCS (repo/branch/WF/ID)
184+
run: |
185+
gsutil -h "Cache-Control:no-cache, no-store, must-revalidate" cp -r artifacts/* gs://neutron-contracts/${{ github.repository }}/${{ env.BRANCH }}/WF/${{ env.ID }}/
186+
gsutil setmeta -r -h "x-goog-meta-Neutron-Repo: ${{ github.repository }}" -h "x-goog-meta-Neutron-Commit: ${{ env.SHA }}" gs://neutron-contracts/${{ github.repository }}/${{ env.BRANCH }}/WF/${{ env.ID }}/
187+
188+
- name: Upload to GCS (repo/sha)
189+
run: |
190+
gsutil -h "Cache-Control:no-cache, no-store, must-revalidate" cp -r artifacts/* gs://neutron-contracts/${{ github.repository }}/${{ env.SHA }}/
191+
gsutil setmeta -r -h "x-goog-meta-Neutron-Repo: ${{ github.repository }}" -h "x-goog-meta-Neutron-Commit: ${{ env.SHA }}" gs://neutron-contracts/${{ github.repository }}/${{ env.SHA }}/
192+
193+
# Skip notification when artifacts already exist
194+
skip-notification:
195+
name: Skip (artifacts exist)
196+
needs: [check-artifacts]
197+
if: needs.check-artifacts.outputs.artifacts_exist == 'true'
198+
runs-on: ubicloud-standard-4
199+
steps:
200+
- run: echo "::notice::Artifacts already exist in GCP Bucket, skipping build."

0 commit comments

Comments
 (0)