Skip to content

Commit

Permalink
Merge pull request #18 from satackey/use-matrix-in-test-workflow
Browse files Browse the repository at this point in the history
Use matrix in test workflow
  • Loading branch information
satackey authored Aug 8, 2020
2 parents 165f244 + b361d9b commit 0c6d193
Showing 1 changed file with 48 additions and 93 deletions.
141 changes: 48 additions & 93 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,43 @@ jobs:
name: built
path: ./

#
# test built image caching

test_saving_built:
runs-on: ubuntu-latest
needs: build
- name: Output matrix
id: set_matrix
uses: actions/github-script@v2
with:
script: |
return {
inspect_image: [
'test_project_node',
'amazon/aws-cli',
],
include: [
{
inspect_image: 'test_project_node',
prepare_command: 'docker-compose -f test_project/docker-compose.yml -p test_project pull',
build_command: 'docker-compose -f test_project/docker-compose.yml -p test_project build',
}, {
inspect_image: 'amazon/aws-cli',
prepare_command: ':',
build_command: 'docker pull amazon/aws-cli',
},
],
}
outputs:
matrix: ${{ steps.set_matrix.outputs.result }}

test_saving:
if: github.event_name != 'delete'
needs: build
strategy:
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- run: docker-compose -f test_project/docker-compose.yml -p test_project pull

- run: ${{ matrix.prepare_command }}

- name: Extract
id: extract
Expand All @@ -64,92 +90,21 @@ jobs:
- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ steps.extract.outputs.branch }}
with:
key: docker-layer-caching-test_project_node-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-test_project_node-sha:${{ github.sha }}-
key: docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-

- run: docker-compose -f test_project/docker-compose.yml -p test_project build
- run: ${{ matrix.build_command }}

test_restoring_built:
test_restoring:
needs: [build, test_saving]
strategy:
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
runs-on: ubuntu-latest
needs: test_saving_built

steps:
- uses: actions/checkout@v2
- run: docker-compose -f test_project/docker-compose.yml -p test_project pull

- name: Extract
id: extract
run: |
echo "##[set-output name=branch;]${GITHUB_REF#refs/heads/}"
- name: Download action
uses: actions/download-artifact@v2
with:
name: built
path: action-dlc

- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ steps.extract.outputs.branch }}
with:
key: docker-layer-caching-test_project_node-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-test_project_node-sha:${{ github.sha }}-

- name: Show cached image info
run: docker inspect test_project_node

- name: Get cached image ID
run: echo ::set-output name=id::$(docker image ls -q test_project_node)
id: cached

- run: docker-compose -f test_project/docker-compose.yml -p test_project build

- name: Show built image info
run: docker inspect test_project_node

- name: Show built image ID
run: echo ::set-output name=id::$(docker image ls -q test_project_node)
id: latest
- run: ${{ matrix.prepare_command }}

- name: Compare cached ID and after build ID
run: |
if [ ! '${{ steps.cached.outputs.id }}' = '${{ steps.latest.outputs.id }}' ];then
echo cached != latest
exit 1
fi
#
# test pulled image caching

test_saving_pulled:
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'delete'

steps:
- name: Extract
id: extract
run: |
echo "##[set-output name=branch;]${GITHUB_REF#refs/heads/}"
- name: Download action
uses: actions/download-artifact@v2
with:
name: built
path: action-dlc

- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ steps.extract.outputs.branch }}
with:
key: docker-layer-caching-aws-cli-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-aws-cli-sha:${{ github.sha }}-

- run: docker run --rm amazon/aws-cli --version

test_restoring_pulled:
runs-on: ubuntu-latest
needs: test_saving_pulled

steps:
- name: Extract
id: extract
run: |
Expand All @@ -164,23 +119,23 @@ jobs:
- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ steps.extract.outputs.branch }}
with:
key: docker-layer-caching-aws-cli-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-aws-cli-sha:${{ github.sha }}-
key: docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-

- name: Show cached image info
run: docker inspect amazon/aws-cli
run: docker inspect ${{ matrix.inspect_image }}

- name: Get cached image ID
run: echo ::set-output name=id::$(docker image ls -q amazon/aws-cli)
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
id: cached

- run: docker pull amazon/aws-cli
- run: ${{ matrix.build_command }}

- name: Show built image info
run: docker inspect amazon/aws-cli
run: docker inspect ${{ matrix.inspect_image }}

- name: Show built image ID
run: echo ::set-output name=id::$(docker image ls -q amazon/aws-cli)
run: echo ::set-output name=id::$(docker image ls -q ${{ matrix.inspect_image }})
id: latest

- name: Compare cached ID and after build ID
Expand Down

0 comments on commit 0c6d193

Please sign in to comment.