github.com/hazelops/ize@v1.1.12-0.20230915191306-97d7c0e48f11/.github/workflows/run.unit-tests.yml (about)

     1  name: "Tests: Unit"
     2  defaults:
     3    run:
     4      shell: bash
     5  
     6  env:
     7    AWS_PROFILE: default
     8    AWS_REGION: us-east-1
     9  
    10  on:
    11    workflow_dispatch:
    12    pull_request:
    13    push:
    14      branches:
    15        - main
    16  
    17  jobs:
    18    build:
    19      name: Build
    20      strategy:
    21        matrix:
    22          os:
    23            - ubuntu-latest
    24  # TODO: re-enable other platforms after Ubuntu is working fine
    25  #          - macos-latest
    26  #          - windows-latest
    27      runs-on: ${{ matrix.os }}
    28      steps:
    29        - name: Install Go
    30          uses: actions/setup-go@v2
    31          with:
    32            go-version: 1.18.x
    33  
    34        - name: Checkout Code
    35          uses: actions/checkout@v2
    36  
    37        - name: Build
    38          run: |
    39            go mod download
    40            make bin
    41  
    42        - name: Upload Artifact
    43          uses: actions/upload-artifact@v3
    44          with:
    45            name: ize-${{ matrix.os }}-${{ github.sha }}
    46            path: ${{ github.workspace }}/ize
    47  
    48    # TODO: this should be executed before the release and fail in proper cases
    49    unit-tests:
    50      name: Unit Tests
    51      needs: build
    52      runs-on: ubuntu-latest
    53      steps:
    54        - uses: actions/checkout@v3
    55  
    56        - name: Set up Go
    57          uses: actions/setup-go@v3
    58          with:
    59            go-version: 1.18
    60  
    61        - name: Generate
    62          run: |
    63            go install github.com/golang/mock/mockgen@v1.6.0
    64            go generate ./...
    65  
    66        - name: Build
    67          run: go build -v ./...
    68  
    69        - name: Generate Test SSH Key
    70          run: ssh-keygen -q -f ~/.ssh/id_rsa
    71  
    72        - name: Install Junit Reporter
    73          run: |
    74            go install github.com/jstemmer/go-junit-report/v2@latest
    75  
    76        - name: Coverage Test
    77          run: |
    78            # If we rerun with DEBUG then we'll see the actual log. Otherwise just JUnit report
    79            if [ ! -z $RUNNER_DEBUG ]; then
    80              go test -v ./... -coverprofile=coverage.out -covermode=atomic 2>&1 ./... | tee report.txt
    81              cat report.txt | go-junit-report -set-exit-code > report.xml
    82            else
    83              go test -v ./... -coverprofile=coverage.out -covermode=atomic 2>&1 ./... > report.txt
    84            fi
    85  
    86        - name: Publish Test Report
    87          uses: mikepenz/action-junit-report@v3
    88          if: always() # always run even if the previous step fails
    89          with:
    90            report_paths: './report.xml'
    91  
    92        - name: Upload coverage to Codecov
    93          uses: codecov/codecov-action@v2