-
Notifications
You must be signed in to change notification settings - Fork 1
111 lines (97 loc) · 3.2 KB
/
publish.yml
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
name: Build, Test and Publish
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
env:
SERVICE_NAME: ${{ github.event.repository.name }}
ACR_REGISTRY: terradevacrpublic.azurecr.io
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: v1-${{ runner.os }}-gradle-refs/heads/dev-${{ github.sha }}
- name: Gradle build service
run: ./gradlew --build-cache :service:build -x test
unit-tests:
needs: [ build ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Needed by sonar to get the git history for the branch the PR will be merged into.
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Test, coverage, and sonar
run: ./gradlew --build-cache --scan test jacocoTestReport sonar --info
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-job:
needs: [ build ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set commit short hash
id: setHash
run: |
git_short_sha=$(git rev-parse --short HEAD)
echo $git_short_sha
echo "::set-output name=git_short_sha::${git_short_sha}"
- name: Construct docker image name and tag
id: image-name
# TODO: update the tag
run: echo ::set-output name=name::${ACR_REGISTRY}/${SERVICE_NAME}:${{ steps.setHash.outputs.git_short_sha }}
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Build image locally with jib
run: |
./gradlew --build-cache :service:jibDockerBuild \
--image=${{ steps.image-name.outputs.name }} \
-Djib.console=plain
- name: Run Trivy vulnerability scanner
# Link to the github location of the action https://github.com/broadinstitute/dsp-appsec-trivy-action
uses: broadinstitute/dsp-appsec-trivy-action@v1
with:
image: ${{ steps.image-name.outputs.name }}
- name: Push Container image
run: |
echo ${{ secrets.ACR_SP_PASSWORD }} | docker login ${ACR_REGISTRY} \
--username ${{ secrets.ACR_SP_USER }} \
--password-stdin
docker push ${{ steps.image-name.outputs.name }}
- name: Notify slack on failure
uses: 8398a7/action-slack@v3
if: failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.LEO_WEB_HOOK_URL }}
with:
status: ${{ job.status }}
author_name: Publish to dev
fields: job
text: 'Publish failed :sadpanda:'