-
Notifications
You must be signed in to change notification settings - Fork 45
128 lines (109 loc) · 3.6 KB
/
ci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: ci
on:
push:
branches: [main, develop]
pull_request_target:
types: [assigned, opened, synchronize, reopened]
env:
REGISTRY: ghcr.io
jobs:
setup:
runs-on: ubuntu-latest
outputs:
ci_name_ref_slug: ${{ steps.set_env.outputs.ci_name_ref_slug }}
image_name: ${{ steps.set_env.outputs.image_name }}
steps:
- uses: FranzDiebold/github-env-vars-action@v2
- name: Generate global env vars
id: set_env
run: |
echo "::set-output name=ci_name_ref_slug::$CI_REF_NAME_SLUG"
echo "::set-output name=image_name::$REGISTRY/$CI_REPOSITORY_OWNER_SLUG/$CI_REPOSITORY_NAME_SLUG"
build:
needs: [setup]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ needs.setup.outputs.image_name }}
# - name: Build and push Docker image
# uses: docker/build-push-action@v3
# with:
# context: .
# file: dev.Dockerfile
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
- name: Build and push test Docker image
uses: docker/build-push-action@v4
with:
context: .
file: dev.Dockerfile
push: true
target: test-image
tags: "${{ needs.setup.outputs.image_name }}/test:${{ github.sha }},${{ needs.setup.outputs.image_name }}/test:${{ needs.setup.outputs.ci_name_ref_slug }}"
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push tool Docker image
uses: docker/build-push-action@v4
with:
context: .
file: tool.Dockerfile
push: true
tags: "${{ needs.setup.outputs.image_name }}/tool:${{ github.sha }},${{ needs.setup.outputs.image_name }}/tool:${{ needs.setup.outputs.ci_name_ref_slug }}"
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
style:
needs: [build]
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/qdax/tool:${{ github.sha }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run pre-commits
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
pre-commit run --all-files
tests:
needs: [build]
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/qdax/test:${{ github.sha }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run pytests
run: |
coverage run -m pytest -vv tests
coverage xml
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2