GitHub Actions: adjust unit tests for fork PRs #19048
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: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
unit: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: styfle/[email protected] | |
- uses: actions/setup-go@v1 | |
with: | |
go-version: '1.18.x' | |
- name: Cache Golang Packages | |
uses: actions/cache@v1 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-golang-${{ hashFiles('go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-golang- | |
- name: checkout | |
uses: actions/checkout@v3 | |
- name: Read Code Climate Reporter ID | |
id: cc_reporter_id | |
env: | |
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_REPORTER_ID }} | |
run: echo "cc_reporter_id=${{ env.CC_TEST_REPORTER_ID }}" >> "GITHUB_OUTPUT" | |
- name: unit-test | |
if: steps.cc_reporter_id.outputs.cc_reporter_id != null | |
uses: paambaati/codeclimate-action@v4 | |
env: | |
CC_TEST_REPORTER_ID: ${{ steps.cc_reporter_id.outputs.cc_reporter_id }} | |
with: | |
coverageCommand: go test -tags=unit ./... -coverprofile cover.out | |
coverageLocations: cover.out:gocov | |
# truncate package name from file paths in report | |
prefix: github.com/SAP/jenkins-library/ | |
- name: unit-test (for fork PR) | |
if: steps.cc_reporter_id.outputs.cc_reporter_id == null | |
run: go test -tags=unit ./... | |
format: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-go@v1 | |
with: | |
go-version: '1.18.x' | |
- name: Cache Golang Packages | |
uses: actions/cache@v1 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-golang-format${{ hashFiles('go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-golang-format | |
${{ runner.os }}-golang- | |
- name: checkout | |
uses: actions/checkout@v3 | |
- name: format | |
run: go fmt ./... | |
- name: verify | |
run: git diff --exit-code | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-go@v1 | |
with: | |
go-version: '1.19.x' | |
# action requires [email protected] | |
- name: checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 | |
- name: staticcheck | |
uses: dominikh/[email protected] | |
with: | |
cache-key: ${{ runner.os }}-golang-staticcheck | |
install-go: false | |
generate: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-go@v1 | |
with: | |
go-version: '1.18.x' | |
- name: Cache Golang Packages | |
uses: actions/cache@v1 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-golang-generate${{ hashFiles('go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-golang-generate | |
${{ runner.os }}-golang- | |
- name: checkout | |
uses: actions/checkout@v3 | |
- name: generate | |
run: go run pkg/generator/step-metadata.go | |
- name: verify | |
run: git diff --exit-code | |
dependencies: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-go@v1 | |
with: | |
go-version: '1.18.x' | |
- name: Cache Golang Packages | |
uses: actions/cache@v1 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-golang-dependencies${{ hashFiles('go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-golang-dependencies | |
${{ runner.os }}-golang- | |
- name: checkout | |
uses: actions/checkout@v3 | |
- name: cleanup dependencies | |
run: go mod tidy | |
- name: verify | |
run: git diff --name-only --exit-code |