Skip to content

Update build.yml

Update build.yml #810

Workflow file for this run

# Copyright (c) HashiCorp, Inc.
name: CI
on:
workflow_dispatch:
push:
pull_request:
branches:
- main
- "release/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GO_VERSION: 1.21.8
CONSUL_VERSION: 1.12.1
TERRAFORM_VERSION: 1.7.5
jobs:
run-check:
name: Run-Check
runs-on: ubuntu-latest
# This job only runs if the action trigger is manual, a commit push, or a PR from a different repo (fork).
# Other jobs can check if this job ran successfully to determine if they should run as well.
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
steps:
- run: |
echo "Run-check job ran successfully"
checks:
name: Checks
runs-on: ubuntu-latest
needs:
- run-check
if: needs.run-check.result == 'success'
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Set up Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ env.GO_VERSION }}
- name: Run Go checks
run: |
make go-fmt-check
- name: Run Terraform checks
run: |
make terraform-fmt-check
- name: Compile weekly tests
run: |
make compile-weekly-tests
- name: Verify go.mod and go.sum are correct
run: |
go mod tidy
git diff --quiet && exit 0
echo "please run 'go mod tidy' to ensure go.mod and go.sum are up to date"
exit 1
build:
name: Build
runs-on: ubuntu-latest
needs:
- run-check
if: needs.run-check.result == 'success'
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Set up Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ env.GO_VERSION }}
- name: Build
run: |
go build -ldflags "-w -s"
unit-and-integration:
name: Unit and Integration Tests
runs-on: ubuntu-latest
needs:
- run-check
if: needs.run-check.result == 'success'
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Set up Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup gotestsum
uses: ./.github/actions/setup-gotestsum
- name: Setup Consul
uses: ./.github/actions/setup-consul
with:
version: ${{ env.CONSUL_VERSION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Run unit and integration tests
run: |
make test-unit-and-integration
- name: Annotate tests
if: always()
uses: guyarb/golang-test-annotations@2941118d7ef622b1b3771d1ff6eae9e90659eb26 # v0.8.0
with:
test-results: .build/test-results.json
e2e-split:
name: E2E Tests Splitting
runs-on: ubuntu-latest
needs:
- run-check
if: needs.run-check.result == 'success'
env:
E2E_TESTS_PARALLELISM: 4
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Set up Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ env.GO_VERSION }}
- name: Split E2E tests
run: |
set -euo pipefail
./build-scripts/list-tests.sh e2e ./e2e | ./build-scripts/split-lines.sh ${{ env.E2E_TESTS_PARALLELISM }} .build/tests
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: e2e-tests-parts
path: .build/tests/
e2e:
name: E2E Tests
runs-on: ubuntu-latest
needs:
- run-check
- e2e-split
if: needs.run-check.result == 'success'
strategy:
fail-fast: false
matrix:
index: [0, 1, 2, 3]
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Set up Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup gotestsum
uses: ./.github/actions/setup-gotestsum
- name: Setup Consul
uses: ./.github/actions/setup-consul
with:
version: ${{ env.CONSUL_VERSION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Move Terraform to work directory
run: |
cp /usr/local/bin/terraform ./e2e/
- uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
name: e2e-tests-parts
path: .build/tests/
- name: Run E2E tests
run: |
set -euo pipefail
cat .build/tests/part.${{ matrix.index }} | ./build-scripts/make-tests-regex.sh > .build/regex
TESTS_REGEX_PATH=.build/regex make test-e2e-ci
- name: Annotate tests
if: always()
uses: guyarb/golang-test-annotations@2941118d7ef622b1b3771d1ff6eae9e90659eb26 # v0.8.0
with:
test-results: .build/test-results.json
slack-notification:
name: Slack Notification
if: |
needs.run-check.result == 'success' &&
failure() &&
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release'))
needs:
- run-check
- checks
- build
- unit-and-integration
- e2e
runs-on: ubuntu-latest
steps:
- name: Slack Workflow Notification
uses: Gamesight/slack-workflow-status@68bf00d0dbdbcb206c278399aa1ef6c14f74347a # v1.3.0
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}