Skip to content

Add artifacts manifest (automatically generated) #72

Add artifacts manifest (automatically generated)

Add artifacts manifest (automatically generated) #72

Workflow file for this run

name: test
on:
workflow_dispatch:
push:
# cancel existing runs of the same workflow on the same ref
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
env:
CONSUL_LICENSE: ${{ secrets.CONSUL_LICENSE }}
jobs:
get-go-version:
uses: ./.github/workflows/reusable-get-go-version.yml
lint:
needs:
- get-go-version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
with:
version: v1.54.2
args: |
--verbose
only-new-issues: false
skip-cache: true
- name: lint-consul-retry
shell: bash
run: |
go install github.com/hashicorp/lint-consul-retry@master && lint-consul-retry
test:
needs:
- get-go-version
name: unit test (consul-version=${{ matrix.consul-version }})
strategy:
matrix:
consul-version:
- 1.18.1
- 1.18.1+ent
env:
TEST_RESULTS_DIR: /tmp/test-results
GOTESTSUM_VERSION: 1.8.2
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: Install Consul
shell: bash
run: |
CONSUL_VERSION="${{ matrix.consul-version }}"
FILENAME="consul_${CONSUL_VERSION}_linux_amd64.zip"
curl -sSLO "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/${FILENAME}" && \
unzip "${FILENAME}" -d /usr/local/bin && \
rm "${FILENAME}"
consul version
- name: Build
run: go build -v ./...
- name: Setup gotestsum
shell: bash
run: |
url=https://github.com/gotestyourself/gotestsum/releases/download
curl -sSL "${url}/v${{ env.GOTESTSUM_VERSION }}/gotestsum_${{ env.GOTESTSUM_VERSION }}_linux_amd64.tar.gz" | \
tar -xz --overwrite -C /usr/local/bin gotestsum
- name: Test
run: |
mkdir -p $TEST_RESULTS_DIR/${{ matrix.consul-version }}/json
PACKAGE_NAMES=$(go list ./... | grep -v 'mocks\|hack\|testing' | tr '\n' ' ')
echo "Testing $(echo $PACKAGE_NAMES | wc -w) packages"
if [[ "${{ matrix.consul-version }}" == *ent ]]; then
FLAGS=-enterprise
TAGS=-tags=enterprise
fi
gotestsum \
--format=short-verbose \
--jsonfile $TEST_RESULTS_DIR/${{ matrix.consul-version }}/json/go-test-race.log \
--junitfile $TEST_RESULTS_DIR/${{ matrix.consul-version }}/gotestsum-report.xml \
-- $PACKAGE_NAMES $TAGS -- $FLAGS
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: ${{ matrix.consul-version }}-test-results
path: ${{ env.TEST_RESULTS_DIR }}/${{ matrix.consul-version }}
# This is job is required for branch protection as a required GitHub check
# because GitHub actions show up as checks at the job level and not the
# workflow level. This is currently a feature request:
# https://github.com/orgs/community/discussions/12395
#
# This job must:
# - be placed after the fanout of a workflow so that everything fans back in
# to this job.
# - "need" any job that is part of the fan out / fan in
# - include if: always() logic because we may have conditional jobs that this job
# needs, and this would potentially get skipped if a previous job got skipped.
# The if clause ensures it does not get skipped.
test-success:
needs:
- lint
- test
runs-on: ubuntu-latest
if: always()
steps:
- name: evaluate upstream job results
run: |
# exit 1 if failure or cancelled result for any upstream job
# this ensures that we fail the PR check regardless of cancellation, rather than skip-passing it
# see https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution#overview
if printf '${{ toJSON(needs) }}' | grep -E -i '\"result\": \"(failure|cancelled)\"'; then
printf "Tests failed or workflow cancelled:\n\n${{ toJSON(needs) }}"
exit 1
fi