github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/.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-16.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 "::set-env name=CACHE_RESULT_STAMP::$CACHE_RESULT_STAMP" 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-16.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 86 - name: Cache Debian dependencies 87 id: cache-deb-downloads 88 uses: actions/cache@v1 89 with: 90 path: /var/cache/apt 91 key: var-cache-apt-{{ hashFiles('**/debian/control') }} 92 - name: Run "apt update" 93 run: | 94 sudo apt update 95 - name: Download Debian dependencies 96 if: steps.cache-deb-downloads.outputs.cache-hit != 'true' 97 run: | 98 sudo apt clean 99 sudo apt build-dep -d -y ${{ github.workspace }}/src/github.com/snapcore/snapd 100 101 - name: Cache snapd test results 102 id: cache-snapd-test-results 103 uses: actions/cache@v1 104 with: 105 path: "${{ github.workspace }}/.test-results" 106 # must include matrix or things get racy, i.e. when latest/edge 107 # finishes after 1.9 it overrides the results from 1.9 108 key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.gochannel }}-results" 109 - name: Check cached test results 110 id: cached-results 111 run: | 112 CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.gochannel }}-success" 113 echo "::set-env name=CACHE_RESULT_STAMP::$CACHE_RESULT_STAMP" 114 if [ -e "$CACHE_RESULT_STAMP" ]; then 115 echo "::set-output name=already-ran::true" 116 fi 117 - name: Install Debian dependencies 118 if: steps.cached-results.outputs.cached-resulsts != 'true' 119 run: | 120 sudo apt build-dep -y ${{ github.workspace }}/src/github.com/snapcore/snapd 121 # golang latest ensures things work on the edge 122 - name: Install the go snap 123 if: steps.cached-results.outputs.already-ran != 'true' 124 run: | 125 sudo snap install --classic --channel=${{ matrix.gochannel }} go 126 - name: Install ShellCheck as a snap 127 if: steps.cached-results.outputs.already-ran != 'true' 128 run: | 129 sudo apt-get remove --purge shellcheck 130 sudo snap install shellcheck 131 - name: Install govendor 132 run: go get -u github.com/kardianos/govendor 133 - name: Cache Go dependencies 134 id: cache-go-govendor 135 uses: actions/cache@v1 136 with: 137 path: ${{ github.workspace }}/.cache/govendor 138 key: go-govendor-{{ hashFiles('**/vendor.json') }} 139 - name: Get Go dependencies 140 run: cd ${{ github.workspace }}/src/github.com/snapcore/snapd && ${{ github.workspace }}/bin/govendor sync 141 - name: Run static checks 142 if: steps.cached-results.outputs.already-ran != 'true' 143 run: | 144 cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1 145 # run gofmt checks only with Go 1.9 and 1.10 146 if ! echo "${{ matrix.gochannel }}" | grep -E '1\.(9|10)' ; then 147 # and skip with other versions 148 export SKIP_GOFMT=1 149 echo "Formatting checks will be skipped due to the use of Go version ${{ matrix.gochannel }}" 150 fi 151 ./run-checks --static 152 - name: Build C 153 if: steps.cached-results.outputs.already-ran != 'true' 154 run: | 155 cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/ 156 ./autogen.sh 157 make -j2 158 - name: Build Go 159 if: steps.cached-results.outputs.already-ran != 'true' 160 run: | 161 go build github.com/snapcore/snapd/... 162 - name: Test C 163 if: steps.cached-results.outputs.already-ran != 'true' 164 run: | 165 cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/ && make check 166 - name: Test Go 167 if: steps.cached-results.outputs.already-ran != 'true' 168 run: | 169 cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1 170 ./run-checks --unit 171 - name: Cache successful run 172 run: | 173 mkdir -p $(dirname "$CACHE_RESULT_STAMP") 174 touch "$CACHE_RESULT_STAMP" 175 176 spread: 177 needs: [unit-tests] 178 runs-on: self-hosted 179 strategy: 180 # FIXME: enable fail-fast mode once spread can cancel an executing job. 181 # Disable fail-fast mode as it doesn't function with spread. It seems 182 # that cancelling tasks requires short, interruptible actions and 183 # interrupting spread, notably, does not work today. As such disable 184 # fail-fast while we tackle that problem upstream. 185 fail-fast: false 186 matrix: 187 system: 188 - amazon-linux-2-64 189 - arch-linux-64 190 - centos-7-64 191 - centos-8-64 192 - debian-9-64 193 - debian-sid-64 194 - fedora-31-64 195 - fedora-32-64 196 - opensuse-15.1-64 197 - opensuse-15.2-64 198 - opensuse-tumbleweed-64 199 - ubuntu-14.04-64 200 - ubuntu-16.04-32 201 - ubuntu-16.04-64 202 - ubuntu-18.04-64 203 - ubuntu-20.04-64 204 - ubuntu-20.10-64 205 - ubuntu-core-16-64 206 - ubuntu-core-18-64 207 - ubuntu-core-20-64 208 - ubuntu-secboot-20.04-64 209 steps: 210 - name: Checkout code 211 uses: actions/checkout@v2 212 - name: Cache snapd test results 213 id: cache-snapd-test-results 214 uses: actions/cache@v1 215 with: 216 path: "${{ github.workspace }}/.test-results" 217 key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.system }}-results" 218 - name: Check cached test results 219 id: cached-results 220 run: | 221 CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.system }}-success" 222 echo "::set-env name=CACHE_RESULT_STAMP::$CACHE_RESULT_STAMP" 223 if [ -e "$CACHE_RESULT_STAMP" ]; then 224 echo "::set-output name=already-ran::true" 225 fi 226 - name: Run spread tests 227 if: "!contains(github.event.pull_request.labels.*.name, 'Skip spread') && steps.cached-results.outputs.already-ran != 'true'" 228 env: 229 SPREAD_GOOGLE_KEY: ${{ secrets.SPREAD_GOOGLE_KEY }} 230 run: | 231 # Register a problem matcher to highlight spread failures 232 echo "::add-matcher::.github/spread-problem-matcher.json" 233 spread -abend google:${{ matrix.system }}:tests/... 234 - name: Cache successful run 235 run: | 236 mkdir -p $(dirname "$CACHE_RESULT_STAMP") 237 touch "$CACHE_RESULT_STAMP" 238 - name: Discard spread workers 239 if: always() 240 run: | 241 shopt -s nullglob; 242 for r in .spread-reuse.*.yaml; do 243 spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')"; 244 done 245 246 spread-nested: 247 needs: [unit-tests] 248 runs-on: self-hosted 249 strategy: 250 # FIXME: enable fail-fast mode once spread can cancel an executing job. 251 # Disable fail-fast mode as it doesn't function with spread. It seems 252 # that cancelling tasks requires short, interruptible actions and 253 # interrupting spread, notably, does not work today. As such disable 254 # fail-fast while we tackle that problem upstream. 255 fail-fast: false 256 matrix: 257 system: 258 - ubuntu-16.04-64 259 - ubuntu-18.04-64 260 - ubuntu-20.04-64 261 steps: 262 - name: Checkout code 263 uses: actions/checkout@v2 264 - name: Cache snapd test results 265 id: cache-snapd-test-results 266 uses: actions/cache@v1 267 with: 268 path: "${{ github.workspace }}/.test-results" 269 key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.system }}-nested-results" 270 - name: Check cached test results 271 id: cached-results 272 run: | 273 CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.system }}-nested-success" 274 echo "::set-env name=CACHE_RESULT_STAMP::$CACHE_RESULT_STAMP" 275 if [ -e "$CACHE_RESULT_STAMP" ]; then 276 echo "::set-output name=already-ran::true" 277 fi 278 - name: Run spread tests 279 if: "contains(github.event.pull_request.labels.*.name, 'Run nested') && steps.cached-results.outputs.already-ran != 'true'" 280 env: 281 SPREAD_GOOGLE_KEY: ${{ secrets.SPREAD_GOOGLE_KEY }} 282 run: | 283 # Register a problem matcher to highlight spread failures 284 echo "::add-matcher::.github/spread-problem-matcher.json" 285 export NESTED_BUILD_SNAPD_FROM_CURRENT=true 286 export NESTED_ENABLE_KVM=true 287 if [ "${{ matrix.system }}" = "ubuntu-20.04-64" ]; then 288 export NESTED_ENABLE_KVM=false 289 fi 290 spread -abend google-nested:${{ matrix.system }}:tests/nested/... 291 - name: Cache successful run 292 run: | 293 mkdir -p $(dirname "$CACHE_RESULT_STAMP") 294 touch "$CACHE_RESULT_STAMP" 295 - name: Discard spread workers 296 if: always() 297 run: | 298 shopt -s nullglob; 299 for r in .spread-reuse.*.yaml; do 300 spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')"; 301 done