Skip to content

[IBM] restructure plugin and minor updates. #980

[IBM] restructure plugin and minor updates.

[IBM] restructure plugin and minor updates. #980

Workflow file for this run

name: Build and Test
on:
push:
branches:
- main
- release/*
tags:
- v*
paths-ignore:
- 'docs/**'
pull_request:
branches:
- main
- features/*
- release/*
paths-ignore:
- 'docs/**'
concurrency:
# Cancel the previously triggered build for only PR build.
group: build-${{ github.ref }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
env:
# Go version to install
GOVER: '^1.22'
GOPROXY: https://proxy.golang.org
# gotestsum version - see: https://github.com/gotestyourself/gotestsum
GOTESTSUMVERSION: 1.10.0
# github contexts
GH_RUN_ID: ${{ github.run_id }}
GH_RUN_NUMBER: ${{ github.run_number }}
GH_RUN_ATTEMPT: ${{ github.run_attempt }}
# Cloud account fields
INVISINETS_GCP_PROJECT_PARENT: ${{ secrets.GCP_FOLDER_ID }}
INVISINETS_GCP_PROJECT_BILLING_ACCOUNT_NAME: ${{ secrets.GCP_BILLING_ACCOUNT_NAME }}
INVISINETS_AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
jobs:
build:
name: Build ${{ matrix.target_os }}_${{ matrix.target_arch }} binaries
runs-on: ubuntu-latest
env:
GOOS: ${{ matrix.target_os }}
GOARCH: ${{ matrix.target_arch }}
GOPROXY: https://proxy.golang.org
strategy:
fail-fast: false
matrix:
include:
- target_os: linux
target_arch: arm
- target_os: linux
target_arch: arm64
- target_os: linux
target_arch: amd64
- target_os: windows
target_arch: amd64
- target_os: darwin
target_arch: amd64
- target_os: darwin
target_arch: arm64
permissions:
checks: write
contents: read
id-token: write
issues: read
pull-requests: write
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Set up Go ${{ env.GOVER }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOVER }}
- name: Get Go Cache path
id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: |
${{ steps.go-cache-paths.outputs.go-build }}
${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Restore the previous coverage
uses: actions/cache/restore@v4
with:
path: ./dist/cache
key: code-coverage-
- name: Parse release version and set environment variables
run: python ./.github/scripts/get_release_version.py
- name: Get protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get protoc-gen-go
run: |
GOOS=$(go env GOHOSTOS) GOARCH=$(go env GOHOSTARCH) go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
GOOS=$(go env GOHOSTOS) GOARCH=$(go env GOHOSTARCH) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
- name: Make build
run: |
make build
- name: Run linter
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
uses: golangci/golangci-lint-action@v6
with:
version: 'latest'
args: --timeout=10m
- name: Run make test (unit tests)
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
env:
GOTESTSUM_OPTS: '--junitfile ./dist/unit_test/results.xml'
GOTEST_OPTS: '-race -coverprofile ./dist/unit_test/coverage_original.out'
run: |
go install gotest.tools/gotestsum@v${{ env.GOTESTSUMVERSION }}
mkdir -p ./dist/unit_test
make test
# The test results file output by gotestsum is missing file and line number on the XML elements
# which is needed for the annotations to work. This script adds the missing information.
- name: 'Transform unit test results'
# Always is REQUIRED here. Otherwise, the action will be skipped when the unit tests fail, which
# defeats the purpose. YES it is counterintuitive. This applies to all of the actions in this file.
if: always() && matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
id: 'process_files'
shell: 'bash'
working-directory: ${{ github.workspace }}
env:
INPUT_DIRECTORY: ./dist/unit_test/
run: |
echo "repository root is $GITHUB_WORKSPACE"
INPUT_FILES="$INPUT_DIRECTORY*.xml"
mkdir -p "$INPUT_DIRECTORY/processed"
for INPUT_FILE in $INPUT_FILES
do
DIRECTORY=$(dirname -- "$INPUT_FILE")
FILENAME=$(basename -- "$INPUT_FILE")
FILENAME="${FILENAME%.*}"
OUTPUT_FILE="${DIRECTORY}/processed/${FILENAME}.xml"
echo "processing test results in $INPUT_FILE to add line and file info..."
python3 ./.github/scripts/transform_test_results.py $GITHUB_WORKSPACE "$INPUT_FILE" "$OUTPUT_FILE"
echo "wrote ${OUTPUT_FILE}"
done
- name: 'Create unit test result report'
uses: EnricoMi/publish-unit-test-result-action@v2
if: always() && matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
with:
check_name: 'Unit Test Results'
files: |
./dist/unit_test/processed/*.xml
- name: 'Upload unit test results'
uses: actions/upload-artifact@v4
if: always() && matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
with:
name: unit_test_results
path: |
./dist/unit_test/*.xml
./dist/unit_test/processed/*.xml
- name: Generate unit-test coverage files
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
run: |
# Remove mock, generated files, and datamodels from original coverage output.
cat ./dist/unit_test/coverage_original.out | grep -v "mock" | grep -v "zz_" > $COVERAGE_FILE
# Generate reports.
$GO_TOOL_COVER -func=$COVERAGE_FILE -o ./dist/unit_test/coverage.txt
$GO_TOOL_COVER -html=$COVERAGE_FILE -o ./dist/unit_test/coverage.html
# Parse total coverage rate from report.
UT_COVERAGE=`cat ./dist/unit_test/coverage.txt | grep total: | grep -Eo '[0-9]+\.[0-9]+'`
echo "Test coverage : $UT_COVERAGE"
echo "ut_coverage=$UT_COVERAGE" >> $GITHUB_ENV
mkdir -p ./dist/cache
MAIN_COVERAGE=0
if [ -f "./dist/cache/ut_coverage.txt" ]; then
MAIN_COVERAGE=$(cat ./dist/cache/ut_coverage.txt | grep total: | grep -Eo '[0-9]+\.[0-9]+')
fi
echo "main_coverage=$MAIN_COVERAGE" >> $GITHUB_ENV
if (( $(echo "$UT_COVERAGE < $MAIN_COVERAGE" | bc -l) )) ; then
COLOR=red
else
COLOR=green
fi
DIFF_RATE=$(echo "$UT_COVERAGE-$MAIN_COVERAGE" | bc -l)
echo "diff_coverage=$DIFF_RATE" >> $GITHUB_ENV
echo "coverage_img=https://img.shields.io/badge/coverage-$UT_COVERAGE%25-$COLOR" >> $GITHUB_ENV
# copy coverage to cache
cp ./dist/unit_test/coverage.txt ./dist/cache/
env:
COVERAGE_FILE: ./dist/unit_test/coverage.out
GO_TOOL_COVER: go tool cover
- name: Upload unit-test coverage artifact
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
uses: actions/upload-artifact@v4
with:
name: unit_test_coverage
path: |
./dist/unit_test/coverage_original.out
./dist/unit_test/coverage.out
./dist/unit_test/coverage.txt
./dist/unit_test/coverage.html
- name: Add coverage result comment
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux' && github.event.pull_request && github.event.pull_request.head.repo.full_name == github.repository
uses: marocchino/sticky-pull-request-comment@v2
with:
header: testcov-${{ github.run_id }}
number: ${{ github.event.pull_request.number }}
hide: true
hide_classify: OUTDATED
message: |
![${{ env.ut_coverage }}](${{ env.coverage_img }})
For the detailed report, please go to `Checks tab`, click `Build and Test`, and then download `unit_test_coverage` artifact at the bottom of build page.
* Your PR branch coverage: ${{ env.ut_coverage }} %
* main branch coverage: ${{ env.main_coverage }} %
* diff coverage: ${{ env.diff_coverage }} %
> The coverage result does not include the functional test results.
- name: Save coverage (only main push)
uses: actions/cache/save@v4
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux' && github.ref == 'refs/heads/main'
with:
path: ./dist/cache
key: code-coverage-${{ github.sha }}-${{ github.run_number }}
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
with:
workload_identity_provider: 'projects/112338121957/locations/global/workloadIdentityPools/github/providers/paraglider'
service_account: 'invisinets-cicd@invisinets-cicd.iam.gserviceaccount.com'
- name: 'Az CLI login'
uses: azure/login@v2
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Run integration tests
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
run: |
make integration-test
- name: Run multicloud tests
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
run: |
make multicloud-test