open-consul/.github/workflows/reusable-unit.yml
hc-github-team-consul-core dd4bd08431
Backport of [NET-4895] ci - api tests and consul container tests error because of dependency bugs with go 1.20.6. Pin go to 1.20.5. into release/1.16.x (#18128)
## Backport

This PR is auto-generated from #18124 to be assessed for backporting due
to the inclusion of the label backport/1.16.


🚨
>**Warning** automatic cherry-pick of commits failed. If the first
commit failed,
you will see a blank no-op commit below. If at least one commit
succeeded, you
will see the cherry-picked commits up to, _not including_, the commit
where
the merge conflict occurred.

The person who merged in the original PR is:
@jmurret
This person should manually cherry-pick the original PR into a new
backport PR,
and close this one when the manual backport PR is merged in.

> merge conflict error: POST
https://api.github.com/repos/hashicorp/consul/merges: 409 Merge conflict
[]



The below text is copied from the body of the original PR.

---

### Description
The following jobs started failing when go 1.20.6 was released:
- `go-test-api-1-19`
- `go-test-api-1-20`
- `compatibility-integration-tests`
- `upgrade-integration-tests`

`compatibility-integration-tests` and `compatibility-integration-tests`
to this testcontainers issue:
https://github.com/testcontainers/testcontainers-go/issues/1359. This
issue calls for testcontainers to release a new version when one of
their dependencies is fixed. When that is done, we will unpin the go
versions in `compatibility-integration-tests` and
`compatibility-integration-tests`.

### Testing & Reproduction steps

See these jobs broken in CI and then see them work with this PR.


---

<details>
<summary> Overview of commits </summary>

- 747195f7aaf291305681bb7d8ae070761a2aef55 -
516492420bf43427f1cf89adce4d4e222bbb5aaa -
f4d6ca19f8e543048e167b9c47528eeb0bdb656f -
a47407115e086bb5eff6b34a08839989534b505f -
8c03b36e00719b65a87d277012dea2ac08b67442 -
c50b17c46ec64dfea20f61d242e1998c804eb8f7 -
7b55f66218e3a17a0c609a1d85d45f6d1a1e6961 -
93ce5fcc61fe0292f4e0cba98c7101fbe5142139

</details>

---------

Co-authored-by: temp <temp@hashicorp.com>
Co-authored-by: John Murret <john.murret@hashicorp.com>
Co-authored-by: Chris Thain <32781396+cthain@users.noreply.github.com>
2023-07-13 14:55:12 -06:00

158 lines
5.5 KiB
YAML

name: reusable-unit
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"
package-names-command:
required: false
type: string
default: 'go list -tags "$GOTAGS" ./...'
go-test-flags:
required: false
type: string
default: ""
repository-name:
required: true
type: string
go-tags:
required: false
type: string
default: ""
go-version:
required: false
type: string
default: ""
secrets:
elevated-github-token:
required: true
consul-license:
required: true
datadog-api-key:
required: true
env:
TEST_RESULTS: /tmp/test-results
GOTESTSUM_VERSION: "1.10.1"
GOARCH: ${{inputs.go-arch}}
CONSUL_LICENSE: ${{secrets.consul-license}}
GOTAGS: ${{ inputs.go-tags}}
DATADOG_API_KEY: ${{secrets.datadog-api-key}}
jobs:
go-test:
runs-on: ${{ fromJSON(inputs.runs-on) }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # pin@v3.3.0
# 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"
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
if: ${{ inputs.go-version != '' }}
with:
go-version: ${{ inputs.go-version }}
cache: true
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
if: ${{ inputs.go-version == '' }}
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
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # pin@v3.0.2
with:
name: ${{inputs.uploaded-binary-name}}
path: ${{inputs.directory}}
- name: Display downloaded file
run: ls -ld consul
working-directory: ${{inputs.directory}}
- run: echo "$GITHUB_WORKSPACE/${{inputs.directory}}" >> $GITHUB_PATH
- name: Make sure consul is executable
run: chmod +x $GITHUB_WORKSPACE/${{inputs.directory}}/consul
- run: go env
- name: Run tests
working-directory: ${{inputs.directory}}
run: |
PACKAGE_NAMES=$(${{inputs.package-names-command}})
# some tests expect this umask, and arm images have a different default
umask 0022
${{inputs.go-test-flags}}
go run gotest.tools/gotestsum@v${{env.GOTESTSUM_VERSION}} \
--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 -- \
-tags="${{env.GOTAGS}}" \
${GO_TEST_FLAGS-} \
-cover -coverprofile=coverage.txt
# 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
# do not run on forks
if: ${{ env.DATADOG_API_KEY}}
env:
DD_ENV: ci
run: datadog-ci junit upload --service "$GITHUB_REPOSITORY" ${{env.TEST_RESULTS}}/gotestsum-report.xml
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # pin@v3.1.2
with:
name: test-results
path: ${{env.TEST_RESULTS}}
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # pin@v3.1.2
with:
name: jsonfile
path: /tmp/jsonfile
- name: "Re-run fails report"
run: |
.github/scripts/rerun_fails_report.sh /tmp/gotestsum-rerun-fails
- name: Notify Slack
if: ${{ failure() }}
run: .github/scripts/notify_slack.sh