github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/.github/workflows/checks.yml (about)

     1  # This workflow is a collection of "quick checks" that should be reasonable
     2  # to run for any new commit to this repository in principle.
     3  #
     4  # The main purpose of this workflow is to represent checks that we want to
     5  # run prior to reviewing and merging a pull request. We should therefore aim
     6  # for these checks to complete in no more than a few minutes in the common
     7  # case.
     8  #
     9  # The build.yml workflow includes some additional checks we run only for
    10  # already-merged changes to release branches and tags, as a compromise to
    11  # keep the PR feedback relatively fast. The intent is that checks.yml should
    12  # catch most problems but that build.yml might occasionally by the one to catch
    13  # more esoteric situations, such as architecture-specific or OS-specific
    14  # misbehavior.
    15  
    16  name: Quick Checks
    17  
    18  on:
    19    pull_request:
    20    push:
    21      branches:
    22        - main
    23        - 'v[0-9]+.[0-9]+'
    24        - checks-workflow-dev/*
    25      tags:
    26        - 'v[0-9]+.[0-9]+.[0-9]+*'
    27  
    28  # This workflow runs for not-yet-reviewed external contributions and so it
    29  # intentionally has no write access and only limited read access to the
    30  # repository.
    31  permissions:
    32    contents: read
    33  
    34  jobs:
    35    unit-tests:
    36      name: "Unit Tests"
    37      runs-on: ubuntu-latest
    38  
    39      steps:
    40        - name: "Fetch source code"
    41          uses: actions/checkout@v2
    42  
    43        - name: Determine Go version
    44          id: go
    45          uses: ./.github/actions/go-version
    46  
    47        - name: Install Go toolchain
    48          uses: actions/setup-go@v2
    49          with:
    50            go-version: ${{ steps.go.outputs.version }}
    51  
    52        # NOTE: This cache is shared so the following step must always be
    53        # identical across the unit-tests, e2e-tests, and consistency-checks
    54        # jobs, or else weird things could happen.
    55        - name: Cache Go modules
    56          uses: actions/cache@v3
    57          with:
    58            path: "~/go/pkg"
    59            key: go-mod-${{ hashFiles('go.sum') }}
    60            restore-keys: |
    61              go-mod-
    62  
    63        - name: "Unit tests"
    64          run: |
    65            go test ./...
    66  
    67    race-tests:
    68      name: "Race Tests"
    69      runs-on: ubuntu-latest
    70  
    71      steps:
    72        - name: "Fetch source code"
    73          uses: actions/checkout@v2
    74  
    75        - name: Determine Go version
    76          id: go
    77          uses: ./.github/actions/go-version
    78  
    79        - name: Install Go toolchain
    80          uses: actions/setup-go@v2
    81          with:
    82            go-version: ${{ steps.go.outputs.version }}
    83  
    84        # NOTE: This cache is shared so the following step must always be
    85        # identical across the unit-tests, e2e-tests, and consistency-checks
    86        # jobs, or else weird things could happen.
    87        - name: Cache Go modules
    88          uses: actions/cache@v3
    89          with:
    90            path: "~/go/pkg"
    91            key: go-mod-${{ hashFiles('go.sum') }}
    92            restore-keys: |
    93              go-mod-
    94  
    95        # The race detector add significant time to the unit tests, so only run
    96        # it for select packages.
    97        - name: "Race detector"
    98          run: |
    99            go test -race ./internal/terraform ./internal/command ./internal/states
   100  
   101    e2e-tests:
   102      # This is an intentionally-limited form of our E2E test run which only
   103      # covers Terraform running on Linux. The build.yml workflow runs these
   104      # tests across various other platforms in order to catch the rare exception
   105      # that might leak through this.
   106      name: "End-to-end Tests"
   107      runs-on: ubuntu-latest
   108  
   109      steps:
   110        - name: "Fetch source code"
   111          uses: actions/checkout@v2
   112  
   113        - name: Determine Go version
   114          id: go
   115          uses: ./.github/actions/go-version
   116  
   117        - name: Install Go toolchain
   118          uses: actions/setup-go@v2
   119          with:
   120            go-version: ${{ steps.go.outputs.version }}
   121  
   122        # NOTE: This cache is shared so the following step must always be
   123        # identical across the unit-tests, e2e-tests, and consistency-checks
   124        # jobs, or else weird things could happen.
   125        - name: Cache Go modules
   126          uses: actions/cache@v3
   127          with:
   128            path: "~/go/pkg"
   129            key: go-mod-${{ hashFiles('go.sum') }}
   130            restore-keys: |
   131              go-mod-
   132  
   133        - name: "End-to-end tests"
   134          run: |
   135            TF_ACC=1 go test -v ./internal/command/e2etest
   136  
   137    consistency-checks:
   138      name: "Code Consistency Checks"
   139      runs-on: ubuntu-latest
   140  
   141      steps:
   142        - name: "Fetch source code"
   143          uses: actions/checkout@v2
   144          with:
   145            fetch-depth: 0 # We need to do comparisons against the main branch.
   146  
   147        - name: Determine Go version
   148          id: go
   149          uses: ./.github/actions/go-version
   150  
   151        - name: Install Go toolchain
   152          uses: actions/setup-go@v2
   153          with:
   154            go-version: ${{ steps.go.outputs.version }}
   155  
   156        # NOTE: This cache is shared so the following step must always be
   157        # identical across the unit-tests, e2e-tests, and consistency-checks
   158        # jobs, or else weird things could happen.
   159        - name: Cache Go modules
   160          uses: actions/cache@v3
   161          with:
   162            path: "~/go/pkg"
   163            key: go-mod-${{ hashFiles('go.sum') }}
   164            restore-keys: |
   165              go-mod-
   166  
   167        - name: "go.mod and go.sum consistency check"
   168          run: |
   169            go mod tidy
   170            if [[ -n "$(git status --porcelain)" ]]; then
   171              echo >&2 "ERROR: go.mod/go.sum are not up-to-date. Run 'go mod tidy' and then commit the updated files."
   172              exit 1
   173            fi
   174  
   175        - name: Cache protobuf tools
   176          uses: actions/cache@v3
   177          with:
   178            path: "tools/protobuf-compile/.workdir"
   179            key: protobuf-tools-${{ hashFiles('tools/protobuf-compile/protobuf-compile.go') }}
   180            restore-keys: |
   181              protobuf-tools-
   182  
   183        - name: Install CI tooling
   184          run: |
   185            go install golang.org/x/tools/cmd/goimports@v0.1.11
   186  
   187        - name: "Code consistency checks"
   188          run: |
   189            make fmtcheck importscheck generate staticcheck exhaustive protobuf
   190            if [[ -n "$(git status --porcelain)" ]]; then
   191              echo >&2 "ERROR: Generated files are inconsistent. Run 'make generate' and 'make protobuf' locally and then commit the updated files."
   192              git >&2 status --porcelain
   193              exit 1
   194            fi