Skip to content

Commit

Permalink
Add go-test action for SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilken Rivera committed Mar 7, 2023
1 parent 2085e33 commit a124fa7
Showing 1 changed file with 136 additions and 0 deletions.
136 changes: 136 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: go-test

on:
push:
branches:
- main
pull_request:
branches:
- main


env:
TEST_RESULTS_PATH: /tmp/test-results

jobs:

linux-tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.18
- 1.19
directory:
- .
permissions:
id-token: write
contents: read
steps:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

- name: Create test directory
run: |
mkdir -p ${{ env.TEST_RESULTS_PATH }}/packer-plugin-sdk
- name: Setup cache for go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download go modules
run: go mod download

- name: Run gofmt
run: |
make fmt-check
- name: Run Go Generate Check
run: |
make generate-check
- name: Install gotestsum
run: go install gotest.tools/[email protected]

- name: Run Go tests
working-directory: ${{ matrix.directory }}
run: |
PACKAGE_NAMES=$(go list ./...)
echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
echo $PACKAGE_NAMES
gotestsum --format=short-verbose --junitfile $TEST_RESULTS_PATH/packer-plugin-sdk/gotestsum-report.xml -- -p 2 $PACKAGE_NAMES
# Save coverage report parts
- name: Upload and save artifacts
uses: actions/upload-artifact@v3
with:
name: linux test results
path: ${{ env.TEST_RESULTS_PATH }}

windows-tests:
runs-on: windows-latest
strategy:
matrix:
go-version:
- 1.18
- 1.19
directory:
- .
permissions:
id-token: write
contents: read
steps:
- name: Run git config #Windows-only
run: git config --global core.autocrlf false

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

- name: Setup cache for go modules
uses: actions/cache@v3
with:
path: |
~\AppData\Local\go-build
~\go\pkg\mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download go modules
run: go mod download

- name: Install gotestsum
shell: bash
run: go install gotest.tools/[email protected]

- name: Run Go tests
shell: bash
working-directory: ${{ matrix.directory }}
run: |
PACKAGE_NAMES=$(go list ./...)
echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
echo $PACKAGE_NAMES
gotestsum --format=short-verbose --junitfile $TEST_RESULTS_PATH/packer-plugin-sdk/gotestsum-report.xml -- -p 2 $PACKAGE_NAMES
# Save coverage report parts
- name: Upload and save artifacts
uses: actions/upload-artifact@v3
with:
name: windows test results
path: ${{ env.TEST_RESULTS_PATH }}

0 comments on commit a124fa7

Please sign in to comment.