2023-03-06 21:57:55 +00:00
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
go-arch:
|
|
|
|
description: The execution architecture (arm, amd64, etc.)
|
|
|
|
required: true
|
|
|
|
type: string
|
2023-03-24 17:17:21 +00:00
|
|
|
enterprise:
|
|
|
|
description: A flag indicating if this workflow is executing for the enterprise repository.
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
total-runners:
|
2023-07-20 13:07:20 +00:00
|
|
|
description: Number of runners to use for executing non-binary tests.
|
2023-03-24 17:17:21 +00:00
|
|
|
required: true
|
|
|
|
type: string
|
2023-07-20 13:07:20 +00:00
|
|
|
binary-tests:
|
|
|
|
description: Whether to run the binary tests.
|
|
|
|
required: false
|
|
|
|
default: false
|
2023-07-20 22:39:29 +00:00
|
|
|
type: boolean
|
2023-03-24 17:17:21 +00:00
|
|
|
env-vars:
|
|
|
|
description: A map of environment variables as JSON.
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
default: '{}'
|
2023-03-21 18:13:40 +00:00
|
|
|
extra-flags:
|
|
|
|
description: A space-separated list of additional build flags.
|
2023-03-06 21:57:55 +00:00
|
|
|
required: false
|
|
|
|
type: string
|
2023-04-24 13:57:37 +00:00
|
|
|
default: ''
|
2023-03-06 21:57:55 +00:00
|
|
|
runs-on:
|
|
|
|
description: An expression indicating which kind of runners to use.
|
|
|
|
required: false
|
|
|
|
type: string
|
|
|
|
default: ubuntu-latest
|
2023-07-12 19:26:00 +00:00
|
|
|
go-tags:
|
2023-04-03 14:26:55 +00:00
|
|
|
description: A comma-separated list of additional build tags to consider satisfied during the build.
|
|
|
|
required: false
|
|
|
|
type: string
|
2023-07-05 21:19:49 +00:00
|
|
|
name:
|
|
|
|
description: A suffix to append to archived test results
|
|
|
|
required: false
|
|
|
|
default: ''
|
|
|
|
type: string
|
|
|
|
go-test-parallelism:
|
|
|
|
description: The parallelism parameter for Go tests
|
|
|
|
required: false
|
|
|
|
default: 20
|
|
|
|
type: number
|
|
|
|
timeout-minutes:
|
2023-07-07 17:52:01 +00:00
|
|
|
description: The maximum number of minutes that this workflow should run
|
2023-07-05 21:19:49 +00:00
|
|
|
required: false
|
2023-07-07 17:52:01 +00:00
|
|
|
default: 60
|
2023-07-05 21:19:49 +00:00
|
|
|
type: number
|
2023-10-03 13:29:31 +00:00
|
|
|
checkout-ref:
|
|
|
|
description: The ref to use for checkout.
|
|
|
|
required: false
|
2023-10-03 17:47:44 +00:00
|
|
|
default: ${{ github.ref }}
|
2023-10-03 13:29:31 +00:00
|
|
|
type: string
|
2023-07-05 21:19:49 +00:00
|
|
|
|
2023-03-24 17:17:21 +00:00
|
|
|
env: ${{ fromJSON(inputs.env-vars) }}
|
2023-03-06 21:57:55 +00:00
|
|
|
|
|
|
|
jobs:
|
2023-07-13 15:23:53 +00:00
|
|
|
test-matrix:
|
2023-06-16 17:10:36 +00:00
|
|
|
permissions:
|
|
|
|
id-token: write # Note: this permission is explicitly required for Vault auth
|
|
|
|
contents: read
|
2023-07-13 15:23:53 +00:00
|
|
|
runs-on: ${{ fromJSON(inputs.runs-on) }}
|
2023-03-06 21:57:55 +00:00
|
|
|
steps:
|
2023-07-07 17:52:01 +00:00
|
|
|
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
2023-10-03 13:29:31 +00:00
|
|
|
with:
|
|
|
|
ref: ${{ inputs.checkout-ref }}
|
2023-07-12 19:26:00 +00:00
|
|
|
- uses: ./.github/actions/set-up-go
|
2023-07-07 17:52:01 +00:00
|
|
|
with:
|
2023-07-12 19:26:00 +00:00
|
|
|
github-token: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
|
2023-07-07 17:52:01 +00:00
|
|
|
- name: Authenticate to Vault
|
|
|
|
id: vault-auth
|
|
|
|
if: github.repository == 'hashicorp/vault-enterprise'
|
|
|
|
run: vault-auth
|
|
|
|
- name: Fetch Secrets
|
|
|
|
id: secrets
|
|
|
|
if: github.repository == 'hashicorp/vault-enterprise'
|
|
|
|
uses: hashicorp/vault-action@130d1f5f4fe645bb6c83e4225c04d64cfb62de6e
|
|
|
|
with:
|
|
|
|
url: ${{ steps.vault-auth.outputs.addr }}
|
|
|
|
caCertificate: ${{ steps.vault-auth.outputs.ca_certificate }}
|
|
|
|
token: ${{ steps.vault-auth.outputs.token }}
|
|
|
|
secrets: |
|
2023-07-13 15:23:53 +00:00
|
|
|
kv/data/github/${{ github.repository }}/datadog-ci DATADOG_API_KEY;
|
2023-07-07 17:52:01 +00:00
|
|
|
kv/data/github/${{ github.repository }}/github-token username-and-token | github-token;
|
2023-07-13 15:23:53 +00:00
|
|
|
kv/data/github/${{ github.repository }}/license license_1 | VAULT_LICENSE_CI;
|
|
|
|
kv/data/github/${{ github.repository }}/license license_2 | VAULT_LICENSE_2;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_API_ADDRESS;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_AUTH_URL;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_CLIENT_ID;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_CLIENT_SECRET;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_RESOURCE_ID;
|
2023-07-07 17:52:01 +00:00
|
|
|
- id: setup-git-private
|
|
|
|
name: Setup Git configuration (private)
|
|
|
|
if: github.repository == 'hashicorp/vault-enterprise'
|
|
|
|
run: |
|
|
|
|
git config --global url."https://${{ steps.secrets.outputs.github-token }}@github.com".insteadOf https://github.com
|
|
|
|
- id: setup-git-public
|
|
|
|
name: Setup Git configuration (public)
|
|
|
|
if: github.repository != 'hashicorp/vault-enterprise'
|
|
|
|
run: |
|
|
|
|
git config --global url."https://${{ secrets.ELEVATED_GITHUB_TOKEN}}@github.com".insteadOf https://github.com
|
2023-07-20 22:39:29 +00:00
|
|
|
- uses: ./.github/actions/set-up-gotestsum
|
2023-07-13 15:23:53 +00:00
|
|
|
- run: mkdir -p test-results/go-test
|
2023-07-20 22:39:29 +00:00
|
|
|
- uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
2023-07-13 15:23:53 +00:00
|
|
|
with:
|
|
|
|
path: test-results/go-test
|
2023-07-20 22:39:29 +00:00
|
|
|
key: go-test-reports-${{ github.run_number }}
|
2023-07-13 15:23:53 +00:00
|
|
|
restore-keys: go-test-reports-
|
|
|
|
- name: List cached results
|
|
|
|
id: list-cached-results
|
|
|
|
run: ls -lhR test-results/go-test
|
|
|
|
- name: Build matrix excluding binary and integration tests
|
|
|
|
id: build-non-binary
|
2023-07-07 17:52:01 +00:00
|
|
|
env:
|
|
|
|
GOPRIVATE: github.com/hashicorp/*
|
|
|
|
run: |
|
2023-07-13 15:23:53 +00:00
|
|
|
(
|
|
|
|
go list ./... | grep -v "_binary" | grep -v "vault/integ" | gotestsum tool ci-matrix --debug \
|
2023-07-20 13:07:20 +00:00
|
|
|
--partitions "${{ inputs.total-runners }}" \
|
2023-07-13 15:23:53 +00:00
|
|
|
--timing-files 'test-results/go-test/*.json' > matrix.json
|
|
|
|
)
|
|
|
|
- name: Capture list of binary tests
|
2023-07-20 13:07:20 +00:00
|
|
|
if: inputs.binary-tests
|
2023-07-13 15:23:53 +00:00
|
|
|
id: list-binary-tests
|
2023-07-07 17:52:01 +00:00
|
|
|
run: |
|
2023-07-13 15:23:53 +00:00
|
|
|
LIST="$(go list ./... | grep "_binary" | xargs)"
|
|
|
|
echo "list=$LIST" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build complete matrix
|
|
|
|
id: build
|
|
|
|
run: |
|
2023-07-20 13:07:20 +00:00
|
|
|
set -exo pipefail
|
|
|
|
matrix_file="matrix.json"
|
|
|
|
if [ "${{ inputs.binary-tests}}" == "true" ] && [ -n "${{ steps.list-binary-tests.outputs.list }}" ]; then
|
|
|
|
export BINARY_TESTS="${{ steps.list-binary-tests.outputs.list }}"
|
|
|
|
jq --arg BINARY "${BINARY_TESTS}" --arg BINARY_INDEX "${{ inputs.total-runners }}" \
|
|
|
|
'.include += [{
|
|
|
|
"id": $BINARY_INDEX,
|
|
|
|
"estimatedRuntime": "N/A",
|
|
|
|
"packages": $BINARY,
|
|
|
|
"description": "partition $BINARY_INDEX - binary test packages"
|
|
|
|
}]' matrix.json > new-matrix.json
|
2023-07-20 22:39:29 +00:00
|
|
|
matrix_file="new-matrix.json"
|
2023-07-20 13:07:20 +00:00
|
|
|
fi
|
|
|
|
# convert the json to a map keyed by id
|
|
|
|
(
|
|
|
|
echo -n "matrix="
|
|
|
|
jq -c \
|
2023-07-20 22:39:29 +00:00
|
|
|
'.include | map( { (.id|tostring): . } ) | add' "$matrix_file"
|
2023-07-20 13:07:20 +00:00
|
|
|
) >> "$GITHUB_OUTPUT"
|
|
|
|
# extract an array of ids from the json
|
|
|
|
(
|
|
|
|
echo -n "matrix_ids="
|
|
|
|
jq -c \
|
|
|
|
'[ .include[].id | tostring ]' "$matrix_file"
|
|
|
|
) >> "$GITHUB_OUTPUT"
|
2023-07-13 15:23:53 +00:00
|
|
|
outputs:
|
|
|
|
matrix: ${{ steps.build.outputs.matrix }}
|
2023-07-20 22:39:29 +00:00
|
|
|
matrix_ids: ${{ steps.build.outputs.matrix_ids }}
|
2023-07-13 15:23:53 +00:00
|
|
|
|
2023-03-06 21:57:55 +00:00
|
|
|
test-go:
|
2023-07-13 15:23:53 +00:00
|
|
|
needs: test-matrix
|
2023-03-06 21:57:55 +00:00
|
|
|
permissions:
|
2023-07-17 16:13:15 +00:00
|
|
|
actions: read
|
2023-03-06 21:57:55 +00:00
|
|
|
contents: read
|
2023-07-17 16:13:15 +00:00
|
|
|
id-token: write # Note: this permission is explicitly required for Vault auth
|
2023-03-06 21:57:55 +00:00
|
|
|
runs-on: ${{ fromJSON(inputs.runs-on) }}
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
2023-07-20 22:39:29 +00:00
|
|
|
matrix:
|
2023-07-20 13:07:20 +00:00
|
|
|
id: ${{ fromJSON(needs.test-matrix.outputs.matrix_ids) }}
|
2023-03-06 21:57:55 +00:00
|
|
|
env:
|
|
|
|
GOPRIVATE: github.com/hashicorp/*
|
2023-07-07 17:52:01 +00:00
|
|
|
TIMEOUT_IN_MINUTES: ${{ inputs.timeout-minutes }}
|
2023-03-06 21:57:55 +00:00
|
|
|
steps:
|
2023-07-05 21:19:49 +00:00
|
|
|
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
2023-10-03 13:29:31 +00:00
|
|
|
with:
|
|
|
|
ref: ${{ inputs.checkout-ref }}
|
2023-07-12 19:26:00 +00:00
|
|
|
- uses: ./.github/actions/set-up-go
|
2023-03-06 21:57:55 +00:00
|
|
|
with:
|
2023-07-12 19:26:00 +00:00
|
|
|
github-token: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
|
2023-03-06 21:57:55 +00:00
|
|
|
- name: Authenticate to Vault
|
|
|
|
id: vault-auth
|
|
|
|
if: github.repository == 'hashicorp/vault-enterprise'
|
|
|
|
run: vault-auth
|
|
|
|
- name: Fetch Secrets
|
|
|
|
id: secrets
|
|
|
|
if: github.repository == 'hashicorp/vault-enterprise'
|
|
|
|
uses: hashicorp/vault-action@130d1f5f4fe645bb6c83e4225c04d64cfb62de6e
|
|
|
|
with:
|
|
|
|
url: ${{ steps.vault-auth.outputs.addr }}
|
|
|
|
caCertificate: ${{ steps.vault-auth.outputs.ca_certificate }}
|
|
|
|
token: ${{ steps.vault-auth.outputs.token }}
|
|
|
|
secrets: |
|
2023-03-31 17:15:57 +00:00
|
|
|
kv/data/github/${{ github.repository }}/datadog-ci DATADOG_API_KEY;
|
2023-04-03 14:26:55 +00:00
|
|
|
kv/data/github/${{ github.repository }}/github-token username-and-token | github-token;
|
2023-03-06 21:57:55 +00:00
|
|
|
kv/data/github/${{ github.repository }}/license license_1 | VAULT_LICENSE_CI;
|
|
|
|
kv/data/github/${{ github.repository }}/license license_2 | VAULT_LICENSE_2;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_API_ADDRESS;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_AUTH_URL;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_CLIENT_ID;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_CLIENT_SECRET;
|
|
|
|
kv/data/github/${{ github.repository }}/hcp-link HCP_RESOURCE_ID;
|
2023-04-03 14:26:55 +00:00
|
|
|
- id: setup-git-private
|
|
|
|
name: Setup Git configuration (private)
|
|
|
|
if: github.repository == 'hashicorp/vault-enterprise'
|
|
|
|
run: |
|
|
|
|
git config --global url."https://${{ steps.secrets.outputs.github-token }}@github.com".insteadOf https://github.com
|
|
|
|
- id: setup-git-public
|
|
|
|
name: Setup Git configuration (public)
|
|
|
|
if: github.repository != 'hashicorp/vault-enterprise'
|
|
|
|
run: |
|
|
|
|
git config --global url."https://${{ secrets.ELEVATED_GITHUB_TOKEN}}@github.com".insteadOf https://github.com
|
2023-04-27 13:41:49 +00:00
|
|
|
- id: build
|
2023-07-20 22:39:29 +00:00
|
|
|
if: inputs.binary-tests && matrix.id == inputs.total-runners
|
2023-04-27 13:41:49 +00:00
|
|
|
env:
|
|
|
|
GOPRIVATE: github.com/hashicorp/*
|
|
|
|
run: time make ci-bootstrap dev
|
2023-07-20 22:39:29 +00:00
|
|
|
- uses: ./.github/actions/set-up-gotestsum
|
2023-03-06 21:57:55 +00:00
|
|
|
- id: run-go-tests
|
|
|
|
name: Run Go tests
|
|
|
|
timeout-minutes: ${{ fromJSON(env.TIMEOUT_IN_MINUTES) }}
|
2023-04-25 21:11:46 +00:00
|
|
|
env:
|
|
|
|
COMMIT_SHA: ${{ github.sha }}
|
2023-03-06 21:57:55 +00:00
|
|
|
run: |
|
|
|
|
set -exo pipefail
|
2023-07-20 22:39:29 +00:00
|
|
|
|
2023-03-06 21:57:55 +00:00
|
|
|
# Build the dynamically generated source files.
|
|
|
|
make prep
|
2023-07-20 22:39:29 +00:00
|
|
|
|
|
|
|
packages=$(echo "${{ toJSON(needs.test-matrix.outputs.matrix) }}" | jq -c -r --arg id "${{ matrix.id }}" '.[$id] | .packages')
|
|
|
|
|
2023-07-20 13:07:20 +00:00
|
|
|
if [ -z "$packages" ]; then
|
|
|
|
echo "no test packages to run"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-03-06 21:57:55 +00:00
|
|
|
# We don't want VAULT_LICENSE set when running Go tests, because that's
|
|
|
|
# not what developers have in their environments and it could break some
|
|
|
|
# tests; it would be like setting VAULT_TOKEN. However some non-Go
|
|
|
|
# CI commands, like the UI tests, shouldn't have to worry about licensing.
|
2023-07-12 19:26:00 +00:00
|
|
|
# So we provide the tests which want an externally supplied license with licenses
|
2023-03-06 21:57:55 +00:00
|
|
|
# via the VAULT_LICENSE_CI and VAULT_LICENSE_2 environment variables, and here we unset it.
|
2023-03-22 19:02:06 +00:00
|
|
|
# shellcheck disable=SC2034
|
2023-03-06 21:57:55 +00:00
|
|
|
VAULT_LICENSE=
|
|
|
|
|
|
|
|
# Assign test licenses to relevant variables if they aren't already
|
|
|
|
if [[ ${{ github.repository }} == 'hashicorp/vault' ]]; then
|
|
|
|
export VAULT_LICENSE_CI=${{ secrets.ci_license }}
|
|
|
|
export VAULT_LICENSE_2=${{ secrets.ci_license_2 }}
|
|
|
|
export HCP_API_ADDRESS=${{ secrets.HCP_API_ADDRESS }}
|
|
|
|
export HCP_AUTH_URL=${{ secrets.HCP_AUTH_URL }}
|
|
|
|
export HCP_CLIENT_ID=${{ secrets.HCP_CLIENT_ID }}
|
|
|
|
export HCP_CLIENT_SECRET=${{ secrets.HCP_CLIENT_SECRET }}
|
|
|
|
export HCP_RESOURCE_ID=${{ secrets.HCP_RESOURCE_ID }}
|
2023-03-16 17:04:23 +00:00
|
|
|
# Temporarily removing this variable to cause HCP Link tests
|
|
|
|
# to be skipped.
|
|
|
|
#export HCP_SCADA_ADDRESS=${{ secrets.HCP_SCADA_ADDRESS }}
|
2023-03-06 21:57:55 +00:00
|
|
|
fi
|
|
|
|
|
2023-04-24 13:57:37 +00:00
|
|
|
if [ -f bin/vault ]; then
|
|
|
|
VAULT_BINARY="$(pwd)/bin/vault"
|
|
|
|
export VAULT_BINARY
|
|
|
|
fi
|
2023-07-12 19:26:00 +00:00
|
|
|
|
2023-07-13 20:08:22 +00:00
|
|
|
# On a release branch, add a flag to rerun failed tests
|
2023-07-20 22:39:29 +00:00
|
|
|
# shellcheck disable=SC2193 # can get false positive for this comparision
|
2023-07-18 18:15:56 +00:00
|
|
|
if [[ "${{ github.base_ref }}" == release/* ]] || [[ -z "${{ github.base_ref }}" && "${{ github.ref_name }}" == release/* ]]
|
|
|
|
then
|
2023-07-13 20:08:22 +00:00
|
|
|
RERUN_FAILS="--rerun-fails"
|
|
|
|
fi
|
|
|
|
|
2023-07-14 01:22:15 +00:00
|
|
|
# shellcheck disable=SC2086 # can't quote RERUN_FAILS
|
2023-03-06 21:57:55 +00:00
|
|
|
GOARCH=${{ inputs.go-arch }} \
|
2023-07-20 22:39:29 +00:00
|
|
|
gotestsum --format=short-verbose \
|
2023-07-13 15:23:53 +00:00
|
|
|
--junitfile test-results/go-test/results-${{ matrix.id }}.xml \
|
|
|
|
--jsonfile test-results/go-test/results-${{ matrix.id }}.json \
|
2023-07-13 18:36:30 +00:00
|
|
|
--jsonfile-timing-events failure-summary-${{ matrix.id }}${{ inputs.name != '' && '-' || '' }}${{ inputs.name }}.json \
|
2023-07-13 20:08:22 +00:00
|
|
|
$RERUN_FAILS \
|
2023-07-20 13:07:20 +00:00
|
|
|
--packages "$packages" \
|
2023-03-06 21:57:55 +00:00
|
|
|
-- \
|
2023-07-12 19:26:00 +00:00
|
|
|
-tags "${{ inputs.go-tags }}" \
|
2023-03-06 21:57:55 +00:00
|
|
|
-timeout=${{ env.TIMEOUT_IN_MINUTES }}m \
|
2023-07-05 21:19:49 +00:00
|
|
|
-parallel=${{ inputs.go-test-parallelism }} \
|
2023-03-21 18:13:40 +00:00
|
|
|
${{ inputs.extra-flags }} \
|
2023-03-31 17:15:57 +00:00
|
|
|
- name: Prepare datadog-ci
|
2023-07-07 17:52:01 +00:00
|
|
|
if: github.repository == 'hashicorp/vault' && (success() || failure())
|
2023-03-31 17:15:57 +00:00
|
|
|
continue-on-error: true
|
|
|
|
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 test results to DataDog
|
|
|
|
continue-on-error: true
|
|
|
|
env:
|
|
|
|
DD_ENV: ci
|
|
|
|
run: |
|
|
|
|
if [[ ${{ github.repository }} == 'hashicorp/vault' ]]; then
|
|
|
|
export DATADOG_API_KEY=${{ secrets.DATADOG_API_KEY }}
|
|
|
|
fi
|
2023-07-13 15:23:53 +00:00
|
|
|
datadog-ci junit upload --service "$GITHUB_REPOSITORY" test-results/go-test/results-${{ matrix.id }}.xml
|
2023-07-04 15:07:05 +00:00
|
|
|
if: success() || failure()
|
2023-03-06 21:57:55 +00:00
|
|
|
- name: Archive test results
|
2023-05-22 17:18:06 +00:00
|
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
2023-03-06 21:57:55 +00:00
|
|
|
with:
|
2023-07-13 18:36:30 +00:00
|
|
|
name: test-results${{ inputs.name != '' && '-' || '' }}${{ inputs.name }}
|
2023-07-13 15:23:53 +00:00
|
|
|
path: test-results/go-test
|
2023-07-07 17:52:01 +00:00
|
|
|
if: success() || failure()
|
2023-07-13 18:36:30 +00:00
|
|
|
# GitHub Actions doesn't expose the job ID or the URL to the job execution,
|
|
|
|
# so we have to fetch it from the API
|
|
|
|
- name: Fetch job logs URL
|
|
|
|
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
|
|
|
|
if: success() || failure()
|
|
|
|
continue-on-error: true
|
|
|
|
with:
|
2023-07-17 16:13:15 +00:00
|
|
|
retries: 3
|
2023-07-13 18:36:30 +00:00
|
|
|
script: |
|
2023-07-17 16:13:15 +00:00
|
|
|
// We surround the whole script with a try-catch block, to avoid each of the matrix jobs
|
|
|
|
// displaying an error in the GHA workflow run annotations, which gets very noisy.
|
|
|
|
// If an error occurs, it will be logged so that we don't lose any information about the reason for failure.
|
|
|
|
try {
|
|
|
|
const fs = require("fs");
|
|
|
|
const result = await github.rest.actions.listJobsForWorkflowRun({
|
2023-07-13 18:36:30 +00:00
|
|
|
owner: context.repo.owner,
|
2023-07-17 16:13:15 +00:00
|
|
|
per_page: 100,
|
2023-07-13 18:36:30 +00:00
|
|
|
repo: context.repo.repo,
|
|
|
|
run_id: context.runId,
|
2023-07-17 16:13:15 +00:00
|
|
|
});
|
2023-07-13 18:36:30 +00:00
|
|
|
|
2023-07-17 16:13:15 +00:00
|
|
|
// Determine what job name to use for the query. These values are hardcoded, because GHA doesn't
|
|
|
|
// expose them in any of the contexts available within a workflow run.
|
|
|
|
let prefixToSearchFor;
|
|
|
|
switch ("${{ inputs.name }}") {
|
|
|
|
case "race":
|
2023-07-20 13:07:20 +00:00
|
|
|
prefixToSearchFor = 'Run Go tests with data race detection / test-go (${{ matrix.id }})'
|
2023-07-17 16:13:15 +00:00
|
|
|
break
|
|
|
|
case "fips":
|
2023-07-20 13:07:20 +00:00
|
|
|
prefixToSearchFor = 'Run Go tests with FIPS configuration / test-go (${{ matrix.id }})'
|
2023-07-17 16:13:15 +00:00
|
|
|
break
|
|
|
|
default:
|
2023-07-20 13:07:20 +00:00
|
|
|
prefixToSearchFor = 'Run Go tests / test-go (${{ matrix.id }})'
|
2023-07-17 16:13:15 +00:00
|
|
|
}
|
2023-07-13 18:36:30 +00:00
|
|
|
|
2023-07-17 16:13:15 +00:00
|
|
|
const jobData = result.data.jobs.filter(
|
|
|
|
(job) => job.name.startsWith(prefixToSearchFor)
|
|
|
|
);
|
|
|
|
const url = jobData[0].html_url;
|
|
|
|
const envVarName = "GH_JOB_URL";
|
|
|
|
const envVar = envVarName + "=" + url;
|
|
|
|
const envFile = process.env.GITHUB_ENV;
|
2023-07-13 18:36:30 +00:00
|
|
|
|
2023-07-17 16:13:15 +00:00
|
|
|
fs.appendFile(envFile, envVar, (err) => {
|
2023-07-13 18:36:30 +00:00
|
|
|
if (err) throw err;
|
|
|
|
console.log("Successfully set " + envVarName + " to: " + url);
|
2023-07-17 16:13:15 +00:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.log("Error: " + error);
|
|
|
|
return
|
|
|
|
}
|
2023-07-13 18:36:30 +00:00
|
|
|
- name: Prepare failure summary
|
|
|
|
if: success() || failure()
|
2023-07-17 16:13:15 +00:00
|
|
|
continue-on-error: true
|
2023-07-13 18:36:30 +00:00
|
|
|
run: |
|
|
|
|
# This jq query filters out successful tests, leaving only the failures.
|
|
|
|
# Then, it formats the results into rows of a Markdown table.
|
|
|
|
# An example row will resemble this:
|
|
|
|
# | github.com/hashicorp/vault/package | TestName | fips | 0 | 2 | [view results](github.com/link-to-logs) |
|
|
|
|
jq -r -n 'inputs
|
|
|
|
| select(.Action == "fail")
|
|
|
|
| "| ${{inputs.name}} | \(.Package) | \(.Test // "-") | \(.Elapsed) | ${{ matrix.id }} | [view test results :scroll:](${{ env.GH_JOB_URL }}) |"' \
|
|
|
|
failure-summary-${{ matrix.id }}${{ inputs.name != '' && '-' || '' }}${{inputs.name}}.json \
|
|
|
|
>> failure-summary-${{ matrix.id }}${{ inputs.name != '' && '-' || '' }}${{inputs.name}}.md
|
2023-07-07 17:52:01 +00:00
|
|
|
- name: Upload failure summary
|
|
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
|
|
if: success() || failure()
|
2023-03-06 21:57:55 +00:00
|
|
|
with:
|
2023-07-07 17:52:01 +00:00
|
|
|
name: failure-summary
|
2023-07-13 18:36:30 +00:00
|
|
|
path: failure-summary-${{ matrix.id }}${{ inputs.name != '' && '-' || '' }}${{inputs.name}}.md
|
2023-07-13 15:23:53 +00:00
|
|
|
|
|
|
|
test-collect-reports:
|
2023-08-02 13:49:27 +00:00
|
|
|
if: ${{ ! cancelled() }}
|
2023-07-13 15:23:53 +00:00
|
|
|
needs: test-go
|
|
|
|
runs-on: ${{ fromJSON(inputs.runs-on) }}
|
|
|
|
steps:
|
2023-07-21 16:53:07 +00:00
|
|
|
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
|
|
|
with:
|
|
|
|
path: test-results/go-test
|
|
|
|
key: go-test-reports-${{ github.run_number }}
|
|
|
|
restore-keys: go-test-reports-
|
2023-07-13 15:23:53 +00:00
|
|
|
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
|
|
|
|
with:
|
|
|
|
name: test-results
|
|
|
|
path: test-results/go-test
|
|
|
|
- run: |
|
|
|
|
ls -lhR test-results/go-test
|
|
|
|
find test-results/go-test -mindepth 1 -mtime +3 -delete
|
|
|
|
ls -lhR test-results/go-test
|