github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/.github/workflows/test.yaml (about)

     1  name: Tests
     2  on:
     3    pull_request:
     4      branches: [ "master", "release/**" ]
     5    push:
     6      branches: [ "release/**" ]
     7  
     8  jobs:
     9    snap-builds:
    10      runs-on: ubuntu-20.04
    11      steps:
    12      - name: Checkout code
    13        uses: actions/checkout@v2
    14      - name: Cache snapd snap build status
    15        id: cache-snapd-build-status
    16        uses: actions/cache@v1
    17        with:
    18          path: "${{ github.workspace }}/.test-results"
    19          key: "${{ github.run_id }}-${{ github.job }}-results"
    20      - name: Check cached snap build
    21        id: cached-results
    22        run: |
    23            CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/snap-build-success"
    24            echo "CACHE_RESULT_STAMP=$CACHE_RESULT_STAMP" >> $GITHUB_ENV
    25            if [ -e "$CACHE_RESULT_STAMP" ]; then
    26                has_cached_snap=0
    27                while read name; do
    28                    has_cached_snap=1
    29                    # bring back artifacts from the cache
    30                    cp -v "$name" "${{ github.workspace }}"
    31                done < <(find "$(dirname $CACHE_RESULT_STAMP)" -name "*.snap")
    32                if [ "$has_cached_snap" = "1" ]; then
    33                    # we have restored an artifact from the cache
    34                    echo "::set-output name=already-ran::true"
    35                fi
    36            fi
    37      - name: Build snapd snap
    38        if: steps.cached-results.outputs.already-ran != 'true'
    39        uses: snapcore/action-build@v1
    40      - name: Cache built artifact
    41        run: |
    42          mkdir -p $(dirname "$CACHE_RESULT_STAMP")
    43          cp -v *.snap "$(dirname $CACHE_RESULT_STAMP)/"
    44      - name: Uploading snapd snap artifact
    45        uses: actions/upload-artifact@v2
    46        with:
    47          name: snap-files
    48          path: "*.snap"
    49      - name: Mark successful snap build
    50        run: |
    51          mkdir -p $(dirname "$CACHE_RESULT_STAMP")
    52          touch "$CACHE_RESULT_STAMP"
    53  
    54    unit-tests:
    55      runs-on: ubuntu-20.04
    56      env:
    57        GOPATH: ${{ github.workspace }}
    58        GO111MODULE: off
    59        # Set PATH to ignore the load of magic binaries from /usr/local/bin And
    60        # to use the go snap automatically. Note that we install go from the
    61        # snap in a step below. Without this we get the GitHub-controlled latest
    62        # version of go.
    63        PATH: /snap/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
    64        GOROOT: ""
    65        # XXX: compat env for "check-pr-title.py" in "run-checks", can go
    66        #      once we switch away from that. Note that we cannot currently
    67        #      use a github action check (like deepakputhraya/action-pr-title)
    68        #      because an update of the PR title in the github UI is not visible
    69        #      to the github action.
    70        TRAVIS_PULL_REQUEST: ${{ github.event.number }}
    71      strategy:
    72        # we cache successful runs so it's fine to keep going
    73        fail-fast: false      
    74        matrix:
    75          gochannel:
    76            - 1.9
    77            - latest/stable
    78      steps:
    79      - name: Checkout code
    80        uses: actions/checkout@v2
    81        with:
    82          # NOTE: checkout the code in a fixed location, even for forks, as this
    83          # is relevant for go's import system.
    84          path: ./src/github.com/snapcore/snapd
    85      # Fetch base ref, needed for golangci-lint
    86      - name: Fetching base ref ${{ github.base_ref }}
    87        run: |
    88          cd ${{ github.workspace }}/src/github.com/snapcore/snapd
    89          git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
    90      - name: Cache Debian dependencies
    91        id: cache-deb-downloads
    92        uses: actions/cache@v1
    93        with:
    94          path: /var/cache/apt
    95          key: var-cache-apt-{{ hashFiles('**/debian/control') }}
    96      - name: Run "apt update"
    97        run: |
    98            sudo apt update
    99      - name: Download Debian dependencies
   100        if: steps.cache-deb-downloads.outputs.cache-hit != 'true'
   101        run: |
   102            sudo apt clean
   103            sudo apt build-dep -d -y ${{ github.workspace }}/src/github.com/snapcore/snapd
   104  
   105      - name: Cache snapd test results
   106        id: cache-snapd-test-results
   107        uses: actions/cache@v1
   108        with:
   109          path: "${{ github.workspace }}/.test-results"
   110          # must include matrix or things get racy, i.e. when latest/edge
   111          # finishes after 1.9 it overrides the results from 1.9
   112          key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.gochannel }}-results"
   113      - name: Check cached test results
   114        id: cached-results
   115        run: |
   116            CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.gochannel }}-success"
   117            echo "CACHE_RESULT_STAMP=$CACHE_RESULT_STAMP" >> $GITHUB_ENV
   118            if [ -e "$CACHE_RESULT_STAMP" ]; then
   119                echo "::set-output name=already-ran::true"
   120            fi
   121      - name: Install Debian dependencies
   122        if: steps.cached-results.outputs.cached-resulsts != 'true'
   123        run: |
   124            sudo apt build-dep -y ${{ github.workspace }}/src/github.com/snapcore/snapd
   125      # golang latest ensures things work on the edge
   126      - name: Install the go snap
   127        if: steps.cached-results.outputs.already-ran != 'true'
   128        run: |
   129            sudo snap install --classic --channel=${{ matrix.gochannel }} go
   130      - name: Install ShellCheck as a snap
   131        if: steps.cached-results.outputs.already-ran != 'true'
   132        run: |
   133            sudo apt-get remove --purge shellcheck
   134            sudo snap install shellcheck
   135      - name: Install govendor
   136        run: go get -u github.com/kardianos/govendor
   137      - name: Cache Go dependencies
   138        id: cache-go-govendor
   139        uses: actions/cache@v1
   140        with:
   141          path: ${{ github.workspace }}/.cache/govendor
   142          key: go-govendor-{{ hashFiles('**/vendor.json') }}
   143      - name: Get Go dependencies
   144        run: cd ${{ github.workspace }}/src/github.com/snapcore/snapd && ${{ github.workspace }}/bin/govendor sync
   145  
   146      - name: golangci-lint
   147        uses: golangci/golangci-lint-action@v2
   148        if: ${{ matrix.gochannel == 'latest/stable' }}
   149        with:
   150          # version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest`
   151          # to use the latest version
   152          version: v1.40.0
   153          working-directory: ./src/github.com/snapcore/snapd
   154          # show only new issues
   155          # use empty path prefix to make annotations work
   156          # TODO: start failing once the config is tuned properly
   157          args: --new-from-rev=${{ github.base_ref }} --path-prefix= --issues-exit-code=0
   158          # skip all additional steps
   159          skip-go-installation: true
   160          skip-pkg-cache: true
   161          skip-build-cache: true
   162          # XXX: does no work with working-directory
   163          # only-new-issues: true
   164  
   165      - name: Run static checks
   166        if: steps.cached-results.outputs.already-ran != 'true'
   167        run: |
   168            cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
   169            # run gofmt checks only with Go 1.9 and 1.10
   170            if ! echo "${{ matrix.gochannel }}" | grep -E '1\.(9|10)' ; then
   171                # and skip with other versions
   172                export SKIP_GOFMT=1
   173                echo "Formatting checks will be skipped due to the use of Go version ${{ matrix.gochannel }}"
   174            fi
   175            sudo apt-get install -y python3-yamlordereddictloader
   176            ./run-checks --static
   177      - name: Build C
   178        if: steps.cached-results.outputs.already-ran != 'true'
   179        run: |
   180            cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/
   181            ./autogen.sh
   182            make -j2
   183      - name: Build Go
   184        if: steps.cached-results.outputs.already-ran != 'true'
   185        run: |
   186            go build github.com/snapcore/snapd/...
   187      - name: Test C
   188        if: steps.cached-results.outputs.already-ran != 'true'
   189        run: |
   190            cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/ && make check
   191      - name: Test Go
   192        if: steps.cached-results.outputs.already-ran != 'true'
   193        run: |
   194          cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
   195          ./run-checks --unit
   196      - name: Test Go (withbootassetstesting)
   197        if: steps.cached-results.outputs.already-ran != 'true'
   198        run: |
   199          cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
   200          SKIP_COVERAGE=1 SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=withbootassetstesting ./run-checks --unit
   201      - name: Test Go (nosecboot)
   202        if: steps.cached-results.outputs.already-ran != 'true'
   203        run: |
   204          cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
   205          echo "Dropping github.com/snapcore/secboot"
   206          # use govendor remove so that a subsequent govendor sync does not
   207          # install secboot again
   208          ${{ github.workspace }}/bin/govendor remove github.com/snapcore/secboot
   209          ${{ github.workspace }}/bin/govendor remove +unused
   210          # we don't need coverage anymore
   211          SKIP_COVERAGE=1 SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=nosecboot ./run-checks --unit
   212      - name: Cache successful run
   213        run: |
   214          mkdir -p $(dirname "$CACHE_RESULT_STAMP")
   215          touch "$CACHE_RESULT_STAMP"
   216  
   217    spread:
   218      needs: [unit-tests]
   219      runs-on: self-hosted
   220      strategy:
   221        # FIXME: enable fail-fast mode once spread can cancel an executing job.
   222        # Disable fail-fast mode as it doesn't function with spread. It seems
   223        # that cancelling tasks requires short, interruptible actions and
   224        # interrupting spread, notably, does not work today. As such disable
   225        # fail-fast while we tackle that problem upstream.
   226        fail-fast: false
   227        matrix:
   228          system:
   229          - amazon-linux-2-64
   230          - arch-linux-64
   231          - centos-7-64
   232          - centos-8-64
   233          - debian-10-64
   234          - debian-sid-64
   235          - fedora-33-64
   236          - fedora-34-64
   237          - opensuse-15.1-64
   238          - opensuse-15.2-64
   239          - opensuse-tumbleweed-64
   240          - ubuntu-14.04-64
   241          - ubuntu-16.04-64
   242          - ubuntu-18.04-32
   243          - ubuntu-18.04-64
   244          - ubuntu-20.04-64
   245          - ubuntu-20.10-64
   246          - ubuntu-21.04-64
   247          - ubuntu-core-16-64
   248          - ubuntu-core-18-64
   249          - ubuntu-core-20-64
   250          - ubuntu-secboot-20.04-64
   251      steps:
   252      - name: Checkout code
   253        uses: actions/checkout@v2
   254        with:
   255          # spread uses tags as delta reference
   256          fetch-depth: 0
   257      - name: Cache snapd test results
   258        id: cache-snapd-test-results
   259        uses: actions/cache@v1
   260        with:
   261          path: "${{ github.workspace }}/.test-results"
   262          key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.system }}-results"
   263      - name: Check cached test results
   264        id: cached-results
   265        run: |
   266            CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.system }}-success"
   267            echo "CACHE_RESULT_STAMP=$CACHE_RESULT_STAMP" >> $GITHUB_ENV
   268            if [ -e "$CACHE_RESULT_STAMP" ]; then
   269                echo "::set-output name=already-ran::true"
   270            fi
   271      - name: Run spread tests
   272        if: "!contains(github.event.pull_request.labels.*.name, 'Skip spread') && steps.cached-results.outputs.already-ran != 'true'"
   273        env:
   274            SPREAD_GOOGLE_KEY: ${{ secrets.SPREAD_GOOGLE_KEY }}
   275        run: |
   276            # Register a problem matcher to highlight spread failures
   277            echo "::add-matcher::.github/spread-problem-matcher.json"
   278            spread -abend google:${{ matrix.system }}:tests/...
   279      - name: Cache successful run
   280        run: |
   281          mkdir -p $(dirname "$CACHE_RESULT_STAMP")
   282          touch "$CACHE_RESULT_STAMP"
   283      - name: Discard spread workers
   284        if: always()
   285        run: |
   286          shopt -s nullglob;
   287          for r in .spread-reuse.*.yaml; do
   288            spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')";
   289          done
   290  
   291    spread-nested:
   292      needs: [unit-tests]
   293      runs-on: self-hosted
   294      strategy:
   295        # FIXME: enable fail-fast mode once spread can cancel an executing job.
   296        # Disable fail-fast mode as it doesn't function with spread. It seems
   297        # that cancelling tasks requires short, interruptible actions and
   298        # interrupting spread, notably, does not work today. As such disable
   299        # fail-fast while we tackle that problem upstream.
   300        fail-fast: false
   301        matrix:
   302          system:
   303          - ubuntu-16.04-64
   304          - ubuntu-18.04-64
   305          - ubuntu-20.04-64
   306          - ubuntu-20.10-64
   307      steps:
   308      - name: Checkout code
   309        uses: actions/checkout@v2
   310      - name: Cache snapd test results
   311        id: cache-snapd-test-results
   312        uses: actions/cache@v1
   313        with:
   314          path: "${{ github.workspace }}/.test-results"
   315          key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.system }}-nested-results"
   316      - name: Check cached test results
   317        id: cached-results
   318        run: |
   319            CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.system }}-nested-success"
   320            echo "CACHE_RESULT_STAMP=$CACHE_RESULT_STAMP" >> $GITHUB_ENV
   321            if [ -e "$CACHE_RESULT_STAMP" ]; then
   322                echo "::set-output name=already-ran::true"
   323            fi
   324      - name: Run spread tests
   325        # run if the commit is pushed to the release/* branch or there is a 'Run
   326        # nested' label set on the PR
   327        if: "(contains(github.event.pull_request.labels.*.name, 'Run nested') || contains(github.ref, 'refs/heads/release/')) && steps.cached-results.outputs.already-ran != 'true'"
   328        env:
   329            SPREAD_GOOGLE_KEY: ${{ secrets.SPREAD_GOOGLE_KEY }}
   330        run: |
   331            # Register a problem matcher to highlight spread failures
   332            echo "::add-matcher::.github/spread-problem-matcher.json"
   333            export NESTED_BUILD_SNAPD_FROM_CURRENT=true
   334            export NESTED_ENABLE_KVM=true
   335            spread -abend google-nested:${{ matrix.system }}:tests/nested/...
   336      - name: Cache successful run
   337        run: |
   338          mkdir -p $(dirname "$CACHE_RESULT_STAMP")
   339          touch "$CACHE_RESULT_STAMP"
   340      - name: Discard spread workers
   341        if: always()
   342        run: |
   343          shopt -s nullglob;
   344          for r in .spread-reuse.*.yaml; do
   345            spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')";
   346          done