forked from mindsdb/mindshub
-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (136 loc) · 4.84 KB
/
Copy pathbuild_deploy_dev.yml
File metadata and controls
149 lines (136 loc) · 4.84 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Build and deploy to dev
permissions:
contents: read
pull-requests: write
pages: write
id-token: write
on:
pull_request:
types: [opened, reopened, synchronize, labeled]
branches:
- 'main'
- 'releases/*'
# Cancel any existing runs of this workflow on the same branch/pr
# We always want to build/deploy/test a new commit over an older one
concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true
jobs:
changes:
name: Filter changed files
runs-on: mdb-dev
outputs:
not-docs: ${{ steps.filter.outputs.not-docs }}
steps:
- uses: dorny/paths-filter@v3
id: filter
with:
predicate-quantifier: "every"
filters: |
not-docs:
- '!docs/**'
- '!assets/**'
- '!**/*.md'
- '!.github/workflows/build_deploy_dev.yml'
- '!.github/workflows/test_on_deploy.yml'
- '!mindsdb/__about__.py'
# Start running unit tests early - we want to run them always
# and they don't depend on build or deployment
run_unit_tests:
name: Run Unit Tests
needs: [changes]
if: ${{ needs.changes.outputs.not-docs == 'true' }}
uses: ./.github/workflows/tests_unit.yml
secrets: inherit
# Looks for labels like "deploy-to-<env>" attached to a PR so we can deploy to those envs
get-deploy-labels:
if: ${{ !github.event.pull_request.head.repo.fork }}
name: Get Deploy Envs
runs-on: mdb-dev
needs: [changes]
outputs:
deploy-envs: ${{ steps.get-labels.outputs.deploy-envs }}
steps:
- id: get-labels
uses: mindsdb/github-actions/get-deploy-labels@main
# Build our docker images based on our bake file
build:
if: ${{ !github.event.pull_request.head.repo.fork && needs.get-deploy-labels.outputs.deploy-envs != '[]' }}
name: Build Docker Images
runs-on: mdb-dev
needs: [get-deploy-labels]
steps:
- uses: actions/checkout@v4
# Build the bakefile and push
- uses: mindsdb/github-actions/docker-bake@main
with:
git-sha: ${{ github.event.pull_request.head.sha }}
target: cloud-cpu
platforms: linux/amd64
push-cache: false
scan-keycloak:
runs-on: mdb-dev
needs: [ build ]
name: Scan cloud-cpu image
steps:
- uses: actions/checkout@v4
- uses: mindsdb/github-actions/snyk-docker-scan@main
with:
image: 168681354662.dkr.ecr.us-east-1.amazonaws.com/mindsdb:${{ github.event.pull_request.head.sha }}-cloud-cpu
snyk-token: ${{ secrets.SNYK_TOKEN }}
dockerfile: docker/mindsdb.Dockerfile
# Push cache layers to docker registry
# This is separate to the build step so we can do other stuff in parallel
build-cache:
if: ${{ !github.event.pull_request.head.repo.fork }}
name: Push Docker Cache
runs-on: mdb-dev
needs: [build]
steps:
- uses: actions/checkout@v4
# Build the bakefile and push
- uses: mindsdb/github-actions/docker-bake@main
with:
git-sha: ${{ github.event.pull_request.head.sha }}
target: cloud-cpu
platforms: linux/amd64
push-cache: true
cache-only: true
# This will run the deployment workflow in the base branch, not in the PR.
# So if you change the deploy workflow in your PR, the changes won't be reflected in this run.
deploy:
if: ${{ !github.event.pull_request.head.repo.fork && needs.get-deploy-labels.outputs.deploy-envs != '[]' }}
name: Deploy
needs: [build, get-deploy-labels]
uses: ./.github/workflows/deploy.yml
with:
deploy-envs: ${{ needs.get-deploy-labels.outputs.deploy-envs }}
image-tag: ${{ github.event.pull_request.head.sha }}
secrets: inherit
# Run integration tests against the deployed environment
run_integration_tests:
if: ${{ !github.event.pull_request.head.repo.fork }}
name: Run Integration Tests
needs: [deploy, get-deploy-labels]
strategy:
fail-fast: false
matrix:
deploy-env: ${{ fromJson(needs.get-deploy-labels.outputs.deploy-envs) }}
concurrency:
group: deploy-${{ matrix.deploy-env }}
cancel-in-progress: false
uses: ./.github/workflows/tests_integration.yml
with:
deploy-env: ${{ matrix.deploy-env }}
secrets: inherit
# This is a collection point for all of the matrix tests above so we can have a single required job
tests_completed:
name: All Tests Succeeded
needs: [run_unit_tests, run_integration_tests, changes]
runs-on: mdb-dev
if: always()
steps:
- name: fail if tests failed or didnt run
if: ${{ (needs.run_unit_tests.result != 'success' || (needs.run_integration_tests.result != 'success' && !github.event.pull_request.head.repo.fork)) && needs.changes.outputs.not-docs == 'true' }}
run: exit 1
- run: echo "Tests ran successfully"