From a6c6537ba861e2f1ca94a983f1a872a4e40762d9 Mon Sep 17 00:00:00 2001 From: Ryan Diers Date: Tue, 9 May 2023 21:18:24 -0700 Subject: [PATCH] first attempt to load unit tests, integration tests, and codecov via GH CI --- .bazelrc | 2 +- .bazelversion | 1 + .../workflows/actions/bazel_build/action.yaml | 6 -- .github/workflows/actions/lint/action.yaml | 6 -- .github/workflows/code-coverage.yaml | 26 +++++++ .github/workflows/integration-test.yaml | 69 +++++++++++++++++++ .github/workflows/lint_and_test.yaml | 52 ++++++++++++++ .github/workflows/main.yaml | 28 -------- BUILD | 10 +++ _ci/lint/Dockerfile | 7 -- internal/cli/BUILD.bazel | 3 +- repositories.bzl | 7 ++ 12 files changed, 168 insertions(+), 49 deletions(-) create mode 100644 .bazelversion delete mode 100644 .github/workflows/actions/bazel_build/action.yaml delete mode 100644 .github/workflows/actions/lint/action.yaml create mode 100644 .github/workflows/code-coverage.yaml create mode 100644 .github/workflows/integration-test.yaml create mode 100644 .github/workflows/lint_and_test.yaml delete mode 100644 .github/workflows/main.yaml delete mode 100644 _ci/lint/Dockerfile diff --git a/.bazelrc b/.bazelrc index 8581022..d0a8e72 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1 @@ -test --test_output=all +test --test_size_filters=small,medium --test_output=all --test_verbose_timeout_warnings \ No newline at end of file diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000..4ac4fde --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +6.2.0 \ No newline at end of file diff --git a/.github/workflows/actions/bazel_build/action.yaml b/.github/workflows/actions/bazel_build/action.yaml deleted file mode 100644 index f30db08..0000000 --- a/.github/workflows/actions/bazel_build/action.yaml +++ /dev/null @@ -1,6 +0,0 @@ -name: "bazel build" -description: "Ensure the project builds with bazel" -runs: - using: docker - # .github/workflows/main.yaml copies the Dockerfile here - image: ../../../../Dockerfile \ No newline at end of file diff --git a/.github/workflows/actions/lint/action.yaml b/.github/workflows/actions/lint/action.yaml deleted file mode 100644 index 465a887..0000000 --- a/.github/workflows/actions/lint/action.yaml +++ /dev/null @@ -1,6 +0,0 @@ -name: "lint" -description: "lint" -runs: - using: docker - # .github/workflows/main.yaml copies the Dockerfile here - image: ../../../../Dockerfile \ No newline at end of file diff --git a/.github/workflows/code-coverage.yaml b/.github/workflows/code-coverage.yaml new file mode 100644 index 0000000..c7092ce --- /dev/null +++ b/.github/workflows/code-coverage.yaml @@ -0,0 +1,26 @@ +name: Code Coverage +on: + pull_request: + +permissions: + contents: read # for actions/checkout to fetch code + +jobs: + code_coverage: + name: Bazel - Code Coverage + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: bazelbuild/setup-bazelisk@v2 + - name: Mount bazel cache + uses: actions/cache@v3 + with: + path: "~/.cache/bazel" + key: bazel + + - name: Build via bazel + run: bazel build //... + + - name: Run bazel code-coverage + run: bazel coverage --nocache_test_results ...:all \ No newline at end of file diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml new file mode 100644 index 0000000..b685169 --- /dev/null +++ b/.github/workflows/integration-test.yaml @@ -0,0 +1,69 @@ +name: Integration Tests +on: + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + +jobs: + integration_tests: + name: Integration Testing - S3 Download and Retrieval of Test PKG file + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: bazelbuild/setup-bazelisk@v2 + - name: Mount bazel cache + uses: actions/cache@v3 + with: + path: "~/.cache/bazel" + key: bazel + + - name: Setup minio S3 bucket + run: | + wget https://dl.min.io/server/minio/release/linux-amd64/minio + chmod +x minio + MINIO_ROOT_USER=minioadmin MINIO_ROOT_PASSWORD=minioadmin ./minio server /tmp --address ":9000" --console-address ":9001" & + + - name: Setup minio S3 bucket + run: | + export AWS_ACCESS_KEY_ID=minioadmin + export AWS_SECRET_ACCESS_KEY=minioadmin + export AWS_EC2_METADATA_DISABLED=true + aws --endpoint-url http://127.0.0.1:9000/ s3 mb s3://test + + - name: Build via bazel + run: bazel build //... + + - name: Setup /tmp folder to test Pantri out + run: | + mkdir -p /tmp/some_git_project + cp ./bazel-bin/pantri_but_go_/pantri_but_go /tmp/some_git_project/pantri_but_go + chmod a+x /tmp/some_git_project/pantri_but_go + + - name: Init Pantri from bazel build output + run: | + export AWS_ACCESS_KEY_ID=minioadmin + export AWS_SECRET_ACCESS_KEY=minioadmin + cd /tmp/some_git_project + ./pantri_but_go init /tmp/some_git_project --backend_address http://127.0.0.1:9000/test --store_type=s3 --region="us-east-1" + + - name: Download and Upload some small package to Pantri test S3/minio bucket + run: | + export AWS_ACCESS_KEY_ID=minioadmin + export AWS_SECRET_ACCESS_KEY=minioadmin + cd /tmp/some_git_project + wget https://github.com/macadmins/nudge/releases/download/v1.1.11.81465/Nudge_Suite-1.1.11.81465.pkg -O nudge_suite.pkg + ./pantri_but_go upload nudge_suite.pkg --vv --debug + + - name: Test File Retrieval with Pantri from test S3/minio bucket + run: | + export AWS_ACCESS_KEY_ID=minioadmin + export AWS_SECRET_ACCESS_KEY=minioadmin + cd /tmp/some_git_project + rm -f ./nudge_suite.pkg + ./pantri_but_go retrieve nudge_suite.pkg.pfile --vv --debug diff --git a/.github/workflows/lint_and_test.yaml b/.github/workflows/lint_and_test.yaml new file mode 100644 index 0000000..20260a4 --- /dev/null +++ b/.github/workflows/lint_and_test.yaml @@ -0,0 +1,52 @@ +name: Lint and Tests +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + +jobs: + golangci_lint: + permissions: + contents: read # for actions/checkout to fetch code + pull-requests: read # for golangci/golangci-lint-action to fetch pull requests + name: golangci_lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v4 + with: + go-version: '1.18' + cache: true + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --verbose + + bazel_tests: + permissions: + contents: read # for actions/checkout to fetch code + runs-on: ubuntu-latest + name: Bazel - Tests + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: bazelbuild/setup-bazelisk@v2 + - name: Mount bazel cache + uses: actions/cache@v3 + with: + path: "~/.cache/bazel" + key: bazel + - name: Build via bazel + run: bazel build //... + - name: Test via bazel + run: bazel test //... diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index 32c59d6..0000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,28 +0,0 @@ -on: [pull_request] -jobs: - bazel_build: - container: - image: gcr.io/bazel-public/bazel:latest@sha256:91d0c1fcbb9e46c562dab1b99eba360188fe5d1e2890f502b7af509219a3ff5d - options: --user root - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - name: copy dockerfile - # awful hack because COPY ../ doesn't work in Dockerfile - # https://github.com/actions/runner/issues/2017 - run: cp ./_ci/bazel_build/Dockerfile ./Dockerfile - - name: bazel_build - uses: ./.github/workflows/actions/bazel_build/ - env: - # https://stackoverflow.com/questions/40775920/how-can-i-make-bazel-use-external-storage-when-building - TEST_TMPDIR: /home/ubuntu/bazel-pantri-output - lint: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - name: copy dockerfile - # awful hack because COPY ../ doesn't work in Dockerfile - # https://github.com/actions/runner/issues/2017 - run: cp ./_ci/lint/Dockerfile ./Dockerfile - - name: lint - uses: ./.github/workflows/actions/lint/ diff --git a/BUILD b/BUILD index 7091892..0681774 100644 --- a/BUILD +++ b/BUILD @@ -5,6 +5,16 @@ load("@bazel_gazelle//:def.bzl", "gazelle") # gazelle:exclude .sl gazelle(name = "gazelle") +gazelle( + name = "gazelle-update-repos", + args = [ + "-from_file=go.mod", + "-to_macro=deps.bzl%go_dependencies", + "-prune", + ], + command = "update-repos", +) + go_library( name = "pantri_but_go_lib", srcs = ["main.go"], diff --git a/_ci/lint/Dockerfile b/_ci/lint/Dockerfile deleted file mode 100644 index 0e11406..0000000 --- a/_ci/lint/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM golangci/golangci-lint - -WORKDIR /app - -COPY . . - -ENTRYPOINT golangci-lint run \ No newline at end of file diff --git a/internal/cli/BUILD.bazel b/internal/cli/BUILD.bazel index 26e7699..0bd44f3 100644 --- a/internal/cli/BUILD.bazel +++ b/internal/cli/BUILD.bazel @@ -25,6 +25,7 @@ go_library( go_test( name = "cli_test", + timeout = "short", srcs = [ "helpers_test.go", "init_test.go", @@ -39,7 +40,7 @@ go_test( "//internal/metadata", "//internal/stores", "//internal/testutil", - "@com_github_gonuts_go_shellquote//:go_default_library", + "@com_github_gonuts_go_shellquote//:go-shellquote", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", diff --git a/repositories.bzl b/repositories.bzl index 5f04fbb..4be53eb 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -637,3 +637,10 @@ def go_repositories(): sum = "h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=", version = "v0.0.0-20200804184101-5ec99f83aff1", ) + go_repository( + name = "com_github_gonuts_go_shellquote", + build_file_proto_mode = "disable_global", + importpath = "github.com/gonuts/go-shellquote", + sum = "h1:rVmtJJsWzJJ3T52/cPd3wXnDq0X2G8oLiuzbl4fVr4A=", + version = "v0.0.0-20180428030007-95032a82bc51", + )