2023-03-28 21:29:27 +00:00
|
|
|
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: ""
|
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-03-28 21:29:27 +00:00
|
|
|
env:
|
|
|
|
TEST_RESULTS: /tmp/test-results
|
|
|
|
GOTESTSUM_VERSION: 1.8.2
|
|
|
|
GOARCH: ${{inputs.go-arch}}
|
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-03-28 21:29:27 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
go-test:
|
|
|
|
runs-on: ${{ fromJSON(inputs.runs-on) }}
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # pin@v3.3.0
|
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"
|
|
|
|
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # pin@v3.5.0
|
2023-03-28 21:29:27 +00:00
|
|
|
with:
|
2023-03-30 16:57:11 +00:00
|
|
|
go-version-file: 'go.mod'
|
|
|
|
cache: true
|
2023-03-28 21:29:27 +00:00
|
|
|
- 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}}
|
2023-03-30 16:57:11 +00:00
|
|
|
path: ${{inputs.directory}}
|
2023-03-28 21:29:27 +00:00
|
|
|
- name: Display downloaded file
|
|
|
|
run: ls -ld consul
|
2023-03-30 16:57:11 +00:00
|
|
|
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
|
2023-03-28 21:29:27 +00:00
|
|
|
- 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}}
|
|
|
|
|
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 -- \
|
|
|
|
-tags="${{env.GOTAGS}}" \
|
|
|
|
${GO_TEST_FLAGS-} \
|
|
|
|
-cover -coverprofile=coverage.txt
|
|
|
|
- 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
|
2023-03-30 16:57:11 +00:00
|
|
|
if: ${{ failure() }}
|
2023-03-28 21:29:27 +00:00
|
|
|
run: .github/scripts/notify_slack.sh
|