Skip to content

refactor: Move e2e tests to /test directory #417

refactor: Move e2e tests to /test directory

refactor: Move e2e tests to /test directory #417

Workflow file for this run

name: Build, Lint, and Test
# This workflow
# - builds the code
# - runs the unit tests
# - runs the linter
# - reports the code coverage and linting errors to Sonar
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
merge_group: # run if triggered as part of a merge queue
schedule:
# this is checking periodically if there are any breaking API changes
# Every day at 00:00
- cron: '0 0 * * *'
defaults:
run:
shell: bash
jobs:
build_test:
name: Build and Test
permissions:
contents: read
checks: write
runs-on: ubuntu-latest
steps:
- name: ⬇️ Check out code into the Go module directory
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
- name: 🛠️ Set up Go 1.x
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 #v5.5.0
with:
go-version-file: go.mod
- name: 🏗️ Compile
run: make compile
- name: 🚀 Binary starts
run: go run ./cmd/monaco
- name: 🛠️ Generate mocks
run: make mocks
- name: Install gotestsum
run: go install gotest.tools/gotestsum@3f7ff0ec4aeb6f95f5d67c998b71f272aa8a8b41 #v1.12.1
- name: 🧪 Unit test with coverage
# the coverage name has to match the one specified in "sonar-project.properties" and in the upload artifact step
run: gotestsum --format testdox --format-icons hivis -- -coverprofile=cov.out -tags=unit -v -race ./...
- name: ⬆️ Archive code coverage results
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4.6.2
with:
name: code-coverage-report
path: cov.out
lint:
name: Run Static Code Analysis
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
steps:
- name: ⬇️ Check out code into the Go module directory
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
- name: 🛠️ Set up Go 1.x
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 #v5.5.0
with:
go-version-file: go.mod
- name: ✍️ Check format
run: make lint
- name: 🕵️ Go vet
run: make vet
- name: 🔎 golangci-lint
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 #v8.0.0
with:
install-mode: 'goinstall' # install mode goinstall in order to use hashes for the version
version: eabc2638a66daf5bb6c6fb052a32fa3ef7b6600d #v2.1.6
args: '--output.checkstyle.path=lint-report.xml --issues-exit-code=0' # if issues are found, don't exit with "1". Sonar decides if it fails or not
- name: ⬆️ Archive lint results
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4.6.2
with:
name: lint-report
path: lint-report.xml
sonar_scan:
name: Report lint and test coverage
if: ${{ always() }} # always runs after lint and test have completed, regardless of whether they were successful
needs: [build_test, lint]
permissions:
contents: read
checks: write
runs-on: ubuntu-latest
steps:
- name: ⬇️ Check out code into the Go module directory
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
with:
# Disabling shallow clones is recommended for improving the relevancy of reporting
fetch-depth: 0
- name: ⬇️ Download coverage artifact
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 #v4.3.0
with:
name: code-coverage-report
- name: ⬇️ Download lint artifact
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 #v4.3.0
with:
name: lint-report
- name: 🏷️ Get latest tag
id: get_latest_tag
run: |
echo "GIT_TAG=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT"
- name: 🔍 SonarQube Scan
uses: SonarSource/sonarqube-scan-action@2500896589ef8f7247069a56136f8dc177c27ccf # nosemgrep false detection of commit v5.2.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: |
-Dsonar.projectVersion=${{steps.get_latest_tag.outputs.GIT_TAG}}