Skip to content

Commit 5a6825e

Browse files
authored
Devops/build updates (#1670)
* More detailed build status reporting in preparation for proper trunk based development -- e.g. it's at least really obvious required builds are passing to justify releasing to test or prod. * Improved variable usage within the release yaml
1 parent fc5efcb commit 5a6825e

File tree

6 files changed

+159
-20
lines changed

6 files changed

+159
-20
lines changed

.github/actions/badge/action.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'Create badge'
2+
description: Create and upload a custom badge
3+
inputs:
4+
label:
5+
type: string
6+
description: Badge name
7+
required: true
8+
status:
9+
type: string
10+
description: Status. Pass/Fail, or numeric, Pass will set color to green, Fail to red, anything else is blue.
11+
required: true
12+
file:
13+
type: string
14+
description: Name of file to create, can include folders
15+
required: true
16+
run_id:
17+
type: number
18+
description: The value of github.run_id, or another appropriate tracker for downstream use.
19+
required: true
20+
outputs: {}
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: Badge directory
25+
shell: bash
26+
run: mkdir -p "badges/$(dirname '${{inputs.file}}')" || true
27+
- name: Prepare variables
28+
id: vars
29+
shell: bash
30+
env:
31+
UNSAFE: ${{ inputs.file }}
32+
run: |
33+
# Act, which we use for testing, doesn't yet support case in expression
34+
# However we may keep this to handle some more complex cases anyways.
35+
case "${{ inputs.status}}" in
36+
"Pass")
37+
echo "color=green" >> $GITHUB_OUTPUT
38+
;;
39+
"Fail")
40+
echo "color=red" >> $GITHUB_OUTPUT
41+
;;
42+
*)
43+
echo "color=blue" >> $GITHUB_OUTPUT
44+
esac
45+
echo "safe_file=${UNSAFE//\//_}" >> $GITHUB_OUTPUT
46+
- name: Build Badge
47+
uses: emibcn/badge-action@v2.0.2
48+
with:
49+
label: ${{inputs.label}}
50+
status: ${{inputs.status}}
51+
color: ${{ steps.vars.outputs.color }}
52+
path: badges/${{inputs.file}}
53+
- name: Upload badge
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: badges_${{ inputs.run_id }}_${{ steps.vars.outputs.safe_file }}
57+
path: badges/**/*.svg
58+
overwrite: true

.github/actions/database-migration-image/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: 'Database Migration Container'
2+
description: Setup database migration container.
23
inputs:
34
base-image:
45
type: string

.github/workflows/build.yml

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
jdk: [11]
17+
# place holder for now and leaving commented but in place. General scheme target tests again the current release, the next release, the previous release, and latest development.
18+
# at this time every possible instance of concern is on 25.07.01, once 26.02.17 is finalized it becomes release and 25.07.01 becomes previous.
19+
# next-release will be comment out until such time as a RC gets made
1720
schema:
1821
- env: latest
1922
image: "ghcr.io/hydrologicengineeringcenter/cwms-database/cwms/database-ready-ora-23.5:latest-dev"
2023
- env: release
2124
image: "ghcr.io/hydrologicengineeringcenter/cwms-database/cwms/database-ready-ora-23.5:25.07.01"
2225
- env: next-release
2326
image: "ghcr.io/hydrologicengineeringcenter/cwms-database/cwms/database-ready-ora-23.5:26.02.17-RC01"
27+
# - env: previous
28+
# image: "ghcr.io/hydrologicengineeringcenter/cwms-database/cwms/database-ready-ora-23.5:25.07.01"
2429
name: build and test (jdk ${{matrix.jdk}}, schema ${{matrix.schema.env}})
2530
runs-on: ubuntu-latest
2631
outputs:
@@ -44,13 +49,21 @@ jobs:
4449
run: ./gradlew clean build --info --init-script init.gradle
4550
- name: integration tests
4651
run: ./gradlew integrationtest --info --init-script init.gradle -PCDA.oracle.database.image=${{matrix.schema.image}}
47-
- name: Publish Test Report
48-
uses: mikepenz/action-junit-report@v5
52+
- name: Create matrix job badge
4953
if: success() || failure() # always run even if the previous step fails
54+
uses: ./.github/actions/badge
5055
with:
51-
annotate_only: true
52-
include_passed: true
53-
report_paths: '**/TEST-*.xml'
56+
label: 'Build'
57+
status: ${{ job.status == 'success' && 'Pass' || 'Fail' }}
58+
file: ${{ matrix.jdk }}/${{ matrix.schema.env }}.svg
59+
run_id: ${{ github.run_id }}
60+
# - name: Publish Test Report
61+
# uses: mikepenz/action-junit-report@v5
62+
# if: success() || failure() # always run even if the previous step fails
63+
# with:
64+
# annotate_only: true
65+
# include_passed: true
66+
# report_paths: '**/TEST-*.xml'
5467
open-api-static-analysis:
5568
name: OpenApi Static Analysis Tests
5669
runs-on: ubuntu-latest
@@ -88,11 +101,39 @@ jobs:
88101
steps:
89102
- name: checkout code
90103
uses: actions/checkout@v5.0.0
104+
# No uploads, we're just verifying that nothing broke the docker image.
91105
- name: Build Migration image
92106
uses: ./.github/actions/database-migration-image
93107
with:
94108
base-image: ghcr.io/hydrologicengineeringcenter/cwms-database/cwms/schema_installer
95109
# TODO get current target image from build information
96110
tag: latest-dev
97111

98-
# No uploads, we're just verifying that nothing broke the docker image.
112+
113+
114+
badges:
115+
needs: build
116+
runs-on: ubuntu-latest
117+
# we are reporing build state so always run, but only on builds on the main branch
118+
if: always() && (github.ref_name == 'develop')
119+
steps:
120+
- name: Badge Branch
121+
uses: actions/checkout@v5.0.0
122+
with:
123+
ref: badges
124+
fetch-depth: 1
125+
- name: Download badges
126+
uses: actions/download-artifact@v4
127+
with:
128+
pattern: badges_${{ github.run_id }}_*
129+
path: ./build # directory to download artifacts into
130+
merge-multiple: true # downloaded artifacts will be in the same directory specified by path
131+
- name: Apply Badge
132+
run: |
133+
find . -type f
134+
git config --local user.email "action@github.com"
135+
git config --local user.name "GitHub Action"
136+
git add build/**/*.svg
137+
git status
138+
git commit --allow-empty -m "Update Badge for build of ${{ github.sha }}"
139+
git push origin badges -f

.github/workflows/release.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,22 @@ jobs:
6767
java-version: '11'
6868
cache: 'gradle'
6969
- name: Set version
70-
if: inputs.nightly == true
71-
run: echo "VERSION=${{inputs.branch}}-nightly" >> $GITHUB_ENV
72-
- name: Set version
73-
if: inputs.nightly == false
74-
run: echo "VERSION=${{inputs.branch}}" >> $GITHUB_ENV
70+
id: version
71+
env:
72+
NIGHTLY: ${{inputs.nightly}}
73+
run:
74+
if [[ "${NIGHTLY}" == true ]]; then
75+
echo "version=${{inputs.branch}}-nightly" >> $GITHUB_OUTPUT
76+
else
77+
echo "version=${{inputs.branch}}" >> $GITHUB_OUTPUT
78+
fi
7579
- name: Sanitize repo for container image names
80+
id: repo
7681
run: |
7782
REPO=`echo "${{github.repository}}" | tr '[:upper:]' '[:lower:]'`
78-
echo "REPO=$REPO" >> $GITHUB_ENV
83+
echo "name=$REPO" >> $GITHUB_OUTPUT
7984
- name: show version
80-
run: echo ${VERSION}
85+
run: echo ${{ steps.version.outputs.version }}
8186
- name: build war
8287
run: ./gradlew build --info --init-script init.gradle -PversionOverride=$VERSION
8388
- name: Create GitHub Release
@@ -86,8 +91,8 @@ jobs:
8691
if: github.event_name != 'pull_request' && (github.event.ref == 'refs/heads/develop' || startsWith(github.event.ref, 'refs/tags'))
8792
uses: softprops/action-gh-release@v2.6.1
8893
with:
89-
files: cwms-data-api/build/libs/cwms-data-api-${{env.VERSION}}.war
90-
tag_name: ${{env.VERSION}}
94+
files: cwms-data-api/build/libs/cwms-data-api-${{steps.version.outputs.version}}.war
95+
tag_name: ${{steps.version.outputs.version}}
9196
generate_release_notes: true
9297
token: ${{ secrets.token != null && secrets.token || secrets.GITHUB_TOKEN }}
9398
- name: Set up Docker Buildx
@@ -101,11 +106,11 @@ jobs:
101106
context: git
102107
images: |
103108
${{secrets.registry != null && secrets.registry ||secrets.HEC_PUB_REGISTRY}}/cwms/data-api
104-
ghcr.io/${{env.REPO}}
109+
ghcr.io/${{steps.repo.outputs.name}}
105110
tags: |
106111
type=sha
107112
type=ref,event=tag
108-
type=raw,value=${{env.VERSION}}
113+
type=raw,value=${{steps.version.outputs.version}}
109114
type=schedule,pattern=${{inputs.branch}}-{{date 'YYYY.MM.DD'}}
110115
type=schedule,pattern=${{inputs.branch}}-{{date 'YYYY.MM.DD-hhmmss'}}
111116
- name: Log in to the Container registry
@@ -133,6 +138,9 @@ jobs:
133138
labels: ${{ steps.meta.outputs.labels }}
134139
- name: Set Output Image
135140
id: set_image
141+
env:
142+
REPO: ${{ steps.repo.outputs.name }}
143+
VERSION: ${{ steps.version.outputs.version }}
136144
run: |
137145
echo "api_image=ghcr.io/${REPO}:$VERSION" >> $GITHUB_OUTPUT
138146
- name: Setup Database Migration Image
@@ -143,6 +151,9 @@ jobs:
143151
tag: latest-dev
144152
- name: Publish migration container
145153
id: migration-publish
154+
env:
155+
REPO: ${{ steps.repo.outputs.name }}
156+
VERSION: ${{ steps.version.outputs.version }}
146157
run: |
147158
IMAGE=ghcr.io/${REPO}-schema-migration:$VERSION
148159
docker tag ${{steps.migration.outputs.image}} $IMAGE

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ pki/certs
1212
compose.env
1313
.vscode
1414
**/node_modules/
15+
cwms-data-api/features.properties

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
</p>
1313

1414
<p align="center">
15-
<a href="https://github.com/usace/cwms-data-api/actions/workflows/build.yml">
16-
<img alt="Build Status" src="https://img.shields.io/github/actions/workflow/status/usace/cwms-data-api/build.yml?branch=develop&style=for-the-badge&label=Build&logo=githubactions">
17-
</a>
1815
<a href="https://github.com/usace/cwms-data-api/actions/workflows/codeql.yml">
1916
<img alt="CodeQL Status" src="https://img.shields.io/github/actions/workflow/status/usace/cwms-data-api/codeql.yml?branch=develop&style=for-the-badge&label=CodeQL&logo=githubactions">
2017
</a>
@@ -23,6 +20,36 @@
2320
</a>
2421
</p>
2522

23+
<div align="center">
24+
<h2>Detailed Build Status</h2>
25+
<table>
26+
<thead>
27+
<tr>
28+
<th>CWMS Database Schema target</th>
29+
<th>Status</th>
30+
</tr>
31+
</thead>
32+
<tbody>
33+
<tr>
34+
<td>Latest</td>
35+
<td><img alt="Latest Status, Svg" src="https://raw.githubusercontent.com/USACE/cwms-data-api/refs/heads/badges/build/11/latest.svg">
36+
</tr>
37+
<tr>
38+
<td>Current Release</td>
39+
<td><img alt="Current Status, Svg" src="https://raw.githubusercontent.com/USACE/cwms-data-api/refs/heads/badges/build/11/release.svg">
40+
</tr>
41+
<tr>
42+
<td>Next Release</td>
43+
<td><img alt="Next Status, Svg" src="https://raw.githubusercontent.com/USACE/cwms-data-api/refs/heads/badges/build/11/next-release.svg">
44+
</tr>
45+
<tr>
46+
<td>Previous Release - NOTE: Not applicable yet</td>
47+
<td><img alt="Previous Status, Svg" src="https://raw.githubusercontent.com/USACE/cwms-data-api/refs/heads/badges/build/11/previous.svg">
48+
</tr>
49+
</tbody>
50+
</table>
51+
</div>
52+
2653
<p align="center">
2754
<strong>
2855
<a href="CONTRIBUTING.md">Contributing</a>

0 commit comments

Comments
 (0)