github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/.github/workflows/pr.yml (about)

     1  name: Go Test on Pull Requests
     2  on:
     3    pull_request:
     4      types:
     5        - opened
     6        - synchronize
     7        - reopened
     8  jobs:
     9    go:
    10      name: Check sources
    11      runs-on: ubuntu-20.04
    12      env:
    13        OPERATOR_SDK_VERSION: v1.18.0
    14      steps:
    15        - name: Set up Go 1.x
    16          uses: actions/setup-go@v5
    17          with:
    18            go-version: "1.21"
    19        - name: Check out code into the Go module directory
    20          uses: actions/checkout@v4
    21          with:
    22            fetch-depth: 0
    23        - name: Cache Operator SDK ${{ env.OPERATOR_SDK_VERSION }}
    24          uses: actions/cache@v4
    25          id: cache-operator-sdk
    26          with:
    27            path: ~/cache
    28            key: operator-sdk-${{ env.OPERATOR_SDK_VERSION }}
    29        - name: Download Operator SDK ${{ env.OPERATOR_SDK_VERSION }}
    30          if: steps.cache-operator-sdk.outputs.cache-hit != 'true'
    31          run: |
    32            mkdir -p ~/cache
    33            wget https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk_linux_amd64 -O ~/cache/operator-sdk-${OPERATOR_SDK_VERSION} > /dev/null -O ~/cache/operator-sdk-${OPERATOR_SDK_VERSION} > /dev/null
    34            chmod +x ~/cache/operator-sdk-${OPERATOR_SDK_VERSION}
    35        - name: Install Operator SDK ${{ env.OPERATOR_SDK_VERSION }}
    36          run: |
    37            mkdir -p ~/bin
    38            cp ~/cache/operator-sdk-${OPERATOR_SDK_VERSION} ~/bin/operator-sdk
    39            echo "$HOME/bin" >> $GITHUB_PATH
    40        - name: Regenerate executables with current environment packages
    41          run: |
    42            rm -f bin/kustomize bin/controller-gen
    43            make kustomize controller-gen
    44        - name: Cache go modules
    45          id: cache-mod
    46          uses: actions/cache@v4
    47          with:
    48            path: ~/go/pkg/mod
    49            key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
    50            restore-keys: |
    51              ${{ runner.os }}-go-
    52        - name: Download dependencies
    53          run: go mod download
    54          if: steps.cache-mod.outputs.cache-hit != 'true'
    55        - name: Check go mod status
    56          run: |
    57            go mod tidy
    58            if [[ ! -z $(git status ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen' -s) ]]
    59            then
    60              echo "Go mod state is not clean:"
    61              git --no-pager diff ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen'
    62              exit 1
    63            fi
    64        - name: Check format
    65          run: |
    66            make fmt
    67            if [[ ! -z $(git status ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen' -s) ]]
    68            then
    69              echo "Some files are not properly formatted."
    70              echo "Please run `go fmt` and amend your commit."
    71              git --no-pager diff ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen'
    72              exit 1
    73            fi
    74        - uses: dominikh/staticcheck-action@v1.3.1
    75          with:
    76            version: "2023.1.3"
    77            install-go: false
    78        - name: Check manifests
    79          run: |
    80            make generate manifests
    81            if [[ ! -z $(git status ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen' -s) ]]
    82            then
    83              echo "generated sources are not up to date:"
    84              git --no-pager diff ':(exclude)bin/kustomize' ':(exclude)bin/controller-gen'
    85              exit 1
    86            fi
    87        - name: Check RBAC wildcards
    88          run: |
    89            if grep -n "*" config/rbac/*.yaml ; then
    90              echo "RBAC files contain wildcards (*)"
    91              exit 1
    92            fi
    93        - name: Run Go Tests
    94          run: make test
    95        - name: Upload coverage to Codecov
    96          uses: codecov/codecov-action@v4
    97        - name: Ensure make build succeeds
    98          run: make build
    99        - name: Ensure make bundle succeeds
   100          run: make bundle
   101    docker:
   102      name: Check docker build
   103      runs-on: ubuntu-20.04
   104      steps:
   105        - name: Check out code into the Go module directory
   106          uses: actions/checkout@v4
   107          with:
   108            fetch-depth: 0
   109        - name: Check if dockerimage build is working
   110          run: docker build -f ./Dockerfile .
   111    gitlint:
   112      name: Run gitlint checks
   113      runs-on: ubuntu-20.04
   114      steps:
   115        - name: Check out code
   116          uses: actions/checkout@v4
   117          with:
   118            fetch-depth: 0
   119            ref: ${{ github.event.pull_request.head.sha }}
   120        - name: Install gitlint into container
   121          run: python -m pip install gitlint
   122        - name: Run gitlint check
   123          run: gitlint --commits origin/${{ github.event.pull_request.base.ref }}..HEAD