-
Notifications
You must be signed in to change notification settings - Fork 128
156 lines (127 loc) · 4.86 KB
/
test.yaml
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: "Features - Test"
on:
workflow_dispatch:
inputs:
on_changes_only:
type: boolean
description: 'on_changes_only'
default: false
enabled:
type: boolean
description: 'enabled'
default: true
workflow_call:
inputs:
on_changes_only:
type: boolean
description: 'on_changes_only'
default: false
enabled:
type: boolean
description: 'enabled'
default: true
pull_request:
push:
branches:
- main
jobs:
find-features:
if: ${{ ( ( github.event_name != 'workflow_call' ) && ( github.event_name != 'workflow_dispatch' ) ) || inputs.enabled }}
runs-on: ubuntu-latest
name: Find feature
outputs:
all-features: ${{ steps.list-features.outputs.all_features }}
changed-features: ${{ steps.list-features.outputs.changed_features }}
steps:
- uses: actions/checkout@v3
- run: |
echo ${{ inputs.enabled }}
echo ${{ github.event_name }}
- id: list-features
uses: ./.github/actions/list-changed-features-action
with:
path: .
prepare-matrix:
needs: [find-features]
runs-on: ubuntu-latest
outputs:
features_to_test: ${{ steps.binning.outputs.binned_features }}
steps:
- name: "resolving features to test"
id: resolve_features
run: |
if [ ${{ github.event_name }} == 'pull_request' ]; then
echo 'features_to_test=${{ needs.find-features.outputs.changed-features }}' >> $GITHUB_OUTPUT
elif [ ${{ github.event_name }} == 'push' ]; then
echo 'features_to_test=${{ needs.find-features.outputs.changed-features }}' >> $GITHUB_OUTPUT
elif [ ${{ github.event_name }} == 'workflow_dispatch' ]; then
if [ ${{ inputs.on_changes_only }} == 'true' ]; then
echo 'features_to_test=${{ needs.find-features.outputs.changed-features }}' >> $GITHUB_OUTPUT
else
echo 'features_to_test=${{ needs.find-features.outputs.all-features }}' >> $GITHUB_OUTPUT
fi
elif [ ${{ github.event_name }} == 'workflow_call' ]; then
if [ ${{ inputs.on_changes_only }} == 'true' ]; then
echo 'features_to_test=${{ needs.find-features.outputs.changed-features }}' >> $GITHUB_OUTPUT
else
echo 'features_to_test=${{ needs.find-features.outputs.all-features }}' >> $GITHUB_OUTPUT
fi
fi
- name: binning
id: binning
run: |
cat > bin_cycle.py << EOF
import sys
from itertools import cycle
from typing import List, Any
import fileinput
import json
MAX_BIN_NUM=256
def cycle_baskets(items: List[Any], maxbaskets: int) -> List[List[Any]]:
baskets = [[] for _ in range(min(maxbaskets, len(items)))]
for item, basket in zip(items, cycle(baskets)):
basket.append(item)
return baskets
std_input = "".join(fileinput.input())
list_binned_values = cycle_baskets(json.loads(std_input), MAX_BIN_NUM)
comma_binned_values = [",".join(values) for values in list_binned_values]
sys.stdout.write(json.dumps(comma_binned_values))
EOF
binned_features=$(echo '${{ steps.resolve_features.outputs.features_to_test }}' | python3 bin_cycle.py)
echo $binned_features
echo "binned_features=$binned_features" >> $GITHUB_OUTPUT
test:
if: ${{ fromJson(needs.prepare-matrix.outputs.features_to_test)[0] != null }}
needs: [find-features, prepare-matrix]
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
features: ${{ fromJson(needs.prepare-matrix.outputs.features_to_test) }}
steps:
- uses: actions/checkout@v3
- name: "Install latest devcontainer CLI"
run: npm install -g @devcontainers/cli
- name: "Generating test scenarios for '${{ matrix.features }}'"
run: |
comma_separated_features=${{ matrix.features }}
feature_array=("${comma_separated_features//,/ }")
devcontainer features test -f ${feature_array[*]} --skip-autogenerated .
- name: Shell Linter
run: |
set -e
# install shellcheck
comma_separated_features=${{ matrix.features }}
for i in ${comma_separated_features//,/ }
do
shellcheck --severity=error src/"$i"/*.sh
done
test-global:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: "Install latest devcontainer CLI"
run: npm install -g @devcontainers/cli
- name: "Testing global scenarios"
run: devcontainer features test --global-scenarios-only .