|
7 | 7 | schedule: |
8 | 8 | - cron: 0 0 */3 * * |
9 | 9 |
|
| 10 | +defaults: |
| 11 | + run: |
| 12 | + shell: bash |
| 13 | + |
10 | 14 | jobs: |
11 | | - no_cache_build: |
| 15 | + build: |
12 | 16 | runs-on: ubuntu-latest |
13 | 17 |
|
14 | 18 | steps: |
15 | | - - run: docker image ls -q | xargs docker rmi |
| 19 | + - name: Output matrix |
| 20 | + id: set_matrix |
| 21 | + uses: actions/github-script@v2 |
| 22 | + with: |
| 23 | + script: | |
| 24 | + return { |
| 25 | + inspect_image: [ |
| 26 | + 'test_project_scratch', |
| 27 | + 'hello-world', |
| 28 | + 'nothing' |
| 29 | + ], |
| 30 | + os: [ |
| 31 | + 'ubuntu-latest', |
| 32 | + 'windows-latest', |
| 33 | + ], |
| 34 | + include: [ |
| 35 | + { |
| 36 | + inspect_image: 'test_project_scratch', |
| 37 | + prepare_command: 'docker-compose -f test_project/docker-compose.yml -p test_project pull', |
| 38 | + build_command: 'docker-compose -f test_project/docker-compose.yml -p test_project build', |
| 39 | + }, { |
| 40 | + inspect_image: 'hello-world', |
| 41 | + prepare_command: ':', |
| 42 | + build_command: 'docker pull hello-world', |
| 43 | + }, { |
| 44 | + inspect_image: 'nothing', |
| 45 | + os: 'ubuntu-latest', |
| 46 | + prepare_command: 'docker tag node:12 nothing', |
| 47 | + build_command: ':', |
| 48 | + }, { |
| 49 | + inspect_image: 'nothing', |
| 50 | + os: 'windows-latest', |
| 51 | + prepare_command: 'docker tag mcr.microsoft.com/windows/nanoserver:1809 nothing', |
| 52 | + build_command: ':', |
| 53 | + }, { |
| 54 | + branch: process.env.GITHUB_REF.replace('refs/heads/', '') |
| 55 | + } |
| 56 | + ], |
| 57 | + exclude: [ |
| 58 | + { |
| 59 | + inspect_image: 'test_project_scratch', |
| 60 | + os: 'windows-latest', |
| 61 | + }, |
| 62 | + ], |
| 63 | + } |
| 64 | +
|
| 65 | + outputs: |
| 66 | + matrix: ${{ steps.set_matrix.outputs.result }} |
| 67 | + |
| 68 | + test_saving: |
| 69 | + if: github.event_name != 'delete' |
| 70 | + needs: build |
| 71 | + strategy: |
| 72 | + matrix: ${{ fromJSON(needs.build.outputs.matrix) }} |
| 73 | + runs-on: ${{ matrix.os }} |
| 74 | + |
| 75 | + steps: |
16 | 76 | - uses: actions/checkout@v2 |
17 | | - - run: docker-compose -f test_project/docker-compose.yml -p test_project pull |
18 | 77 |
|
19 | | - - uses: satackey/action-docker-layer-caching@v0.0.8 |
| 78 | + - run: ${{ matrix.prepare_command }} |
| 79 | + |
| 80 | + - uses: satackey/action-docker-layer-caching@master-release |
20 | 81 | with: |
21 | | - key: docker-layer-caching-${{ github.workflow }}-${{ github.event_name }}-{hash} |
22 | | - restore-keys: docker-layer-caching-${{ github.workflow }}-${{ github.event_name }}- |
| 82 | + key: docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash} |
| 83 | + restore-keys: '' |
23 | 84 |
|
24 | | - - run: docker image ls -q | xargs docker rmi |
25 | | - - run: docker-compose -f test_project/docker-compose.yml -p test_project build --no-cache |
| 85 | + - run: ${{ matrix.build_command }} |
26 | 86 |
|
27 | | - cached_build: |
28 | | - runs-on: ubuntu-latest |
29 | | - needs: |
30 | | - - no_cache_build |
| 87 | + test_restoring: |
| 88 | + needs: [build, test_saving] |
| 89 | + strategy: |
| 90 | + matrix: ${{ fromJSON(needs.build.outputs.matrix) }} |
| 91 | + runs-on: ${{ matrix.os }} |
31 | 92 |
|
32 | 93 | steps: |
33 | | - - run: docker image ls -q | xargs docker rmi |
34 | 94 | - uses: actions/checkout@v2 |
35 | | - - run: docker-compose -f test_project/docker-compose.yml -p test_project pull |
36 | 95 |
|
37 | | - - uses: satackey/action-docker-layer-caching@v0.0.8 |
| 96 | + - run: ${{ matrix.prepare_command }} |
| 97 | + |
| 98 | + - uses: satackey/action-docker-layer-caching@master-release |
38 | 99 | with: |
39 | | - key: docker-layer-caching-${{ github.workflow }}-${{ github.event_name }}-{hash} |
40 | | - restore-keys: docker-layer-caching-${{ github.workflow }}-${{ github.event_name }}- |
| 100 | + key: never-restored-docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash} |
| 101 | + restore-keys: docker-layer-caching-${{ github.workflow }}-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}- |
| 102 | + skip-save: 'true' |
| 103 | + |
| 104 | + - name: Show cached image info |
| 105 | + run: docker inspect ${{ matrix.inspect_image }} |
41 | 106 |
|
42 | 107 | - name: Get cached image ID |
43 | | - run: echo ::set-output name=id::$(docker image ls -q test_project_node) |
| 108 | + run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }}) |
44 | 109 | id: cached |
45 | 110 |
|
46 | | - - run: docker-compose -f test_project/docker-compose.yml -p test_project build |
| 111 | + - run: ${{ matrix.build_command }} |
| 112 | + |
| 113 | + - name: Show built image info |
| 114 | + run: docker inspect ${{ matrix.inspect_image }} |
47 | 115 |
|
48 | 116 | - name: Show built image ID |
49 | | - run: echo ::set-output name=id::$(docker image ls -q test_project_node) |
| 117 | + run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }}) |
50 | 118 | id: latest |
51 | 119 |
|
52 | 120 | - name: Compare cached ID and after build ID |
|
55 | 123 | echo cached != latest |
56 | 124 | exit 1 |
57 | 125 | fi |
58 | | -
|
|
0 commit comments