This is an automated email from the ASF dual-hosted git repository.

zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ab9ffd39f Add Unit Tests to Codecov (#7226)
2ab9ffd39f is described below

commit 2ab9ffd39f3943548438a7249b843acc92b335d6
Author: Eric Holguin <[email protected]>
AuthorDate: Fri Dec 2 12:56:33 2022 -0700

    Add Unit Tests to Codecov (#7226)
    
    * initial codecov setup
    
    * updated codecov gha
    
    * fix coverpkg arg
    
    * fix path
    
    * coverage file path
    
    * name changes
    
    * update flags
    
    * separate unit tests and add codecov
    
    * Change workflow name
    
    * Fix tabbing
    
    * change job names
    
    * Update names to be more descriptive
    
    * Add codecov yaml
    
    * fixes
    
    * fix path
    
    * fixes cont
    
    * testing changes
    
    * remove unused env var
    
    * remove missed path
    
    * add newline
    
    * update codecov yaml
    
    * add TR tests to codecov
    
    * undo tr changes
---
 .github/actions/go-test/action.yml => .codecov.yml |  24 ++--
 .github/actions/go-test/action.yml                 |   8 +-
 .github/actions/go-test/entrypoint.sh              |  11 +-
 .github/workflows/go.unit.tests.yaml               | 158 +++++++++++++++++++--
 4 files changed, 172 insertions(+), 29 deletions(-)

diff --git a/.github/actions/go-test/action.yml b/.codecov.yml
similarity index 75%
copy from .github/actions/go-test/action.yml
copy to .codecov.yml
index 1075f3dd63..f598ace578 100644
--- a/.github/actions/go-test/action.yml
+++ b/.codecov.yml
@@ -14,15 +14,17 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+#
+
+coverage:
+  status:
+    project:
+      default:
+        informational: true
+    patch:
+      default:
+        informational: true
 
-name: 'go-test'
-description: 'Runs go tests'
-inputs:
-  dir:  # id of input
-    description: 'Directory in which to run tests'
-    required: true
-runs:
-  using: 'docker'
-  image: 'Dockerfile'
-  args:
-    - ${{ inputs.dir }}
+flag_management:
+  default_rules: # the rules that will be followed for any flag added, 
generally
+    carryforward: true
diff --git a/.github/actions/go-test/action.yml 
b/.github/actions/go-test/action.yml
index 1075f3dd63..8f7502ac44 100644
--- a/.github/actions/go-test/action.yml
+++ b/.github/actions/go-test/action.yml
@@ -21,8 +21,12 @@ inputs:
   dir:  # id of input
     description: 'Directory in which to run tests'
     required: true
+  test_name:
+    description: 'Name of the test being ran'
+    required: true
 runs:
   using: 'docker'
   image: 'Dockerfile'
-  args:
-    - ${{ inputs.dir }}
+  env:
+    INPUT_DIR: ${{ inputs.dir }}
+    TEST_NAME: ${{ inputs.test_name }}
diff --git a/.github/actions/go-test/entrypoint.sh 
b/.github/actions/go-test/entrypoint.sh
index 0da9a0a561..1ca3f56565 100755
--- a/.github/actions/go-test/entrypoint.sh
+++ b/.github/actions/go-test/entrypoint.sh
@@ -18,10 +18,8 @@
 
 set -e
 
-cd "${GOPATH}/src/github.com/apache/trafficcontrol"
-
 download_go() {
-       go_version="$(cat GO_VERSION)"
+       go_version="$(cat "${GITHUB_WORKSPACE}/GO_VERSION")"
        wget -O go.tar.gz 
"https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz";
        tar -C /usr/local -xzf go.tar.gz
        rm go.tar.gz
@@ -36,6 +34,9 @@ if [ -z "$INPUT_DIR" ]; then
 fi
 
 # Need to fetch golang.org/x/* dependencies
-go mod vendor -v
-go test --buildvcs=false $INPUT_DIR
+if ! [ -d "${GITHUB_WORKSPACE}/vendor/golang.org" ]; then
+       go mod vendor
+fi
+
+go test --buildvcs=false $INPUT_DIR  -coverpkg=$INPUT_DIR 
-coverprofile="$TEST_NAME-coverage.out"
 exit $?
diff --git a/.github/workflows/go.unit.tests.yaml 
b/.github/workflows/go.unit.tests.yaml
index 3b423846ad..2ec9967442 100644
--- a/.github/workflows/go.unit.tests.yaml
+++ b/.github/workflows/go.unit.tests.yaml
@@ -56,28 +56,164 @@ on:
     types: [opened, reopened, ready_for_review, synchronize]
 
 jobs:
-  test:
+  grove_unit_tests:
     if: github.event.pull_request.draft == false
     runs-on: ubuntu-latest
 
     steps:
     - name: Checkout
       uses: actions/checkout@master
-      with:
-        fetch-depth: 1
-        path: src/github.com/apache/trafficcontrol
     - name: Cache Alpine Docker image
       uses: actions/cache@v2
       with:
         path: ${{ github.workspace }}/docker-images
         key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
     - name: Import cached Alpine Docker image
-      run: 
src/github.com/apache/trafficcontrol/.github/actions/save-alpine-tar/entrypoint.sh
 load ${{ env.ALPINE_VERSION }}
-    - name: Run unit tests
-      uses: ./src/github.com/apache/trafficcontrol/.github/actions/go-test
+      run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ 
env.ALPINE_VERSION }}
+    - name: Run Grove unit tests
+      uses: ./.github/actions/go-test
+      with:
+        dir: ./grove/...
+        test_name: grove
+    - name: Upload coverage to Codecov
+      uses: codecov/codecov-action@v3
       with:
-        dir: ./grove/... ./lib/... ./traffic_monitor/... 
./traffic_ops/traffic_ops_golang/... ./cache-config/t3c-generate/... 
./traffic_stats/... ./traffic_ops/app/bin/...
-      env:
-        GOPATH: /github/workspace
+        files: grove-coverage.out
+        flags: grove_unit
     - name: Save Alpine Docker image
-      run: 
src/github.com/apache/trafficcontrol/.github/actions/save-alpine-tar/entrypoint.sh
 save ${{ env.ALPINE_VERSION }}
+      run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ 
env.ALPINE_VERSION }}
+
+  go_lib_unit_tests:
+    if: github.event.pull_request.draft == false
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@master
+      - name: Cache Alpine Docker image
+        uses: actions/cache@v2
+        with:
+          path: ${{ github.workspace }}/docker-images
+          key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
+      - name: Import cached Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ 
env.ALPINE_VERSION }}
+      - name: Run Go Lib unit tests
+        uses: ./.github/actions/go-test
+        with:
+          dir: ./lib/...
+          test_name: golib
+      - name: Upload coverage to Codecov
+        uses: codecov/codecov-action@v3
+        with:
+          files: golib-coverage.out
+          flags: golib_unit
+      - name: Save Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ 
env.ALPINE_VERSION }}
+
+  traffic_monitor_unit_tests:
+    if: github.event.pull_request.draft == false
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@master
+      - name: Cache Alpine Docker image
+        uses: actions/cache@v2
+        with:
+          path: ${{ github.workspace }}/docker-images
+          key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
+      - name: Import cached Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ 
env.ALPINE_VERSION }}
+      - name: Run Traffic Monitor unit tests
+        uses: ./.github/actions/go-test
+        with:
+          dir: ./traffic_monitor/...
+          test_name: traffic_monitor
+      - name: Upload coverage to Codecov
+        uses: codecov/codecov-action@v3
+        with:
+          files: traffic_monitor-coverage.out
+          flags: traffic_monitor_unit
+      - name: Save Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ 
env.ALPINE_VERSION }}
+
+  traffic_ops_unit_tests:
+    if: github.event.pull_request.draft == false
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@master
+      - name: Cache Alpine Docker image
+        uses: actions/cache@v2
+        with:
+          path: ${{ github.workspace }}/docker-images
+          key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
+      - name: Import cached Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ 
env.ALPINE_VERSION }}
+      - name: Run Traffic Ops unit tests
+        uses: ./.github/actions/go-test
+        with:
+          dir: ./traffic_ops/traffic_ops_golang/...
+          test_name: traffic_ops
+      - name: Upload coverage to Codecov
+        uses: codecov/codecov-action@v3
+        with:
+          files: traffic_ops-coverage.out
+          flags: traffic_ops_unit
+      - name: Save Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ 
env.ALPINE_VERSION }}
+
+  t3c_generate_unit_tests:
+    if: github.event.pull_request.draft == false
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@master
+      - name: Cache Alpine Docker image
+        uses: actions/cache@v2
+        with:
+          path: ${{ github.workspace }}/docker-images
+          key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
+      - name: Import cached Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ 
env.ALPINE_VERSION }}
+      - name: Run T3C Generate unit tests
+        uses: ./.github/actions/go-test
+        with:
+          dir: ./cache-config/t3c-generate/...
+          test_name: t3c_generate
+      - name: Upload coverage to Codecov
+        uses: codecov/codecov-action@v3
+        with:
+          files: t3c_generate-coverage.out
+          flags: t3c_generate_unit
+      - name: Save Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ 
env.ALPINE_VERSION }}
+
+  traffic_stats_unit_tests:
+    if: github.event.pull_request.draft == false
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@master
+      - name: Cache Alpine Docker image
+        uses: actions/cache@v2
+        with:
+          path: ${{ github.workspace }}/docker-images
+          key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
+      - name: Import cached Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ 
env.ALPINE_VERSION }}
+      - name: Run Traffic Stats unit tests
+        uses: ./.github/actions/go-test
+        with:
+          dir: ./traffic_stats/...
+          test_name: traffic_stats
+      - name: Upload coverage to Codecov
+        uses: codecov/codecov-action@v3
+        with:
+          files: traffic_stats-coverage.out
+          flags: traffic_stats_unit
+      - name: Save Alpine Docker image
+        run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ 
env.ALPINE_VERSION }}

Reply via email to