Skip to content

Commit

Permalink
feat: skip tests if no code changes
Browse files Browse the repository at this point in the history
Signed-off-by: Michele Palazzi <sysdadmin@m1k.cloud>
  • Loading branch information
ironashram committed Feb 23, 2024
1 parent 3a4ba78 commit a1c2e36
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/go-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ name: Go unit tests
on:
pull_request:
types: [ opened, edited, reopened, synchronize ]
paths:
- 'src/**'
push:
branches:
- master
paths:
- 'src/**'
workflow_dispatch:

jobs:
Expand All @@ -15,16 +19,28 @@ jobs:
go-version: [ 1.21.x, 1.22.x ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
env:
SKIP: 0

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check for changes in src
id: changes
run: |
if git diff --quiet HEAD^ HEAD -- ./src; then
echo "SKIP=1" >> $GITHUB_ENV
fi
- name: Install Go
if: env.SKIP == '0'
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4

- name: Restore cache
if: env.SKIP == '0'
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
Expand All @@ -33,6 +49,7 @@ jobs:
${{ runner.os }}-go-
- name: Gofmt
if: env.SKIP == '0' && matrix.os == 'ubuntu-latest'
working-directory: ${{ github.workspace }}/src
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ];
Expand All @@ -41,12 +58,13 @@ jobs:
git diff
exit 1
fi
if: matrix.os == 'ubuntu-latest'
- name: Build
if: env.SKIP == '0'
working-directory: ${{ github.workspace }}/src
run: go build -v ./...

- name: Test
if: env.SKIP == '0'
working-directory: ${{ github.workspace }}/src
run: go test -v ./...

0 comments on commit a1c2e36

Please sign in to comment.