-
Notifications
You must be signed in to change notification settings - Fork 40
131 lines (110 loc) · 4.65 KB
/
Copy pathtest-challenges.yml
File metadata and controls
131 lines (110 loc) · 4.65 KB
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
name: Test Challenges
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_dispatch:
inputs:
test_all:
description: 'Test all challenges'
required: false
default: true
type: boolean
schedule:
- cron: '0 2 * * *' # Daily at 2 AM UTC
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has-changes: ${{ steps.set-matrix.outputs.has-changes }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for proper diff
- name: Get challenges to test
id: changed-challenges
run: |
# Check if we should test all challenges (manual dispatch or schedule)
if [ "${{ github.event_name }}" = "workflow_dispatch" ] || [ "${{ github.event_name }}" = "schedule" ]; then
echo "Testing all challenges (triggered by ${{ github.event_name }})"
# Find all challenge directories
CHALLENGES=$(find . -type d -path "*/*/challenge" -o -path "*/*/tests_public" -o -path "*/*/tests_private" |
cut -d'/' -f2-3 | sort -u |
grep -v "^\." |
grep -v "^ci/" |
grep -v "^legacy/" |
tr '\n' ' ')
else
# Set up environment variables for the script
export GITHUB_EVENT_NAME="${{ github.event_name }}"
if [ "${{ github.event_name }}" = "pull_request" ]; then
export GITHUB_BASE_SHA="${{ github.event.pull_request.base.sha }}"
else
export GITHUB_EVENT_BEFORE="${{ github.event.before }}"
export GITHUB_EVENT_AFTER="${{ github.event.after }}"
fi
# Run the changed challenges detection script and capture output
CHALLENGES=$(./ci/changed_challenges.sh | tr '\n' ' ')
fi
# Output for debugging
echo "Challenges to test: $CHALLENGES"
# Save raw output
echo "challenges=$CHALLENGES" >> $GITHUB_OUTPUT
- name: Set up matrix
id: set-matrix
run: |
CHALLENGES="${{ steps.changed-challenges.outputs.challenges }}"
if [ -z "$CHALLENGES" ]; then
echo "No challenges to test"
echo "has-changes=false" >> $GITHUB_OUTPUT
echo 'matrix={"challenge":[]}' >> $GITHUB_OUTPUT
else
echo "has-changes=true" >> $GITHUB_OUTPUT
# Convert space-separated list to JSON array using jq (trim whitespace first)
MATRIX=$(echo "$CHALLENGES" | xargs | tr ' ' '\n' | jq -R . | jq -s '{challenge: .}' -c)
echo "Matrix: $MATRIX"
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
fi
test-challenges:
needs: detect-changes
if: needs.detect-changes.outputs.has-changes == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false # Continue testing other challenges even if one fails
matrix: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y git-crypt
pip install jinja2 black pyastyle pwntools
- name: Remove encrypted directories
run: |
# Find and remove directories containing encrypted files using git-crypt status (these cannot be tested currently)
git crypt status -e | sed -e "s/ *encrypted: //" | xargs dirname | xargs rm -rf
- name: Test challenge
run: |
echo "================================================"
echo "Testing challenge: ${{ matrix.challenge }}"
echo "================================================"
# Run the test and transform FAILED lines on the fly
./build.py "./${{ matrix.challenge }}" 2>&1 | sed "s|^FAILED: /tmp/[^/]*/|::error::TEST FAILED: ${{ matrix.challenge }}/|"
# Check exit status of build.py (not sed)
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo "================================================"
echo "✓ ${{ matrix.challenge }} passed"
echo "================================================"
else
echo "================================================"
echo "✗ ${{ matrix.challenge }} failed"
echo "================================================"
exit 1
fi