github.com/crossplane/upjet@v1.3.0/.github/workflows/ci.yml (about)

     1  # SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
     2  #
     3  # SPDX-License-Identifier: CC0-1.0
     4  
     5  name: CI
     6  
     7  on:
     8    push:
     9      branches:
    10        - main
    11        - release-*
    12    pull_request: {}
    13    workflow_dispatch: {}
    14  
    15  env:
    16    # Common versions
    17    GO_VERSION: "1.21"
    18    GOLANGCI_VERSION: "v1.55.2"
    19    DOCKER_BUILDX_VERSION: "v0.8.2"
    20  
    21    # Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run
    22    # a step 'if env.AWS_USR' != ""', so we copy these to succinctly test whether
    23    # credentials have been provided before trying to run steps that need them.
    24    DOCKER_USR: ${{ secrets.DOCKER_USR }}
    25    AWS_USR: ${{ secrets.AWS_USR }}
    26  
    27  jobs:
    28    detect-noop:
    29      runs-on: ubuntu-20.04
    30      outputs:
    31        noop: ${{ steps.noop.outputs.should_skip }}
    32      steps:
    33        - name: Detect No-op Changes
    34          id: noop
    35          uses: fkirc/skip-duplicate-actions@v5.3.0
    36          with:
    37            github_token: ${{ secrets.GITHUB_TOKEN }}
    38            paths_ignore: '["**.md", "**.png", "**.jpg"]'
    39            do_not_skip: '["workflow_dispatch", "schedule", "push"]'
    40            concurrent_skipping: false
    41  
    42    lint:
    43      runs-on: ubuntu-20.04
    44      needs: detect-noop
    45      if: needs.detect-noop.outputs.noop != 'true'
    46  
    47      steps:
    48        - name: Checkout
    49          uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 #v3
    50          with:
    51            submodules: true
    52  
    53        - name: Setup Go
    54          uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
    55          with:
    56            go-version: ${{ env.GO_VERSION }}
    57  
    58        - name: Find the Go Build Cache
    59          id: go
    60          run: echo "cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
    61  
    62        - name: Find the Go Build Cache
    63          id: gomod
    64          run: echo "cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
    65  
    66        - name: Cache the Go Build Cache
    67          uses: actions/cache@v3
    68          with:
    69            path: ${{ steps.go.outputs.cache }}
    70            key: ${{ runner.os }}-build-lint-${{ hashFiles('**/go.sum') }}
    71            restore-keys: ${{ runner.os }}-build-lint-
    72  
    73        - name: Cache Go Dependencies
    74          uses: actions/cache@v3
    75          with:
    76            path: .work/pkg
    77            key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
    78            restore-keys: ${{ runner.os }}-pkg-
    79  
    80        - name: Vendor Dependencies
    81          run: make vendor vendor.check
    82  
    83        # We could run 'make lint' to ensure our desired Go version, but we prefer
    84        # this action because it leaves 'annotations' (i.e. it comments on PRs to
    85        # point out linter violations).
    86        - name: Lint
    87          uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 # v3
    88          with:
    89            version: ${{ env.GOLANGCI_VERSION }}
    90  
    91    check-diff:
    92      runs-on: ubuntu-20.04
    93      needs: detect-noop
    94      if: needs.detect-noop.outputs.noop != 'true'
    95  
    96      steps:
    97        - name: Checkout
    98          uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 #v3
    99          with:
   100            submodules: true
   101  
   102        - name: Setup Go
   103          uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
   104          with:
   105            go-version: ${{ env.GO_VERSION }}
   106  
   107        - name: Find the Go Build Cache
   108          id: go-cache-paths
   109          run: |
   110            echo "go-build=$(make go.cachedir)" >> $GITHUB_OUTPUT
   111            echo "go-mod=$(make go.mod.cachedir)" >> $GITHUB_OUTPUT
   112  
   113        - name: Cache the Go Build Cache
   114          uses: actions/cache@v3
   115          with:
   116            path: ${{ steps.go-cache-paths.outputs.go-build }}
   117            key: ${{ runner.os }}-build-check-diff-${{ hashFiles('**/go.sum') }}
   118            restore-keys: ${{ runner.os }}-build-check-diff-
   119  
   120        - name: Cache Go Dependencies
   121          uses: actions/cache@v3
   122          with:
   123            path: ${{ steps.go-cache-paths.outputs.go-mod }}
   124            key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
   125            restore-keys: ${{ runner.os }}-pkg-
   126  
   127        - name: Vendor Dependencies
   128          run: make vendor vendor.check
   129  
   130        - name: Check Diff
   131          run: make check-diff
   132  
   133    unit-tests:
   134      runs-on: ubuntu-20.04
   135      needs: detect-noop
   136      if: needs.detect-noop.outputs.noop != 'true'
   137  
   138      steps:
   139        - name: Checkout
   140          uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 #v3
   141          with:
   142            submodules: true
   143  
   144        - name: Fetch History
   145          run: git fetch --prune --unshallow
   146  
   147        - name: Setup Go
   148          uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
   149          with:
   150            go-version: ${{ env.GO_VERSION }}
   151  
   152        - name: Find the Go Build Cache
   153          id: go-cache-paths
   154          run: |
   155            echo "go-build=$(make go.cachedir)" >> $GITHUB_OUTPUT
   156            echo "go-mod=$(make go.mod.cachedir)" >> $GITHUB_OUTPUT
   157  
   158        - name: Cache the Go Build Cache
   159          uses: actions/cache@v3
   160          with:
   161            path: ${{ steps.go-cache-paths.outputs.go-build }}
   162            key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
   163            restore-keys: ${{ runner.os }}-build-unit-tests-
   164  
   165        - name: Cache Go Dependencies
   166          uses: actions/cache@v3
   167          with:
   168            path: ${{ steps.go-cache-paths.outputs.go-mod }}
   169            key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
   170            restore-keys: ${{ runner.os }}-pkg-
   171  
   172        - name: Vendor Dependencies
   173          run: make vendor vendor.check
   174  
   175        - name: Run Unit Tests
   176          run: make -j2 test
   177  
   178        - name: Publish Unit Test Coverage
   179          uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3
   180          with:
   181            flags: unittests
   182            file: _output/tests/linux_amd64/coverage.txt