Awk grains #658
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
--- | |
# | |
# .github/workflows/go.yml | |
# | |
name: Go Workflow | |
on: # yamllint disable-line rule:truthy | |
pull_request: | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
stage1: | |
name: Change Check | |
runs-on: 'ubuntu-latest' | |
outputs: | |
docs_changed: ${{ steps.check_file_changed.outputs.docs_changed }} | |
steps: | |
- name: Checkout Repo | |
id: checkout-repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.ref }} | |
submodules: recursive | |
- name: Get Change List | |
id: check_file_changed | |
run: | | |
# Diff HEAD with the previous commit then output to stdout. | |
printf "=== Which files changed? ===\n" | |
GIT_DIFF="$(git diff --name-only HEAD^ HEAD)" | |
printf "%s\n" "${GIT_DIFF}" | |
printf "\n" | |
# Check if the files are present in the changed file list (added, modified, deleted) then output to stdout. | |
HAS_DIFF=false | |
printf "=== Which Golang files changed? ===\n" | |
if printf "%s\n" "${GIT_DIFF}" | grep -E '^(go/.*[.]go|go/.*/go[.](sum|mod)|.github/workflows/go.yml)'; then | |
HAS_DIFF=true | |
fi | |
printf "\n" | |
# Did Golang files change? | |
printf "=== Did Golang files change? ===\n" | |
printf "%s\n" "${HAS_DIFF}" | |
printf "\n" | |
# Set the output named "docs_changed" | |
printf "%s=%s\n" "docs_changed" "${HAS_DIFF}" >> "${GITHUB_OUTPUT}" | |
stage2: | |
name: Go Checks | |
strategy: | |
matrix: | |
go-version: ["1.19"] | |
os: ["ubuntu-latest", "windows-latest", "macos-latest"] | |
exclude: | |
- os: "macos-latest" | |
go-version: "1.19" | |
- os: "windows-latest" | |
go-version: "1.19" | |
runs-on: "${{ matrix.os }}" | |
needs: [stage1] | |
if: needs.stage1.outputs.docs_changed == 'True' | |
steps: | |
- name: Checkout Repo | |
id: checkout-repo | |
uses: actions/checkout@v3 | |
- name: Set up Go ${{ matrix.go-version }} | |
id: setup-go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: Show Go version | |
id: go-version | |
run: | | |
go version | |
- name: Install Go Tools | |
id: install-go-tools | |
run: | | |
go install golang.org/x/lint/golint@latest | |
go install golang.org/x/tools/cmd/cover@latest | |
go install github.com/securego/gosec/v2/cmd/gosec@latest | |
go install github.com/rakyll/gotest@latest | |
- name: CD to Go Dir | |
id: cd-to-go-dir | |
run: | | |
pwd | |
ls | |
cd ./go | |
pwd | |
ls | |
- name: Analysing the code with golint | |
id: golint | |
run: | | |
cd ./go | |
./for_each golint -set_exit_status pkg_name | |
- name: Analysing the code with go vet | |
id: go-vet | |
run: | | |
cd ./go | |
./for_each go vet pkg_name | |
- name: Testing with gotest | |
id: go-test-run | |
run: | | |
cd ./go | |
./for_each gotest -v -covermode=count -coverprofile coverage.out pkg_name | |
- name: Testing with go test coverage | |
id: go-test-coverage | |
run: | | |
cd ./go | |
./for_each go tool cover -func=coverage.out | |
git restore ./*/coverage.out | |
- name: Testing with gosec | |
id: go-test-security | |
run: |- | |
cd ./go | |
gosec ./... |