diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 000000000000..4a74a180c581 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,56 @@ +name: Build +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: + - linux-amd64 + - linux-386 + - darwin-amd64 + - windows-amd64 + - linux-arm + - linux-arm64 + - linux-ppc64le + - linux-s390x + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: "^1.16" + - env: + TARGET: ${{ matrix.target }} + run: | + echo "${TARGET}" + case "${TARGET}" in + linux-amd64) + GOARCH=amd64 PASSES='build' ./test.sh + ;; + linux-386) + GOARCH=386 PASSES='build' ./test.sh + ;; + darwin-amd64) + GO_BUILD_FLAGS='-v -mod=readonly' GOOS=darwin GOARCH=amd64 ./build.sh + ;; + windows-amd64) + GO_BUILD_FLAGS='-v -mod=readonly' GOOS=windows GOARCH=amd64 ./build.sh + ;; + linux-arm) + GO_BUILD_FLAGS='-v -mod=readonly' GOARCH=arm ./build.sh + ;; + linux-arm64) + GO_BUILD_FLAGS='-v -mod=readonly' GOARCH=arm64 ./build.sh + ;; + linux-ppc64le) + GO_BUILD_FLAGS='-v -mod=readonly' GOARCH=ppc64le ./build.sh + ;; + linux-s390x) + GO_BUILD_FLAGS='-v -mod=readonly' GOARCH=s390x ./build.sh + ;; + *) + echo "Failed to find target" + exit 1 + ;; + esac diff --git a/.github/workflows/junit.yaml b/.github/workflows/junit.yaml new file mode 100644 index 000000000000..460a114aaf59 --- /dev/null +++ b/.github/workflows/junit.yaml @@ -0,0 +1,41 @@ +name: JUnit + +on: + workflow_run: + workflows: ["Tests"] + types: + - completed + +jobs: + unit-test-results: + runs-on: ubuntu-latest + if: > + github.event.workflow_run.conclusion != 'skipped' && ( + github.event.sender.login == 'dependabot[bot]' || + github.event.workflow_run.head_repository.full_name != github.repository + ) + + steps: + - name: Download and Extract Artifacts + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + mkdir artifacts && cd artifacts + + artifacts_url=${{ github.event.workflow_run.artifacts_url }} + artifacts=$(gh api $artifacts_url -q '.artifacts[] | {name: .name, url: .archive_download_url}') + + IFS=$'\n' + for artifact in $artifacts + do + name=$(jq -r .name <<<$artifact) + url=$(jq -r .url <<<$artifact) + gh api $url > "$name.zip" + unzip -d "$name" "$name.zip" + done + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + commit: ${{ github.event.workflow_run.head_sha }} + files: "artifacts/**/*.xml" \ No newline at end of file diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml new file mode 100644 index 000000000000..c62318797944 --- /dev/null +++ b/.github/workflows/static-analysis.yaml @@ -0,0 +1,38 @@ +name: Static Analysis +on: [push, pull_request] +jobs: + run: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: + - linux-amd64-fmt + - linux-amd64-bom + - linux-amd64-dep + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: "^1.16" + - run: date + - env: + TARGET: ${{ matrix.target }} + JUNIT_REPORT_DIR: "." + run: | + echo "${TARGET}" + case "${TARGET}" in + linux-amd64-fmt) + GOARCH=amd64 PASSES='fmt' ./test.sh + ;; + linux-amd64-bom) + GOARCH=amd64 PASSES='bom' ./test.sh + ;; + linux-amd64-dep) + GOARCH=amd64 PASSES='dep' ./test.sh + ;; + *) + echo "Failed to find target" + exit 1 + ;; + esac diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index cf63ec25a82d..3466e349f526 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -7,12 +7,10 @@ jobs: fail-fast: false matrix: target: - - linux-amd64-fmt - linux-amd64-integration-1-cpu - linux-amd64-integration-2-cpu - linux-amd64-integration-4-cpu - linux-amd64-unit-4-cpu-race - - all-build - linux-386-unit-1-cpu steps: - uses: actions/checkout@v2 @@ -24,31 +22,19 @@ jobs: TARGET: ${{ matrix.target }} run: | echo "${TARGET}" + mkdir -p junit/${TARGET} case "${TARGET}" in - linux-amd64-fmt) - GOARCH=amd64 PASSES='fmt bom dep' ./test.sh - ;; linux-amd64-integration-1-cpu) - GOARCH=amd64 CPU=1 PASSES='integration' RACE='false' ./test.sh + GOARCH=amd64 CPU=1 PASSES='integration' RACE='false' JUNIT_REPORT_DIR=junit/${TARGET} ./test.sh ;; linux-amd64-integration-2-cpu) - GOARCH=amd64 CPU=2 PASSES='integration' RACE='false' ./test.sh + GOARCH=amd64 CPU=2 PASSES='integration' RACE='false' JUNIT_REPORT_DIR=junit/${TARGET} ./test.sh ;; linux-amd64-integration-4-cpu) - GOARCH=amd64 CPU=4 PASSES='integration' RACE='false' ./test.sh + GOARCH=amd64 CPU=4 PASSES='integration' RACE='false' JUNIT_REPORT_DIR=junit/${TARGET} ./test.sh ;; linux-amd64-unit-4-cpu-race) - GOARCH=amd64 PASSES='unit' RACE='true' CPU='4' ./test.sh -p=2 - ;; - all-build) - GOARCH=amd64 PASSES='build' ./test.sh - GOARCH=386 PASSES='build' ./test.sh - GO_BUILD_FLAGS='-v -mod=readonly' GOOS=darwin GOARCH=amd64 ./build.sh - GO_BUILD_FLAGS='-v -mod=readonly' GOOS=windows GOARCH=amd64 ./build.sh - GO_BUILD_FLAGS='-v -mod=readonly' GOARCH=arm ./build.sh - GO_BUILD_FLAGS='-v -mod=readonly' GOARCH=arm64 ./build.sh - GO_BUILD_FLAGS='-v -mod=readonly' GOARCH=ppc64le ./build.sh - GO_BUILD_FLAGS='-v -mod=readonly' GOARCH=s390x ./build.sh + GOARCH=amd64 PASSES='unit' RACE='true' CPU='4' JUNIT_REPORT_DIR=junit/${TARGET} ./test.sh -p=2 ;; linux-386-unit-1-cpu) GOARCH=386 PASSES='unit' RACE='false' CPU='1' ./test -p=4 @@ -58,3 +44,8 @@ jobs: exit 1 ;; esac + - uses: actions/upload-artifact@v2 + # the test job might be skipped, we don't need to run this job then + if: success() || failure() + with: + path: ./**/junit_*.xml diff --git a/scripts/test_lib.sh b/scripts/test_lib.sh index 6a27e0591b40..7e98f03e02a0 100644 --- a/scripts/test_lib.sh +++ b/scripts/test_lib.sh @@ -231,13 +231,7 @@ function produce_junit_xmlreport { local junit_xml_filename junit_xml_filename="${junit_filename_prefix}.xml" - if ! command -v gotestsum >/dev/null 2>&1; then - log_callout "gotestsum not found; installing now" - pushd "${ETCD_ROOT_DIR}/tools/mod" >/dev/null || return - GO111MODULE=on go install gotest.tools/gotestsum - popd >/dev/null || return - fi - gotestsum --junitfile "${junit_xml_filename}" --raw-command cat "${junit_filename_prefix}"*.stdout + run_go_tool gotest.tools/gotestsum --junitfile "${junit_xml_filename}" --raw-command cat "${junit_filename_prefix}"*.stdout || exit 1 if [ "${VERBOSE}" != "1" ]; then rm "${junit_filename_prefix}"*.stdout fi