Skip to content

Commit 4dd77b3

Browse files
committed
CI: Add scripts and all steps
#### Problem This repo only contains the implementation of the program and CLI, with no way of testing that it actually works. #### Summary of changes Get this repo in shape, based on the memo repo. Does the following: * add CI for testing during PRs * add publish step (only works with CLI currently) * add dependabot * add scripts * update Cargo.toml to use crates version of spl-token * add Cargo workspace * add license * add toolchain file / format file
1 parent cc888e0 commit 4dd77b3

31 files changed

+8728
-7
lines changed

.github/actions/setup/action.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Setup environment
2+
3+
inputs:
4+
cargo-cache-key:
5+
description: The key to cache cargo dependencies. Skips cargo caching if not provided.
6+
required: false
7+
cargo-cache-fallback-key:
8+
description: The fallback key to use when caching cargo dependencies. Default to not using a fallback key.
9+
required: false
10+
cargo-cache-local-key:
11+
description: The key to cache local cargo dependencies. Skips local cargo caching if not provided.
12+
required: false
13+
clippy:
14+
description: Install Clippy if `true`. Defaults to `false`.
15+
required: false
16+
rustfmt:
17+
description: Install Rustfmt if `true`. Defaults to `false`.
18+
required: false
19+
solana:
20+
description: Install Solana if `true`. Defaults to `false`.
21+
required: false
22+
23+
runs:
24+
using: 'composite'
25+
steps:
26+
- name: Setup pnpm
27+
uses: pnpm/action-setup@v3
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: 20
33+
cache: 'pnpm'
34+
35+
- name: Install Dependencies
36+
run: pnpm install --frozen-lockfile
37+
shell: bash
38+
39+
- name: Set Environment Variables
40+
shell: bash
41+
run: pnpm zx ./scripts/ci/set-env.mjs
42+
43+
- name: Install Rustfmt
44+
if: ${{ inputs.rustfmt == 'true' }}
45+
uses: dtolnay/rust-toolchain@master
46+
with:
47+
toolchain: ${{ env.TOOLCHAIN_FORMAT }}
48+
components: rustfmt
49+
50+
- name: Install Clippy
51+
if: ${{ inputs.clippy == 'true' }}
52+
uses: dtolnay/rust-toolchain@master
53+
with:
54+
toolchain: ${{ env.TOOLCHAIN_LINT }}
55+
components: clippy
56+
57+
- name: Install Solana
58+
if: ${{ inputs.solana == 'true' }}
59+
uses: solana-program/actions/install-solana@v1
60+
with:
61+
version: ${{ env.SOLANA_VERSION }}
62+
cache: true
63+
64+
- name: Cache Cargo Dependencies
65+
if: ${{ inputs.cargo-cache-key && !inputs.cargo-cache-fallback-key }}
66+
uses: actions/cache@v4
67+
with:
68+
path: |
69+
~/.cargo/bin/
70+
~/.cargo/registry/index/
71+
~/.cargo/registry/cache/
72+
~/.cargo/git/db/
73+
target/
74+
key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
75+
restore-keys: ${{ runner.os }}-${{ inputs.cargo-cache-key }}
76+
77+
- name: Cache Cargo Dependencies With Fallback
78+
if: ${{ inputs.cargo-cache-key && inputs.cargo-cache-fallback-key }}
79+
uses: actions/cache@v4
80+
with:
81+
path: |
82+
~/.cargo/bin/
83+
~/.cargo/registry/index/
84+
~/.cargo/registry/cache/
85+
~/.cargo/git/db/
86+
target/
87+
key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
88+
restore-keys: |
89+
${{ runner.os }}-${{ inputs.cargo-cache-key }}
90+
${{ runner.os }}-${{ inputs.cargo-cache-fallback-key }}-${{ hashFiles('**/Cargo.lock') }}
91+
${{ runner.os }}-${{ inputs.cargo-cache-fallback-key }}
92+
93+
- name: Cache Local Cargo Dependencies
94+
if: ${{ inputs.cargo-cache-local-key }}
95+
uses: actions/cache@v4
96+
with:
97+
path: |
98+
.cargo/bin/
99+
.cargo/registry/index/
100+
.cargo/registry/cache/
101+
.cargo/git/db/
102+
key: ${{ runner.os }}-${{ inputs.cargo-cache-local-key }}-${{ hashFiles('**/Cargo.lock') }}
103+
restore-keys: ${{ runner.os }}-${{ inputs.cargo-cache-local-key }}

.github/dependabot.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: cargo
9+
directory: "/"
10+
schedule:
11+
interval: daily
12+
time: "08:00"
13+
timezone: UTC
14+
open-pull-requests-limit: 6
15+
- package-ecosystem: npm
16+
directory: "/"
17+
schedule:
18+
interval: daily
19+
time: "09:00"
20+
timezone: UTC
21+
open-pull-requests-limit: 6
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Dependabot auto-merge
2+
on: pull_request
3+
4+
permissions:
5+
contents: write
6+
pull-requests: write
7+
8+
jobs:
9+
dependabot:
10+
runs-on: ubuntu-latest
11+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'solana-program/feature-proposal'
12+
steps:
13+
- name: Enable auto-merge
14+
run: gh pr merge --auto --squash "$PR_URL"
15+
env:
16+
PR_URL: ${{ github.event.pull_request.html_url }}
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yml

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
format_and_lint_programs:
11+
name: Format & Lint Programs
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Git Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Environment
18+
uses: ./.github/actions/setup
19+
with:
20+
clippy: true
21+
rustfmt: true
22+
23+
- name: Format Programs
24+
run: pnpm programs:format
25+
26+
- name: Lint Programs
27+
run: pnpm programs:lint
28+
29+
format_and_lint_cli:
30+
name: Format & Lint CLI
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Git Checkout
34+
uses: actions/checkout@v4
35+
36+
- name: Setup Environment
37+
uses: ./.github/actions/setup
38+
with:
39+
clippy: true
40+
rustfmt: true
41+
42+
- name: Format CLI
43+
run: pnpm clients:cli:format
44+
45+
- name: Lint CLI
46+
run: pnpm clients:cli:lint
47+
48+
audit_rust:
49+
name: Audit Rust
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Git Checkout
53+
uses: actions/checkout@v4
54+
55+
- name: Setup Environment
56+
uses: ./.github/actions/setup
57+
with:
58+
cargo-cache-key: cargo-audit
59+
60+
- name: Install cargo-audit
61+
uses: taiki-e/install-action@v2
62+
with:
63+
tool: cargo-audit
64+
65+
- name: Run cargo-audit
66+
run: pnpm rust:audit
67+
68+
semver_rust:
69+
name: Check semver Rust
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Git Checkout
73+
uses: actions/checkout@v4
74+
75+
- name: Setup Environment
76+
uses: ./.github/actions/setup
77+
with:
78+
cargo-cache-key: cargo-semver
79+
80+
- name: Install cargo-audit
81+
uses: taiki-e/install-action@v2
82+
with:
83+
tool: cargo-semver-checks
84+
85+
- name: Run semver checks
86+
run: pnpm rust:semver
87+
88+
spellcheck_rust:
89+
name: Spellcheck Rust
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Git Checkout
93+
uses: actions/checkout@v4
94+
95+
- name: Setup Environment
96+
uses: ./.github/actions/setup
97+
with:
98+
cargo-cache-key: cargo-spellcheck
99+
100+
- name: Install cargo-spellcheck
101+
uses: taiki-e/install-action@v2
102+
with:
103+
tool: cargo-spellcheck
104+
105+
- name: Run cargo-spellcheck
106+
run: pnpm rust:spellcheck
107+
108+
build_programs:
109+
name: Build programs
110+
runs-on: ubuntu-latest
111+
needs: format_and_lint_programs
112+
steps:
113+
- name: Git Checkout
114+
uses: actions/checkout@v4
115+
116+
- name: Setup Environment
117+
uses: ./.github/actions/setup
118+
with:
119+
cargo-cache-key: cargo-programs
120+
solana: true
121+
122+
- name: Build Programs
123+
run: pnpm programs:build
124+
125+
- name: Upload Program Builds
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: program-builds
129+
path: ./target/deploy/*.so
130+
if-no-files-found: error
131+
132+
- name: Save Program Builds For Client Jobs
133+
uses: actions/cache/save@v4
134+
with:
135+
path: ./**/*.so
136+
key: ${{ runner.os }}-builds-${{ github.sha }}
137+
138+
test_programs:
139+
name: Test Programs
140+
runs-on: ubuntu-latest
141+
needs: format_and_lint_programs
142+
steps:
143+
- name: Git Checkout
144+
uses: actions/checkout@v4
145+
146+
- name: Setup Environment
147+
uses: ./.github/actions/setup
148+
with:
149+
cargo-cache-key: cargo-program-tests
150+
cargo-cache-fallback-key: cargo-programs
151+
solana: true
152+
153+
- name: Test Programs
154+
run: pnpm programs:test
155+
156+
test_cli:
157+
name: Test CLI
158+
runs-on: ubuntu-latest
159+
needs: build_programs
160+
steps:
161+
- name: Git Checkout
162+
uses: actions/checkout@v4
163+
164+
- name: Setup Environment
165+
uses: ./.github/actions/setup
166+
with:
167+
cargo-cache-key: cargo-rust-client
168+
solana: true
169+
170+
- name: Restore Program Builds
171+
uses: actions/cache/restore@v4
172+
with:
173+
path: ./**/*.so
174+
key: ${{ runner.os }}-builds-${{ github.sha }}
175+
176+
- name: Test CLI
177+
run: pnpm clients:cli:test

0 commit comments

Comments
 (0)