|
| 1 | +name: Test workflows |
| 2 | +on: [push, pull_request] |
| 3 | + |
| 4 | +# Avoid multiple caching tests stomping over each other |
| 5 | +concurrency: mainline-cache-${{ github.sha }} |
| 6 | + |
| 7 | +jobs: |
| 8 | + # We need to start with a clean slate for this SHA, so we can distinguish |
| 9 | + # between caches created in different ref contexts. |
| 10 | + clear-caches: |
| 11 | + name: Clear any existing caches |
| 12 | + permissions: |
| 13 | + actions: write |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Clear existing caches for this commit |
| 17 | + uses: actions/github-script@v6 |
| 18 | + with: |
| 19 | + script: | |
| 20 | + try { |
| 21 | + const response = await github.rest.actions.deleteActionsCacheByKey({ |
| 22 | + owner: context.repo.owner, |
| 23 | + repo: context.repo.repo, |
| 24 | + key: `mainline-build-${context.sha}` |
| 25 | + }); |
| 26 | + core.info(`Deleted ${response.data.total_count} caches`); |
| 27 | + if (core.isDebug()) { |
| 28 | + for (const cache of response.data.actions_caches) { |
| 29 | + core.debug(`Deleted cache ID ${cache.id}, ref ${cache.ref}, key ${cache.key}, version ${cache.version}`); |
| 30 | + } |
| 31 | + } |
| 32 | + } catch(e) { |
| 33 | + if (e.response.status == 404) { |
| 34 | + core.info('No caches to delete'); |
| 35 | + return; |
| 36 | + } |
| 37 | + throw(e); // Not the error we were looking for |
| 38 | + } |
| 39 | +
|
| 40 | + mainline: |
| 41 | + name: Basic mainline test |
| 42 | + needs: clear-caches |
| 43 | + uses: ./.github/workflows/build-test.yml |
| 44 | + with: |
| 45 | + cygport_file: t/mainline.cygport |
| 46 | + |
| 47 | + ensure-build-cache: |
| 48 | + name: Check there's a current build cache |
| 49 | + needs: mainline |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - name: Check number of caches for the mainline build |
| 53 | + id: check |
| 54 | + uses: actions/github-script@v6 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + const response = await github.rest.actions.getActionsCacheList({ |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + key: 'mainline-build-' + context.sha |
| 61 | + }); |
| 62 | + core.info(`Found ${response.data.total_count} caches`); |
| 63 | + if (response.data.total_count != 1) { |
| 64 | + core.setFailed(`Expected one cache entry, found ${response.data.total_count}.`); |
| 65 | + if (response.data.total_count > 0) { |
| 66 | + core.startGroup('Cache list'); |
| 67 | + response.data.actions_caches.forEach(cache => |
| 68 | + core.info(`cache id: ${cache.id}, ref: ${cache.ref}, key: ${cache.key}, version: ${cache.version}`)); |
| 69 | + core.endGroup(); |
| 70 | + } |
| 71 | + } |
| 72 | +
|
| 73 | + mainline-use-cache: |
| 74 | + name: Check a build won't create a new cache unnecessarily |
| 75 | + needs: mainline |
| 76 | + uses: ./.github/workflows/build-test.yml |
| 77 | + with: |
| 78 | + cygport_file: t/mainline.cygport |
| 79 | + |
| 80 | + ensure-cache-used: |
| 81 | + name: Check the build did use the extant cache |
| 82 | + needs: mainline-use-cache |
| 83 | + runs-on: ubuntu-latest |
| 84 | + steps: |
| 85 | + - name: Error if cache unused |
| 86 | + if: needs.mainline-use-cache.outputs.cache-found != 'true' |
| 87 | + run: | |
| 88 | + echo '::error title=Cache not used::Cache reportedly not used for rebuild' |
| 89 | + exit 1 |
0 commit comments