-
Notifications
You must be signed in to change notification settings - Fork 286
200 lines (172 loc) · 7.5 KB
/
java-build-push-test.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Java Build, Push, Test
on:
pull_request:
types: [opened, reopened, synchronize]
paths:
- .github/workflows/java-build-push-test.yaml
- 'backend/**'
- 'protos/**'
- pom.xml
- build_and_publish_backend.sh
push:
branches:
- main
- 'release/*'
permissions:
id-token: write # This is required for requesting the JWT
contents: write # Read is required for actions/checkout, write is required to comment on commits
pull-requests: write # This is needed for the coverage plugin to write comments to the PR
packages: write
statuses: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
VERTA_ECR_REGISTRY: "493416687123.dkr.ecr.us-east-1.amazonaws.com"
ECR_REPOSITORY: "493416687123.dkr.ecr.us-east-1.amazonaws.com/services/oss/modeldb/backend"
jobs:
build-push-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# need previous commit to find PR head commit info
fetch-depth: 2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::493416687123:role/github-actions
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Get branch names
id: branch_names
uses: tj-actions/[email protected]
- name: Get docker image tag
id: image_info
run: |
branch=$(echo ${{ steps.branch_names.outputs.current_branch }} | sed 's,/,_,g')
# PRs checkout a merge of PR head with target. Branches checkout current head of branch.
# When in a PR, use the PR head commit sha instead of the checkout commit sha.
pr_sha="${{ github.event.pull_request.head.sha }}"
sha=${pr_sha:-$GITHUB_SHA}
sha_details=$(TZ=UTC git show -s --format=%cd--%h --date='format-local:%Y-%m-%dT%H-%M-%S' --abbrev=7 $sha)
echo "sha=${sha}" >> $GITHUB_OUTPUT
echo "tag=${branch}-${sha_details}" >> $GITHUB_OUTPUT
- name: Update commit status with Docker image status
uses: ouzi-dev/commit-status-updater@v2
with:
name: "Tag: ${{ steps.image_info.outputs.tag }}"
description: "Building..."
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
cache: 'maven'
server-id: github-verta # Value of the distributionManagement/repository/id field of the pom.xml
- name: Check formatting
run: mvn spotless:check
- name: Build and Publish to GitHub Packages Apache Maven
run: ./build_and_publish_backend.sh
env:
GITHUB_TOKEN: ${{ github.token }}
BRANCH_NAME: ${{ steps.branch_names.outputs.current_branch }}
- name: Update commit status with Docker image status
uses: ouzi-dev/commit-status-updater@v2
with:
name: "Tag: ${{ steps.image_info.outputs.tag }}"
description: "Publishing..."
- name: Inspect image to see if it already exists
id: should_publish
run: |
TARGETS=""
docker manifest inspect $ECR_REPOSITORY:${{ steps.image_info.outputs.tag }} || TARGETS="modeldb"
echo "targets=${TARGETS}" >> $GITHUB_OUTPUT
- name: Build and push Docker image to ECR
uses: docker/build-push-action@v5
if: "!(steps.should_publish.outputs.targets == '')"
with:
context: backend
push: true
build-args: |
BASE_IMAGE=${{ env.VERTA_ECR_REGISTRY }}/ops/containers/base/java:main-17-latest
tags: |
${{ env.ECR_REPOSITORY }}:${{ steps.image_info.outputs.tag }}
- name: Configure AWS credentials for us-west-2
if: startsWith( github.ref, 'refs/heads/release/' )
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::493416687123:role/github-actions
aws-region: us-west-2
- name: Login to Amazon ECR for us-west-2
id: login-ecr-release
if: startsWith( github.ref, 'refs/heads/release/' )
uses: aws-actions/amazon-ecr-login@v2
- name: Mirror Docker image to us-west-2
id: mirror-release
if: startsWith( github.ref, 'refs/heads/release/' )
shell: bash
run: |
export TARGET_REPOSITORY=${ECR_REPOSITORY/us-east-1/us-west-2}
docker manifest inspect ${TARGET_REPOSITORY}:${{ steps.image_info.outputs.tag }} || \
docker tag ${ECR_REPOSITORY}:${{ steps.image_info.outputs.tag }} ${TARGET_REPOSITORY}:${{ steps.image_info.outputs.tag }} && \
docker push ${TARGET_REPOSITORY}:${{ steps.image_info.outputs.tag }}
- name: Create commit comment
uses: peter-evans/commit-comment@v3
if: "!(steps.should_publish.outputs.targets == '')"
with:
body: "Docker Tag: ${{ steps.image_info.outputs.tag }}"
- name: Update commit status with Docker image status
uses: ouzi-dev/commit-status-updater@v2
with:
name: "Tag: ${{ steps.image_info.outputs.tag }}"
url: "${{ github.server_url }}/${{ github.repository }}/commit/${{ steps.image_info.outputs.sha }}#comments"
status: success
- name: Test
env:
VERTA_MODELDB_TEST_CONFIG: itconfig/config-test-h2.yaml
LIQUIBASE_MIGRATION: true
RUN_LIQUIBASE_SEPARATE: false
LOG4J_CONFIGURATION_FILE: itconfig/log4j2.yaml
LOG4J_FORMAT_MSG_NO_LOOKUPS: true
run: JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8 ./test_backend.sh
- name: Upload Report
uses: 'actions/upload-artifact@v4'
with:
name: jacoco-reports
path: |
${{ github.workspace }}/backend/common/target/site/jacoco/jacoco.xml
${{ github.workspace }}/backend/server/target/site/jacoco/jacoco.xml
- name: Jacoco Report Common to PR
id: jacoco-common
uses: madrapps/jacoco-report@94dfcf8dae9680be2cfa714ca37fb37790bd7663 # Using specific commit until new release available
with:
paths: ${{ github.workspace }}/backend/common/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 10
min-coverage-changed-files: 70
debug-mode: false
update-comment: true
title: Common Code Coverage
- name: Jacoco Report Server to PR
id: jacoco-server
uses: madrapps/jacoco-report@94dfcf8dae9680be2cfa714ca37fb37790bd7663 # Using specific commit until new release available
with:
paths: ${{ github.workspace }}/backend/server/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 34
min-coverage-changed-files: 70
debug-mode: false
update-comment: true
title: Backend Code Coverage
- name: Create Code Coverage comment
uses: peter-evans/commit-comment@v3
with:
body: |
Total coverage (common): ${{ steps.jacoco-common.outputs.coverage-overall }}
Total coverage (server): ${{ steps.jacoco-server.outputs.coverage-overall }}
Changed Files coverage (common): coverage ${{ steps.jacoco-common.outputs.coverage-changed-files }}
Changed Files coverage (server): ${{ steps.jacoco-server.outputs.coverage-changed-files }}