Skip to content

Commit

Permalink
Merge pull request #5 from arunsathiya/actions/setup-tests-workflow
Browse files Browse the repository at this point in the history
Setup tests workflow on GitHub Actions
  • Loading branch information
arunsathiya committed Dec 27, 2023
2 parents e17a07c + 9f09f98 commit 9973487
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Go Test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
diff:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- id: set-matrix
run: |
changed_dirs=$(git diff --name-only origin/${{ github.base_ref }} | grep '.go$' | xargs -I {} dirname {} | uniq | awk '{print "\"" $0 "\""}' | jq -R -s -c 'split("\n")[:-1]')
echo "Changed directories: $changed_dirs"
echo "matrix=$changed_dirs" >> $GITHUB_OUTPUT
test:
needs: diff
runs-on: ubuntu-latest
if: needs.diff.outputs.matrix != '[]'
strategy:
fail-fast: false
matrix:
dir: ${{fromJson(needs.diff.outputs.matrix)}}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "^1.12.1"
- name: Run tests in changed directories
run: |
for dir in "${{ matrix.dir }}"; do
if [ -d "$dir" ]; then
echo "Running tests in $dir"
(cd "$dir" && go test ./...)
else
echo "No Go files in $dir"
fi
done
test-main:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "^1.12.1"
- name: Run tests
run: go test ./...

0 comments on commit 9973487

Please sign in to comment.