-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (116 loc) · 3.47 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
name: Unit Tests
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
pull-requests: write
jobs:
setup:
runs-on: ubuntu-latest
outputs:
cache-key: ${{ steps.cache-go-build.outputs.cache-hit }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
- name: Cache Go modules and build cache
id: cache-go-build
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/golangci-lint
~/.cache/go-build
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-build-
# General Tests Job (Excluding ElGamal)
tests:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
- name: Restore cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/golangci-lint
~/.cache/go-build
key: ${{ needs.setup.outputs.cache-key }}
- name: Run general unit tests (excluding elgamal)
run: |
echo "Determining packages to test (excluding elgamal)..."
go list ./... | grep -v '/pkg/encryption/elgamal$' | xargs go test -mod=readonly -race -v -timeout 5m
# Define a matrix for ElGamal package test subsets
elgamal-tests:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
test_group: [
'EncryptionDecryption',
'KeyGeneration',
'48BitEncryptionDecryption',
'AddCiphertext',
'TwistedElGamal'
]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
- name: Restore cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/golangci-lint
~/.cache/go-build
key: ${{ needs.setup.outputs.cache-key }}
- name: Run ElGamal ${{ matrix.test_group }} tests
run: |
cd pkg/encryption/elgamal
mapfile -t TESTS < <(go list -f '{{.Dir}}/*.go' ./...)
# Modify the run pattern based on your test naming conventions
go test -mod=readonly -race -timeout 20m -run ^Test${{ matrix.test_group }} -v ./...
unit-test-check:
name: Unit Test Check
runs-on: ubuntu-latest
needs:
- tests
- elgamal-tests
if: always()
steps:
- name: Get workflow conclusion
id: workflow_conclusion
uses: nick-fields/retry@v2
with:
max_attempts: 2
retry_on: error
timeout_seconds: 30
command: |
jobs=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs)
job_statuses=$(echo "$jobs" | jq -r '.jobs[] | .conclusion')
for status in $job_statuses
do
echo "Status: $status"
if [[ "$status" == "failure" ]]; then
echo "Some or all tests have failed!"
exit 1
fi
done
echo "All tests have passed!"