forked from devcontainers-contrib/features
-
Notifications
You must be signed in to change notification settings - Fork 9
189 lines (156 loc) · 6.19 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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
schedule:
# every day at 01:00
- cron: '0 1 * * *'
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
elif [ ${{ github.event_name }} == 'schedule' ]; then
echo 'features_to_test=${{ needs.find-features.outputs.all-features }}' >> $GITHUB_OUTPUT
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: Check if the disk has to be cleaned up
id: check-disk-space-requiement
run: |
# Array of features that require more disk storage
# If there's a feature that fails during tests due to lack of disk space, add it here
features_that_require_more_disk_storage=("homebrew-package" "haskell")
# Array of features to test from comma separated list passed in matrix.features
IFS=',' read -r -a features_to_test <<< "${{ matrix.features }}"
# Check if any feature to test requires more disk storage
# If so, set the output to true
for feature in "${features_that_require_more_disk_storage[@]}"; do
for f in "${features_to_test[@]}"; do
if [ "$f" == "$feature" ]; then
echo "clean_disk_space=true" >> "$GITHUB_OUTPUT"
fi
done
done
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
if: ${{ steps.check-disk-space-requiement.outputs.clean_disk_space == 'true' }}
with:
tool-cache: false
docker-images: false
swap-storage: false
- 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 -e SC2148 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 .