-
Notifications
You must be signed in to change notification settings - Fork 6
156 lines (135 loc) · 4.48 KB
/
test.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Test Rust package and built binaries
on:
push:
branches: [main]
pull_request:
branches: ["*"]
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
test_rust_crate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Basic build validation
run: |
cargo build
- name: Check program
run: |
cargo check
- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
- name: Output test coverage
run: |
cargo install cargo-tarpaulin
cargo tarpaulin --fail-under 75
build_binaries:
uses: ./.github/workflows/build.yml
test_built_binaries:
needs: build_binaries
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
include:
- os: macos-latest
artifact: macos-binaries
- os: windows-latest
artifact: windows-binaries
- os: ubuntu-latest
artifact: linux-binaries
steps:
- uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ matrix.artifact }}
path: artifact/
- name: Extract artifact (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$sourcePath = "artifact"
# Get all .zip files from the sourcePath directory
$files = Get-ChildItem -Path $sourcePath -Recurse -Include "*.zip"
# Loop through each .zip file
foreach ($file in $files) {
# Extract the file to the current directory
Expand-Archive -Path $file.FullName -DestinationPath "." -Force
}
- name: Extract artifact (Linux/MacOS)
if: runner.os != 'Windows'
shell: bash
run: |
for file in artifact/*; do
tar -xf "$file"
done
- name: Create sample folder and copy foo.ts
shell: bash
run: |
rm -rf sample
mkdir sample
cp ./.github/foo.ts sample/foo.ts
- name: Test binary
shell: bash
run: |
EXPECTED_OUTPUT=$(cat <<'EOF'
[{"file_name":"foo.ts","cyclo":3,"halstead":{"uniq_operators":13,"uniq_operands":21,"total_operators":39,"total_operands":44,"program_length":83,"vocabulary_size":34,"volume":422.25941582377817,"difficulty":12.571428571428571,"effort":5308.404084641783,"time":294.9113380356546,"bugs":0.14075313860792607},"line_count":16,"fta_score":36.502594866022214,"assessment":"OK"}]
EOF
)
if [[ "${{ runner.os }}" == "Windows" ]]; then
OUTPUT=$(./fta.exe sample --json)
elif [[ "${{ runner.os }}" == "macOS" ]]; then
brew install jq
OUTPUT=$(./fta sample --json)
else
sudo apt-get install -y jq
OUTPUT=$(./fta sample --json)
fi
if [ "$(echo "$OUTPUT" | jq --sort-keys '.')" == "$(echo "$EXPECTED_OUTPUT" | jq --sort-keys '.')" ]; then
echo "Output matches expected"
else
echo "Output does not match expected."
echo "Expected:"
echo "$EXPECTED_OUTPUT"
echo "Got:"
echo "$OUTPUT"
exit 1
fi
publish_dry_run_nix:
needs: test_built_binaries
uses: ./.github/workflows/publish-dry-run.yml
# This is a "trick", a meta task which does not change, and we can use in
# the protected branch rules as opposed to the tests one above which
# may change regularly.
validate-tests:
name: Tests status
runs-on: ubuntu-latest
needs:
- test_rust_crate
- build_binaries
- test_built_binaries
- publish_dry_run_nix
if: always()
steps:
- name: Successful run
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: Failing run
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1