Find directories inside the go subfolder and run test for each #13
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Find directories | |
id: set-matrix | |
run: | | |
dirs=$(find go -mindepth 1 -type d -exec basename {} \; | jq -R -s -c 'split("\n")[:-1]') | |
echo "matrix=$dirs" >> $GITHUB_OUTPUT | |
test: | |
needs: build | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
dirs: ${{ fromJson(needs.build.outputs.matrix) }} | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: 1.18 | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Run tests in each directory | |
run: | | |
for dir in "${{ matrix.dirs }}"; do | |
full_dir="go/$dir" | |
if [ -d "$full_dir" ]; then | |
echo "Running tests in $full_dir" | |
(cd "$full_dir" && go test ./...) | |
else | |
echo "No Go files in $full_dir" | |
fi | |
done |