-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (110 loc) · 4.06 KB
/
build.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Build Java JAR and publish as Docker image to Docker Hub.
#
# Adopted from
#
# - https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
# -
name: Build and Publish
on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Build and Test with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: clean build test cucumber jacocoTestReport
- name: Attach JAR as Build Artifact
uses: actions/upload-artifact@v3
with:
name: train-delays-0.0.1-SNAPSHOT.jar
path: build/libs/train-delays-0.0.1-SNAPSHOT.jar
- name: Attach Test Results as Build Artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
build/reports/jacoco/test
build/reports/tests
publish-reports:
name: Publish Test Reports
runs-on: ubuntu-latest
# Repository secrets may only be used when running on the controlled main branch
# otherwise we run the risk of exposing secrets to a malicious attacker
# AND
# Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace'
if: github.ref == 'refs/heads/main' && github.repository == 'wonderbird/train-delays'
needs: build-and-test
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Download Test Results
uses: actions/download-artifact@v3
with:
name: test-results
path: build/reports
- name: Report Coverage to Coveralls
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
with:
arguments: coveralls
- name: Report Coverage to CodeClimate
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
JACOCO_SOURCE_PATH: "src/main/java"
with:
coverageLocations: build/reports/jacoco/test/jacocoTestReport.xml:jacoco
publish-docker-image:
# Documentation: https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
name: Publish Docker Image
runs-on: ubuntu-latest
# Repository secrets may only be used when running on the controlled main branch
# otherwise we run the risk of exposing secrets to a malicious attacker
# AND
# Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace'
if: github.ref == 'refs/heads/main' && github.repository == 'wonderbird/train-delays'
needs: build-and-test
steps:
- uses: actions/checkout@v3
- name: Download JAR
uses: actions/download-artifact@v3
with:
name: train-delays-0.0.1-SNAPSHOT.jar
path: build/libs
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: boos/train-delays
tags: type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}