Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
rust_projects: ${{ steps.filter.outputs.rust_projects }}
go_projects: ${{ steps.filter.outputs.go_projects }}
csharp_projects: ${{ steps.filter.outputs.csharp_projects }}
zig_projects: ${{ steps.filter.outputs.zig_projects }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -27,7 +28,14 @@ jobs:
if [ "${{ github.event_name }}" == "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
else
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
# Handle first push or null before hash
BEFORE="${{ github.event.before }}"
if [ "$BEFORE" == "0000000000000000000000000000000000000000" ] || [ -z "$BEFORE" ]; then
# Get files changed in the last commit
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD 2>/dev/null || git ls-files)
else
CHANGED_FILES=$(git diff --name-only $BEFORE ${{ github.sha }})
fi
fi

echo "Changed files:"
Expand All @@ -37,13 +45,15 @@ jobs:
ALL_RUST_PROJECTS=("2015" "2018" "2019/aoc_rust" "2020/01" "2021/_1" "2021/_2" "2021/_3" "2021/_4" "2021/_5" "2021/_6" "2021/_7" "2022")
ALL_GO_PROJECTS=("2017" "2019/go" "2020/02" "2024/golang")
ALL_CSHARP_PROJECTS=("2021/cs/1" "2021/cs/2")
ALL_ZIG_PROJECTS=("2024/zig")

# Check for workflow changes - if workflow changed, run all tests
if echo "$CHANGED_FILES" | grep -q "^.github/workflows/tests.yml"; then
echo "Workflow changed, running all tests"
RUST_PROJECTS=$(printf '%s\n' "${ALL_RUST_PROJECTS[@]}" | jq -R . | jq -s -c .)
GO_PROJECTS=$(printf '%s\n' "${ALL_GO_PROJECTS[@]}" | jq -R . | jq -s -c .)
CSHARP_PROJECTS=$(printf '%s\n' "${ALL_CSHARP_PROJECTS[@]}" | jq -R . | jq -s -c .)
ZIG_PROJECTS=$(printf '%s\n' "${ALL_ZIG_PROJECTS[@]}" | jq -R . | jq -s -c .)
else
# Detect Rust projects
RUST_PROJECTS=()
Expand All @@ -69,6 +79,14 @@ jobs:
fi
done

# Detect Zig projects
ZIG_PROJECTS=()
for project in "${ALL_ZIG_PROJECTS[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^${project}/"; then
ZIG_PROJECTS+=("$project")
fi
done

if [ ${#RUST_PROJECTS[@]} -eq 0 ]; then
RUST_PROJECTS="[]"
else
Expand All @@ -86,15 +104,23 @@ jobs:
else
CSHARP_PROJECTS=$(printf '%s\n' "${CSHARP_PROJECTS[@]}" | jq -R . | jq -s -c .)
fi

if [ ${#ZIG_PROJECTS[@]} -eq 0 ]; then
ZIG_PROJECTS="[]"
else
ZIG_PROJECTS=$(printf '%s\n' "${ZIG_PROJECTS[@]}" | jq -R . | jq -s -c .)
fi
fi

echo "rust_projects=$RUST_PROJECTS" >> $GITHUB_OUTPUT
echo "go_projects=$GO_PROJECTS" >> $GITHUB_OUTPUT
echo "csharp_projects=$CSHARP_PROJECTS" >> $GITHUB_OUTPUT
echo "zig_projects=$ZIG_PROJECTS" >> $GITHUB_OUTPUT

echo "Rust projects to test: $RUST_PROJECTS"
echo "Go projects to test: $GO_PROJECTS"
echo "C# projects to test: $CSHARP_PROJECTS"
echo "Zig projects to test: $ZIG_PROJECTS"

rust_tests:
needs: detect_changes
Expand Down Expand Up @@ -181,3 +207,22 @@ jobs:
- name: Run C# tests in ${{ matrix.project }}
run: dotnet test
working-directory: ${{ matrix.project }}

zig_tests:
needs: detect_changes
if: needs.detect_changes.outputs.zig_projects != '[]'
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.detect_changes.outputs.zig_projects) }}
steps:
- uses: actions/checkout@v4
- name: Set up Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: master
- name: Run Zig tests in ${{ matrix.project }}
run: zig build test
working-directory: ${{ matrix.project }}
10 changes: 10 additions & 0 deletions 2024/zig/data/04/example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX
Loading
Loading