-
Notifications
You must be signed in to change notification settings - Fork 34
163 lines (160 loc) · 7.38 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
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
# SPDX-FileCopyrightText: Contributors to the GXF project
#
# SPDX-License-Identifier: Apache-2.0
name: Build analyse and push docker container
on:
push:
branches:
- development
tags:
- '**'
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: maven
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Set maven options
id: maven_options
if: contains(github.ref, 'release') || contains(github.ref, 'development') || contains(github.event.pull_request.labels.*.name, 'build_containers')
run: echo 'maven_options=-DskipTestJarWithDependenciesAssembly=false' >> $GITHUB_OUTPUT
- name: Build and analyse
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./mvnw -T1C -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=gxf -Dsonar.projectKey=OSGP_open-smart-grid-platform ${{ steps.maven_options.outputs.maven_options }}
- name: Staging war and jar files
run: mkdir staging && find . -name *.war -not -path './staging/*' -exec cp -prv --parents '{}' 'staging/' ';' -o -name cucumber-*-test-jar-with-dependencies.jar -not -path './staging/*' -exec cp -prv --parents '{}' 'staging/' ';'
if: contains(github.ref, 'release') || contains(github.ref, 'development') || contains(github.event.pull_request.labels.*.name, 'build_containers')
- uses: actions/upload-artifact@v4
if: contains(github.ref, 'release') || contains(github.ref, 'development') || contains(github.event.pull_request.labels.*.name, 'build_containers')
with:
name: warFiles
path: staging
docker:
name: Building docker images
runs-on: ubuntu-latest
if: contains(github.ref, 'release') || contains(github.ref, 'development') || contains(github.event.pull_request.labels.*.name, 'build_containers')
needs: build
permissions:
contents: read
packages: write
attestations: write
id-token: write
strategy:
matrix:
include:
- image: ghcr.io/osgp/osgp-core
context: ./osgp/platform/osgp-core/
- image: ghcr.io/osgp/osgp-logging
context: ./osgp/platform/osgp-logging/
- image: ghcr.io/osgp/osgp-adapter-domain-admin
context: ./osgp/platform/osgp-adapter-domain-admin/
- image: ghcr.io/osgp/osgp-adapter-domain-core
context: ./osgp/platform/osgp-adapter-domain-core/
- image: ghcr.io/osgp/osgp-adapter-domain-publiclighting
context: ./osgp/platform/osgp-adapter-domain-publiclighting/
- image: ghcr.io/osgp/osgp-adapter-domain-smartmetering
context: ./osgp/platform/osgp-adapter-domain-smartmetering/
- image: ghcr.io/osgp/osgp-adapter-domain-tariffswitching
context: ./osgp/platform/osgp-adapter-domain-tariffswitching/
- image: ghcr.io/osgp/osgp-adapter-ws-admin
context: ./osgp/platform/osgp-adapter-ws-admin/
- image: ghcr.io/osgp/osgp-adapter-ws-core
context: ./osgp/platform/osgp-adapter-ws-core/
- image: ghcr.io/osgp/osgp-adapter-ws-publiclighting
context: ./osgp/platform/osgp-adapter-ws-publiclighting/
- image: ghcr.io/osgp/osgp-adapter-ws-smartmetering
context: ./osgp/platform/osgp-adapter-ws-smartmetering/
- image: ghcr.io/osgp/osgp-adapter-ws-tariffswitching
context: ./osgp/platform/osgp-adapter-ws-tariffswitching/
- image: ghcr.io/osgp/osgp-protocol-adapter-iec60870
context: ./osgp/protocol-adapter-iec60870/osgp-protocol-adapter-iec60870
- image: ghcr.io/osgp/osgp-protocol-simulator-iec60870
context: ./osgp/protocol-adapter-iec60870/osgp-protocol-simulator-iec60870
- image: ghcr.io/osgp/osgp-protocol-adapter-iec61850
context: ./osgp/protocol-adapter-iec61850/osgp-protocol-adapter-iec61850
- image: ghcr.io/osgp/osgp-protocol-simulator-iec61850
context: ./osgp/protocol-adapter-iec61850/osgp-protocol-simulator-iec61850
- image: ghcr.io/osgp/osgp-protocol-adapter-oslp
context: ./osgp/protocol-adapter-oslp/osgp-protocol-adapter-oslp-elster
- image: ghcr.io/osgp/osgp-signing-server
context: ./osgp/protocol-adapter-oslp/signing-server
- image: ghcr.io/osgp/osgp-web-device-simulator
context: ./osgp/protocol-adapter-oslp/web-device-simulator
- image: ghcr.io/osgp/osgp-cucumber-tests-platform-common
context: ./integration-tests
file: /cucumber-tests-platform-common/Dockerfile
- image: ghcr.io/osgp/osgp-cucumber-tests-platform-publiclighting
context: ./integration-tests
file: /cucumber-tests-platform-publiclighting/Dockerfile
- image: ghcr.io/osgp/osgp-cucumber-tests-platform-smartmetering
context: ./integration-tests
file: /cucumber-tests-platform-smartmetering/Dockerfile
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download war files
uses: actions/download-artifact@v4
with:
name: warFiles
- run: find ${{ matrix.context }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
if: ${{ matrix.file == null }}
with:
context: ${{ matrix.context }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push Docker image with file path
id: pushWithFile
uses: docker/build-push-action@v6
if: ${{ matrix.file != null }}
with:
context: ${{ matrix.context }}
file: ${{ matrix.context }}${{ matrix.file }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
if: ${{ matrix.file == null }}
with:
subject-name: ${{ matrix.image }}
subject-digest: ${{ steps.push.outputs.digest }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
if: ${{ matrix.file != null }}
with:
subject-name: ${{ matrix.image }}
subject-digest: ${{ steps.pushWithFile.outputs.digest }}