-
Notifications
You must be signed in to change notification settings - Fork 4
138 lines (131 loc) · 3.81 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: CI
on:
workflow_call:
workflow_dispatch:
push:
branches:
- main
- master
paths-ignore:
- "LICENSE*"
- "**.md"
- "**.png"
tags-ignore:
- "**"
pull_request:
branches:
- main
- master
- dev
paths-ignore:
- "LICENSE*"
- "**.md"
- "**.png"
jobs:
# Run cargo clippy -- -D warnings
clippy_check:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- name: Run clippy
run: cargo clippy -- -D warnings
# Run cargo fmt --all -- --check
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Run cargo fmt
run: cargo fmt --all -- --check
# Run cargo test
test:
name: Run API Tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- name: Run tests
run: cargo test
get-tests:
name: Get all Tests as output
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has_tests: ${{ steps.set-matrix.outputs.has_tests }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- id: set-matrix
run: |
FOLDERS=$(ls -d tests/*/)
HAS_FOLDERS=$((${#FOLDERS[@]} > 0 ? 1 : 0))
JSON_FOLDERS=$(echo "$FOLDERS" | jq -R -s -c 'split("\n")[:-1]')
echo "has_tests=$HAS_FOLDERS" >> $GITHUB_OUTPUT
echo "matrix={\"folder\":$JSON_FOLDERS}" >> $GITHUB_OUTPUT
build-znap:
name: Build Znap Cli
needs: [get-tests]
runs-on: ubuntu-latest
if: ${{ needs.get-tests.outputs.has_tests == 1 }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo b -r -p znap-cli && mkdir -p bin && mv ./target/release/znap bin
- uses: actions/upload-artifact@v4
name: Upload Artifact
with:
name: znap-cli
path: bin/
retention-days: 1
run-tests:
name: Run Tests
needs: [get-tests, build-znap]
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.get-tests.outputs.matrix) }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
- uses: actions/download-artifact@v4
id: download-cli
with:
path: /tmp/artifacts
- name: fix excecution file
run: chmod +x ${{ steps.download-cli.outputs.download-path }}/znap-cli/znap
- name: Install dependencies and run tests
id: prepare
run: |
echo "Installing dependencies..."
npm ci --prefix "${{ matrix.folder }}"
- name: Run Tests on folder ${{ matrix.folder }}
env:
ZNAP_LIB: ${{ github.workspace }}/znap
ZNAP_CWD: ${{ matrix.folder }}
IDENTITY_KEYPAIR: ${{ secrets.IDENTITY_KEYPAIR }}
run: |
echo "Running tests..."
cd "${{ matrix.folder }}" && ${{ steps.download-cli.outputs.download-path }}/znap-cli/znap test