Skip to content

Commit b7f957c

Browse files
authored
Add main CI workflow (#53)
1 parent 587286c commit b7f957c

File tree

3 files changed

+262
-0
lines changed

3 files changed

+262
-0
lines changed

.changeset/polite-eels-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-solana-program": patch
3+
---
4+
5+
Add main CI workflow
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Setup environment
2+
3+
inputs:
4+
{% if programFramework === 'anchor' %}
5+
anchor:
6+
description: The Anchor version to install
7+
{% endif %}
8+
cache:
9+
description: Enable caching
10+
default: "true"
11+
node:
12+
description: The Node.js version to install
13+
required: true
14+
solana:
15+
description: The Solana version to install
16+
17+
runs:
18+
using: "composite"
19+
steps:
20+
- name: Setup pnpm
21+
uses: pnpm/action-setup@v3
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: {% raw %}${{ inputs.node }}{% endraw %}
26+
cache: "pnpm"
27+
- name: Install dependencies
28+
run: pnpm install --frozen-lockfile
29+
shell: bash
30+
- name: Install Solana
31+
if: {% raw %}${{ inputs.solana != '' }}{% endraw %}
32+
uses: metaplex-foundation/actions/install-solana@v1
33+
with:
34+
version: {% raw %}${{ inputs.solana }}{% endraw %}
35+
cache: {% raw %}${{ inputs.cache }}{% endraw %}
36+
{% if programFramework === 'anchor' %}
37+
- name: Install Anchor
38+
if: {% raw %}${{ inputs.anchor != '' }}{% endraw %}
39+
uses: metaplex-foundation/actions/install-anchor-cli@v1
40+
with:
41+
version: {% raw %}${{ inputs.anchor }}{% endraw %}
42+
cache: {% raw %}${{ inputs.cache }}{% endraw %}
43+
{% endif %}
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
NODE_VERSION: 18
11+
SOLANA_VERSION: 1.18.12
12+
{% if programFramework === 'anchor' %}
13+
ANCHOR_VERSION: 0.30.0
14+
{% endif %}
15+
CARGO_CACHE: |
16+
~/.cargo/bin/
17+
~/.cargo/registry/index/
18+
~/.cargo/registry/cache/
19+
~/.cargo/git/db/
20+
target/
21+
22+
jobs:
23+
build_programs:
24+
name: Build programs
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Git checkout
28+
uses: actions/checkout@v4
29+
- name: Setup environment
30+
uses: ./.github/actions/setup
31+
with:
32+
node: {% raw %}${{ env.NODE_VERSION }}{% endraw %}
33+
solana: {% raw %}${{ env.SOLANA_VERSION }}{% endraw %}
34+
{% if programFramework === 'anchor' %}
35+
anchor: {% raw %}${{ env.ANCHOR_VERSION }}{% endraw %}
36+
{% endif %}
37+
- name: Cache cargo dependencies
38+
uses: actions/cache@v4
39+
with:
40+
path: {% raw %}${{ env.CARGO_CACHE }}{% endraw %}
41+
key: {% raw %}${{ runner.os }}-cargo-programs-${{ hashFiles('**/Cargo.lock') }}{% endraw %}
42+
restore-keys: {% raw %}${{ runner.os }}-cargo-programs{% endraw %}
43+
- name: Build programs
44+
run: pnpm programs:build
45+
- name: Upload program builds
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: program-builds
49+
path: ./target/deploy/*.so
50+
if-no-files-found: error
51+
- name: Save all builds for clients
52+
uses: actions/cache/save@v4
53+
with:
54+
path: ./**/*.so
55+
key: {% raw %}${{ runner.os }}-builds-${{ github.sha }}{% endraw %}
56+
57+
test_programs:
58+
name: Test programs
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Git checkout
62+
uses: actions/checkout@v4
63+
- name: Setup environment
64+
uses: ./.github/actions/setup
65+
with:
66+
node: {% raw %}${{ env.NODE_VERSION }}{% endraw %}
67+
solana: {% raw %}${{ env.SOLANA_VERSION }}{% endraw %}
68+
{% if programFramework === 'anchor' %}
69+
anchor: {% raw %}${{ env.ANCHOR_VERSION }}{% endraw %}
70+
{% endif %}
71+
- name: Cache test cargo dependencies
72+
uses: actions/cache@v4
73+
with:
74+
path: {% raw %}${{ env.CARGO_CACHE }}{% endraw %}
75+
key: {% raw %}${{ runner.os }}-cargo-program-tests-${{ hashFiles('**/Cargo.lock') }}{% endraw %}
76+
restore-keys: |
77+
{% raw %}${{ runner.os }}-cargo-program-tests{% endraw %}
78+
{% raw %}${{ runner.os }}-cargo-programs-${{ hashFiles('**/Cargo.lock') }}{% endraw %}
79+
{% raw %}${{ runner.os }}-cargo-programs{% endraw %}
80+
- name: Test programs
81+
run: pnpm programs:test
82+
83+
generate_idls:
84+
name: Check IDL generation
85+
needs: build_programs
86+
runs-on: ubuntu-latest
87+
steps:
88+
- name: Git checkout
89+
uses: actions/checkout@v4
90+
- name: Setup environment
91+
uses: ./.github/actions/setup
92+
with:
93+
node: {% raw %}${{ env.NODE_VERSION }}{% endraw %}
94+
solana: {% raw %}${{ env.SOLANA_VERSION }}{% endraw %}
95+
{% if programFramework === 'anchor' %}
96+
anchor: {% raw %}${{ env.ANCHOR_VERSION }}{% endraw %}
97+
{% endif %}
98+
- name: Cache cargo dependencies
99+
uses: actions/cache@v4
100+
with:
101+
path: {% raw %}${{ env.CARGO_CACHE }}{% endraw %}
102+
key: {% raw %}${{ runner.os }}-cargo-programs-${{ hashFiles('**/Cargo.lock') }}{% endraw %}
103+
restore-keys: {% raw %}${{ runner.os }}-cargo-programs{% endraw %}
104+
- name: Cache local cargo dependencies
105+
uses: actions/cache@v4
106+
with:
107+
path: |
108+
.cargo/bin/
109+
.cargo/registry/index/
110+
.cargo/registry/cache/
111+
.cargo/git/db/
112+
key: {% raw %}${{ runner.os }}-cargo-local-${{ hashFiles('**/Cargo.lock') }}{% endraw %}
113+
restore-keys: {% raw %}${{ runner.os }}-cargo-local{% endraw %}
114+
- name: Generate IDLs
115+
run: pnpm generate:idls
116+
- name: Ensure working directory is clean
117+
run: test -z "$(git status --porcelain)"
118+
119+
{% if clients.length > 0 %}
120+
generate_clients:
121+
name: Check client generation
122+
needs: build_programs
123+
runs-on: ubuntu-latest
124+
steps:
125+
- name: Git checkout
126+
uses: actions/checkout@v4
127+
- name: Setup environment
128+
uses: ./.github/actions/setup
129+
with:
130+
node: {% raw %}${{ env.NODE_VERSION }}{% endraw %}
131+
solana: {% raw %}${{ env.SOLANA_VERSION }}{% endraw %}
132+
- name: Generate clients
133+
run: pnpm generate:clients
134+
- name: Ensure working directory is clean
135+
run: test -z "$(git status --porcelain)"
136+
{% endif %}
137+
138+
{% if jsClient %}
139+
test_js:
140+
name: Test JS client
141+
needs: build_programs
142+
runs-on: ubuntu-latest
143+
steps:
144+
- name: Git checkout
145+
uses: actions/checkout@v4
146+
- name: Setup environment
147+
uses: ./.github/actions/setup
148+
with:
149+
node: {% raw %}${{ env.NODE_VERSION }}{% endraw %}
150+
solana: {% raw %}${{ env.SOLANA_VERSION }}{% endraw %}
151+
- name: Restore all builds
152+
uses: actions/cache/restore@v4
153+
with:
154+
path: ./**/*.so
155+
key: {% raw %}${{ runner.os }}-builds-${{ github.sha }}{% endraw %}
156+
- name: Test JS client
157+
run: pnpm clients:js:test
158+
159+
lint_js:
160+
name: Lint JS client
161+
needs: build_programs
162+
runs-on: ubuntu-latest
163+
steps:
164+
- name: Git checkout
165+
uses: actions/checkout@v4
166+
- name: Setup environment
167+
uses: ./.github/actions/setup
168+
with:
169+
node: {% raw %}${{ env.NODE_VERSION }}{% endraw %}
170+
- name: Lint JS client
171+
run: pnpm clients:js:lint
172+
{% endif %}
173+
174+
{% if rustClient %}
175+
test_rust:
176+
name: Test Rust client
177+
needs: build_programs
178+
runs-on: ubuntu-latest
179+
steps:
180+
- name: Git checkout
181+
uses: actions/checkout@v4
182+
- name: Setup environment
183+
uses: ./.github/actions/setup
184+
with:
185+
node: {% raw %}${{ env.NODE_VERSION }}{% endraw %}
186+
solana: {% raw %}${{ env.SOLANA_VERSION }}{% endraw %}
187+
- name: Cache Rust client dependencies
188+
uses: actions/cache@v4
189+
with:
190+
path: {% raw %}${{ env.CARGO_CACHE }}{% endraw %}
191+
key: {% raw %}${{ runner.os }}-cargo-rust-client-${{ hashFiles('**/Cargo.lock') }}{% endraw %}
192+
restore-keys: {% raw %}${{ runner.os }}-cargo-rust-client{% endraw %}
193+
- name: Restore all builds
194+
uses: actions/cache/restore@v4
195+
with:
196+
path: ./**/*.so
197+
key: {% raw %}${{ runner.os }}-builds-${{ github.sha }}{% endraw %}
198+
- name: Test Rust client
199+
run: pnpm clients:rust:test
200+
201+
lint_rust:
202+
name: Lint Rust client
203+
needs: build_programs
204+
runs-on: ubuntu-latest
205+
steps:
206+
- name: Git checkout
207+
uses: actions/checkout@v4
208+
- name: Setup environment
209+
uses: ./.github/actions/setup
210+
with:
211+
node: {% raw %}${{ env.NODE_VERSION }}{% endraw %}
212+
- name: Lint Rust client
213+
run: pnpm clients:rust:lint
214+
{% endif %}

0 commit comments

Comments
 (0)