2023-03-28 21:29:27 +00:00
|
|
|
name: reusable-unit-split
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
directory:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
runs-on:
|
|
|
|
description: An expression indicating which kind of runners to use.
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
go-arch:
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
default: ""
|
|
|
|
uploaded-binary-name:
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
default: "consul-bin"
|
|
|
|
args:
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
default: ""
|
|
|
|
runner-count:
|
|
|
|
required: false
|
|
|
|
type: number
|
|
|
|
default: 1
|
|
|
|
go-test-flags:
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
default: ""
|
2023-03-30 16:57:11 +00:00
|
|
|
repository-name:
|
|
|
|
required: true
|
|
|
|
type: string
|
2023-04-05 22:49:48 +00:00
|
|
|
go-tags:
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
default: ""
|
2023-03-30 16:57:11 +00:00
|
|
|
secrets:
|
|
|
|
elevated-github-token:
|
|
|
|
required: true
|
|
|
|
consul-license:
|
|
|
|
required: true
|
2023-05-10 20:49:18 +00:00
|
|
|
datadog-api-key:
|
|
|
|
required: true
|
2023-03-28 21:29:27 +00:00
|
|
|
env:
|
|
|
|
TEST_RESULTS: /tmp/test-results
|
2023-07-12 00:13:54 +00:00
|
|
|
GOTESTSUM_VERSION: "1.10.1"
|
2023-03-28 21:29:27 +00:00
|
|
|
GOARCH: ${{inputs.go-arch}}
|
|
|
|
TOTAL_RUNNERS: ${{inputs.runner-count}}
|
2023-03-30 16:57:11 +00:00
|
|
|
CONSUL_LICENSE: ${{secrets.consul-license}}
|
2023-04-05 22:49:48 +00:00
|
|
|
GOTAGS: ${{ inputs.go-tags}}
|
2023-06-21 15:26:27 +00:00
|
|
|
GOPRIVATE: github.com/hashicorp # Required for enterprise deps
|
2023-05-10 20:49:18 +00:00
|
|
|
DATADOG_API_KEY: ${{secrets.datadog-api-key}}
|
2023-03-28 21:29:27 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
set-test-package-matrix:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
|
|
package-matrix: ${{ steps.set-matrix.outputs.matrix }}
|
|
|
|
steps:
|
2023-07-19 23:56:50 +00:00
|
|
|
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
2023-06-13 17:00:55 +00:00
|
|
|
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
|
2023-03-28 21:29:27 +00:00
|
|
|
with:
|
|
|
|
go-version-file: 'go.mod'
|
|
|
|
- id: set-matrix
|
|
|
|
run: ./.github/scripts/set_test_package_matrix.sh ${{env.TOTAL_RUNNERS}}
|
|
|
|
|
|
|
|
go-test:
|
|
|
|
runs-on: ${{ fromJSON(inputs.runs-on) }}
|
|
|
|
name: "go-test"
|
|
|
|
needs:
|
|
|
|
- set-test-package-matrix
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
package: ${{ fromJson(needs.set-test-package-matrix.outputs.package-matrix) }}
|
|
|
|
steps:
|
|
|
|
- name: ulimit
|
|
|
|
run: |
|
|
|
|
echo "Soft limits"
|
|
|
|
ulimit -Sa
|
|
|
|
echo "Hard limits"
|
|
|
|
ulimit -Ha
|
2023-07-19 23:56:50 +00:00
|
|
|
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
2023-03-30 16:57:11 +00:00
|
|
|
# NOTE: This step is specifically needed for ENT. It allows us to access the required private HashiCorp repos.
|
|
|
|
- name: Setup Git
|
|
|
|
if: ${{ endsWith(inputs.repository-name, '-enterprise') }}
|
|
|
|
run: git config --global url."https://${{ secrets.elevated-github-token }}:@github.com".insteadOf "https://github.com"
|
2023-06-13 17:00:55 +00:00
|
|
|
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
|
2023-03-28 21:29:27 +00:00
|
|
|
with:
|
|
|
|
go-version-file: 'go.mod'
|
|
|
|
cache: true
|
|
|
|
- run: mkdir -p ${{env.TEST_RESULTS}}
|
|
|
|
- name: go mod download
|
|
|
|
working-directory: ${{inputs.directory}}
|
|
|
|
run: go mod download
|
|
|
|
- name: Download consul
|
2023-06-13 17:00:55 +00:00
|
|
|
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
|
2023-03-28 21:29:27 +00:00
|
|
|
with:
|
|
|
|
name: ${{inputs.uploaded-binary-name}}
|
2023-03-30 16:57:11 +00:00
|
|
|
path: ${{inputs.directory}}
|
|
|
|
- name: Display downloaded file
|
|
|
|
run: ls -ld consul
|
|
|
|
working-directory: ${{inputs.directory}}
|
|
|
|
- run: echo "$GITHUB_WORKSPACE/${{inputs.directory}}" >> $GITHUB_PATH
|
2023-03-28 21:29:27 +00:00
|
|
|
- name: Make sure consul is executable
|
2023-03-30 16:57:11 +00:00
|
|
|
run: chmod +x $GITHUB_WORKSPACE/${{inputs.directory}}/consul
|
2023-03-28 21:29:27 +00:00
|
|
|
- run: go env
|
|
|
|
- name: Run tests
|
|
|
|
working-directory: ${{inputs.directory}}
|
|
|
|
run: |
|
|
|
|
# separate the list
|
|
|
|
PACKAGE_NAMES="${{ join(matrix.package, ' ') }}"
|
|
|
|
# PACKAGE_NAMES="${{ matrix.package }}"
|
|
|
|
|
|
|
|
${{inputs.go-test-flags}}
|
|
|
|
|
|
|
|
# some tests expect this umask, and arm images have a different default
|
|
|
|
umask 0022
|
|
|
|
|
2023-03-30 16:57:11 +00:00
|
|
|
go run gotest.tools/gotestsum@v${{env.GOTESTSUM_VERSION}} \
|
2023-03-28 21:29:27 +00:00
|
|
|
--format=short-verbose \
|
|
|
|
--jsonfile /tmp/jsonfile/go-test.log \
|
|
|
|
--debug \
|
|
|
|
--rerun-fails=3 \
|
|
|
|
--rerun-fails-max-failures=40 \
|
|
|
|
--rerun-fails-report=/tmp/gotestsum-rerun-fails \
|
|
|
|
--packages="$PACKAGE_NAMES" \
|
|
|
|
--junitfile ${{env.TEST_RESULTS}}/gotestsum-report.xml -- \
|
2023-10-03 14:11:47 +00:00
|
|
|
-tags="${{env.GOTAGS}}" \
|
2023-10-27 23:33:54 +00:00
|
|
|
-cover -coverprofile=coverage.txt \
|
|
|
|
-timeout=30m
|
2023-05-10 20:49:18 +00:00
|
|
|
|
|
|
|
# NOTE: ENT specific step as we store secrets in Vault.
|
|
|
|
- name: Authenticate to Vault
|
|
|
|
if: ${{ endsWith(github.repository, '-enterprise') }}
|
|
|
|
id: vault-auth
|
|
|
|
run: vault-auth
|
|
|
|
|
|
|
|
# NOTE: ENT specific step as we store secrets in Vault.
|
|
|
|
- name: Fetch Secrets
|
|
|
|
if: ${{ endsWith(github.repository, '-enterprise') }}
|
|
|
|
id: secrets
|
|
|
|
uses: hashicorp/vault-action@v2.5.0
|
|
|
|
with:
|
|
|
|
url: ${{ steps.vault-auth.outputs.addr }}
|
|
|
|
caCertificate: ${{ steps.vault-auth.outputs.ca_certificate }}
|
|
|
|
token: ${{ steps.vault-auth.outputs.token }}
|
|
|
|
secrets: |
|
|
|
|
kv/data/github/${{ github.repository }}/datadog apikey | DATADOG_API_KEY;
|
|
|
|
|
|
|
|
- name: prepare datadog-ci
|
|
|
|
if: ${{ !endsWith(github.repository, '-enterprise') }}
|
|
|
|
run: |
|
|
|
|
curl -L --fail "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_linux-x64" --output "/usr/local/bin/datadog-ci"
|
|
|
|
chmod +x /usr/local/bin/datadog-ci
|
|
|
|
|
|
|
|
- name: upload coverage
|
2023-05-24 18:57:49 +00:00
|
|
|
# do not run on forks
|
|
|
|
if: ${{ env.DATADOG_API_KEY}}
|
2023-05-10 20:49:18 +00:00
|
|
|
env:
|
|
|
|
DD_ENV: ci
|
|
|
|
run: datadog-ci junit upload --service "$GITHUB_REPOSITORY" ${{env.TEST_RESULTS}}/gotestsum-report.xml
|
|
|
|
|
2023-06-13 17:00:55 +00:00
|
|
|
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
2023-03-28 21:29:27 +00:00
|
|
|
with:
|
|
|
|
name: test-results
|
|
|
|
path: ${{env.TEST_RESULTS}}
|
2023-06-13 17:00:55 +00:00
|
|
|
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
2023-03-28 21:29:27 +00:00
|
|
|
with:
|
|
|
|
name: jsonfile
|
|
|
|
path: /tmp/jsonfile
|
|
|
|
- name: "Re-run fails report"
|
|
|
|
run: |
|
|
|
|
.github/scripts/rerun_fails_report.sh /tmp/gotestsum-rerun-fails
|