Skip to content

Commit c4b7f6d

Browse files
committed
15 | Add caching to workflow
1 parent 89959ef commit c4b7f6d

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

.github/workflows/test.yaml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,56 @@ permissions:
77
contents: read
88

99
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Cache Docker layers
17+
uses: actions/cache@v4
18+
with:
19+
path: /tmp/.buildx-cache
20+
key: ${{ runner.os }}-docker-flask-inputfilter-${{ hashFiles('Dockerfile', '**') }}
21+
restore-keys: |
22+
${{ runner.os }}-docker-flask-inputfilter-
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v2
26+
with:
27+
driver-opts: image=moby/buildkit:latest
28+
29+
- name: Build flask-inputfilter image with cache
30+
run: |
31+
docker buildx build \
32+
--cache-from=type=local,src=/tmp/.buildx-cache \
33+
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \
34+
-t flask-inputfilter flask-inputfilter --load
35+
-t flask-inputfilter . --load
36+
37+
- name: Save flask-inputfilter image
38+
run: docker save -o flask-inputfilter.tar flask-inputfilter
39+
40+
- name: Upload flask-inputfilter artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: flask-inputfilter-image
44+
path: flask-inputfilter.tar
45+
1046
test:
1147
runs-on: ubuntu-latest
1248

1349
steps:
1450
- name: Checkout code
1551
uses: actions/checkout@v4
1652

17-
- name: Build Docker image
18-
run: docker build . -t flask-inputfilter
53+
- name: Download flask-inputfilter artifact
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: flask-inputfilter-image
57+
58+
- name: Load flask-inputfilter image
59+
run: docker load -i flask-inputfilter.tar
1960

2061
- name: Run tests in Docker and upload coverage to Coveralls
2162
env:
@@ -25,12 +66,12 @@ jobs:
2566
set -e # Exit immediately if a command exits with a non-zero status.
2667
set -u # Exit immediately if a variable is not defined.
2768
28-
docker run -e COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} flask-inputfilter sh -c "coverage run --source=flask_inputfilter -m pytest test/ && coveralls"
69+
docker run --rm -e COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} flask-inputfilter sh -c "coverage run --source=flask_inputfilter -m pytest test/ && coveralls"
2970
3071
- name: Run code style checks
3172
run: |
3273
set -x # Print commands and their arguments as they are executed
3374
set -e # Exit immediately if a command exits with a non-zero status
3475
set -u # Exit immediately if a variable is not defined
3576
36-
docker run flask-inputfilter flake8
77+
docker run --rm flask-inputfilter flake8

0 commit comments

Comments
 (0)