Skip to content

Commit

Permalink
Backport of Github Actions Migration - move go-tests workflows to GHA…
Browse files Browse the repository at this point in the history
… into release/1.15.x (#16803)

* backport of commit df9d97f

* backport of commit 8913844

* backport of commit e8d708b

* backport of commit b42be82

* backport of commit 2e7fc80

* backport of commit 6e65358

* backport of commit 924060e

* backport of commit b4f5218

* backport of commit 4a3c1a2

* backport of commit e6f0d8e

* backport of commit 9eed445

* backport of commit 8481706

* backport of commit 5aab675

* backport of commit 07d8ede

* backport of commit 5b1b1ac

* backport of commit 2ca46f8

* backport of commit c9f8538

* backport of commit c450fa7

* backport of commit 9302ebc

* backport of commit 0f55035

* backport of commit 76694ab

* backport of commit e7a7d98

* backport of commit fea35f5

* backport of commit d64af3f

* backport of commit 840d80a

---------

Co-authored-by: John Murret <[email protected]>
Co-authored-by: Dan Bond <[email protected]>
  • Loading branch information
3 people authored Mar 28, 2023
1 parent 7d44a4c commit aeee58b
Show file tree
Hide file tree
Showing 13 changed files with 830 additions and 18 deletions.
22 changes: 22 additions & 0 deletions .github/scripts/get_runner_classes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# This script generates tag-sets that can be used as runs-on: values to select runners.

set -euo pipefail

case "$GITHUB_REPOSITORY" in
*-enterprise)
# shellcheck disable=SC2129
echo "compute-small=['self-hosted', 'linux', 'small']" >> "$GITHUB_OUTPUT"
echo "compute-medium=['self-hosted', 'linux', 'medium']" >> "$GITHUB_OUTPUT"
echo "compute-large=['self-hosted', 'linux', 'large']" >> "$GITHUB_OUTPUT"
echo "compute-xl=['self-hosted', 'ondemand', 'linux', 'type=m5.2xlarge']" >> "$GITHUB_OUTPUT"
;;
*)
# shellcheck disable=SC2129
echo "compute-small=['custom-linux-s-consul-latest']" >> "$GITHUB_OUTPUT"
echo "compute-medium=['custom-linux-m-consul-latest']" >> "$GITHUB_OUTPUT"
echo "compute-large=['custom-linux-l-consul-latest']" >> "$GITHUB_OUTPUT"
echo "compute-xl=['custom-linux-xl-consul-latest']" >> "$GITHUB_OUTPUT"
;;
esac
27 changes: 27 additions & 0 deletions .github/scripts/notify_slack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -uo pipefail

# This script is used in GitHub Actions pipelines to notify Slack of a job failure.

if [[ $GITHUB_REF_NAME == "main" ]]; then
GITHUB_ENDPOINT="https://github.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
GITHUB_ACTIONS_ENDPOINT="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
COMMIT_MESSAGE=$(git log -1 --pretty=%B | head -n1)
SHORT_REF=$(git rev-parse --short "${GITHUB_SHA}")
curl -X POST -H 'Content-type: application/json' \
--data \
"{ \
\"attachments\": [ \
{ \
\"fallback\": \"GitHub Actions workflow failed!\", \
\"text\": \"❌ Failed: \`${GITHUB_ACTOR}\`'s <${GITHUB_ACTIONS_ENDPOINT}|${GITHUB_JOB}> job failed for commit <${GITHUB_ENDPOINT}|${SHORT_REF}> on \`${GITHUB_REF_NAME}\`!\n\n- <${COMMIT_MESSAGE}\", \
\"footer\": \"${GITHUB_REPOSITORY}\", \
\"ts\": \"$(date +%s)\", \
\"color\": \"danger\" \
} \
] \
}" "${FEED_CONSUL_GH_URL}"
else
echo "Not posting slack failure notifications for non-main branch"
fi
24 changes: 24 additions & 0 deletions .github/scripts/rerun_fails_report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

#
# Add a comment on the github PR if there were any rerun tests.
#
set -eu -o pipefail

report_filename="${1?report filename is required}"
if [ ! -s "$report_filename" ]; then
echo "gotestsum rerun report file is empty or missing"
exit 0
fi

function report {
echo ":repeat: gotestsum re-ran some tests in https://github.com/hashicorp/consul/actions/run/$GITHUB_RUN_ID"
echo
echo '```'
cat "$report_filename"
echo '```'
}

report
8 changes: 8 additions & 0 deletions .github/scripts/set_test_package_matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
export RUNNER_COUNT=$1

# set matrix var to list of unique packages containing tests
matrix="$(go list -json="ImportPath,TestGoFiles" ./... | jq --compact-output '. | select(.TestGoFiles != null) | .ImportPath' | jq --slurp --compact-output '.' | jq --argjson runnercount $RUNNER_COUNT -cM '[_nwise(length / $runnercount | floor)]'))"

echo "matrix=${matrix}" >> "${GITHUB_OUTPUT}"
48 changes: 30 additions & 18 deletions .github/workflows/build-distros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@ permissions:
contents: read

jobs:
check-go-mod:
runs-on: ubuntu-22.04
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
compute-small: ${{ steps.setup-outputs.outputs.compute-small }}
compute-medium: ${{ steps.setup-outputs.outputs.compute-medium }}
compute-large: ${{ steps.setup-outputs.outputs.compute-large }}
compute-xl: ${{ steps.setup-outputs.outputs.compute-xl }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # [email protected]
with:
go-version-file: 'go.mod'
- run: go mod tidy
- run: |
if [[ -n $(git status -s) ]]; then
echo "Git directory has changes"
git status -s
exit 1
fi
- id: setup-outputs
name: Setup outputs
run: ./.github/scripts/get_runner_classes.sh

check-go-mod:
needs:
- setup
uses: ./.github/workflows/reusable-check-go-mod.yml
with:
runs-on: ${{ needs.setup.outputs.compute-medium }}

build-386:
needs: check-go-mod
needs:
- setup
- check-go-mod
env:
XC_OS: "freebsd linux windows"
runs-on: ubuntu-22.04
runs-on: ${{ fromJSON(needs.setup.outputs.compute-medium) }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # [email protected]
Expand All @@ -40,10 +48,12 @@ jobs:
done
build-amd64:
needs: check-go-mod
needs:
- setup
- check-go-mod
env:
XC_OS: "darwin freebsd linux solaris windows"
runs-on: ubuntu-22.04
runs-on: ${{ fromJSON(needs.setup.outputs.compute-medium) }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # [email protected]
Expand All @@ -56,8 +66,10 @@ jobs:
done
build-arm:
needs: check-go-mod
runs-on: ubuntu-22.04
needs:
- setup
- check-go-mod
runs-on: ${{ fromJSON(needs.setup.outputs.compute-medium) }}
env:
CGO_ENABLED: 1
GOOS: linux
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

name: frontend

on:
push:
branches:
- main
- ui/**
- backport/ui/**

permissions:
contents: read

jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
compute-small: ${{ steps.setup-outputs.outputs.compute-small }}
compute-medium: ${{ steps.setup-outputs.outputs.compute-medium }}
compute-large: ${{ steps.setup-outputs.outputs.compute-large }}
compute-xl: ${{ steps.setup-outputs.outputs.compute-xl }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]
- id: setup-outputs
name: Setup outputs
run: ./.github/scripts/get_runner_classes.sh

workspace-tests:
needs: setup
runs-on: ${{ fromJSON(needs.setup.outputs.compute-small) }}
defaults:
run:
working-directory: ui
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]

- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # [email protected]
with:
node-version: '16'

# Install dependencies.
- name: install yarn packages
working-directory: ui
run: make deps

- run: make test-workspace

node-tests:
needs: setup
runs-on: ${{ fromJSON(needs.setup.outputs.compute-small) }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]

- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # [email protected]
with:
node-version: '16'

# Install dependencies.
- name: install yarn packages
working-directory: ui
run: make deps

- run: make test-node
working-directory: ui/packages/consul-ui

ember-build-test:
needs: setup
runs-on: ${{ fromJSON(needs.setup.outputs.compute-large) }}
env:
EMBER_TEST_REPORT: test-results/report-oss.xml #outputs test report for CircleCI test summary
EMBER_TEST_PARALLEL: true #enables test parallelization with ember-exam
CONSUL_NSPACES_ENABLED: 0 # NOTE: this should be 1 in ENT.
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]

- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # [email protected]
with:
node-version: '16'

# Install dependencies.
- name: install yarn packages
working-directory: ui
run: make deps

- working-directory: ui/packages/consul-ui
run: |
make build-ci
node_modules/.bin/ember exam --path dist --silent -r xunit
- working-directory: ui/packages/consul-ui
run: make test-coverage-ci
Loading

0 comments on commit aeee58b

Please sign in to comment.