Skip to content

work dir

work dir #25

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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: golangci-lint
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # v3.4.0
with:
version: v1.54.2
args: |
--verbose
only-new-issues: false
skip-pkg-cache: true
skip-build-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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- 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@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: 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