-
Notifications
You must be signed in to change notification settings - Fork 25
167 lines (166 loc) · 5.74 KB
/
Copy pathrelease.yml
File metadata and controls
167 lines (166 loc) · 5.74 KB
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
---
name: Nightly Release - Build
on:
workflow_call:
inputs:
branch:
type: string
required: true
nightly:
type: boolean
required: true
secrets:
token:
required: false
registry:
required: false
registry_user:
required: false
registry_password:
required: false
outputs:
api_image:
description: GHCR.io image tag for downstream consumption
value: ${{ jobs.release.outputs.api_image }}
migration_image:
description: Modified CWMS Schema installer image
value: ${{ jobs.release.outputs.migration_image }}
workflow_dispatch:
inputs:
branch:
type: choice
required: true
description: Which Branch to make the build from
options:
- develop
- test
nightly:
type: boolean
required: true
description: Is this part of a "nightly" workflow?
default: true
jobs:
release:
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
outputs:
api_image: ${{steps.set_image.outputs.api_image}}
migration_image: ${{steps.migration-publish.outputs.image}}
steps:
- name: Clean up disk space, so we don't run out.
if: matrix.platform == 'ubuntu-latest'
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
- name: checkout code
uses: actions/checkout@v5.0.0
with:
ref: ${{inputs.branch}}
- name: setup java
uses: actions/setup-java@v5.2.0
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'
- name: Set version
id: version
env:
BRANCH: ${{inputs.branch}}
NIGHTLY: ${{inputs.nightly}}
run: |
if [[ "${NIGHTLY}" == true ]]; then
VERSION="${BRANCH}-nightly"
PRERELEASE=true
else
VERSION="${BRANCH}"
if [[ "${VERSION}" =~ ^[0-9]{4}\.[0-9]{2}\.[0-9]{2}-(dev|test)[a-z]*$ ]]; then
PRERELEASE=true
else
PRERELEASE=false
fi
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"
- name: Sanitize repo for container image names
id: repo
run: |
REPO=`echo "${{github.repository}}" | tr '[:upper:]' '[:lower:]'`
echo "name=$REPO" >> $GITHUB_OUTPUT
- name: show version
run: echo ${{ steps.version.outputs.version }}
- name: build war
run: ./gradlew build --info --init-script init.gradle -PversionOverride=$VERSION
- name: Create GitHub Release
id: create_release
# Allow testing without creating a release
if: github.event_name != 'pull_request' && (github.event.ref == 'refs/heads/develop' || startsWith(github.event.ref, 'refs/tags'))
uses: softprops/action-gh-release@v2.6.1
with:
files: cwms-data-api/build/libs/cwms-data-api-${{steps.version.outputs.version}}.war
tag_name: ${{steps.version.outputs.version}}
generate_release_notes: true
prerelease: ${{steps.version.outputs.prerelease}}
token: ${{ secrets.token != null && secrets.token || secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4.1.0
- name: Docker meta
id: meta
uses: docker/metadata-action@v6.1.0
with:
# this is triggered by the schedule so we want to actually use the checked out information
# and not the context from the workflow itself.
context: git
images: |
ghcr.io/${{steps.repo.outputs.name}}
tags: |
type=sha
type=ref,event=tag
type=raw,value=${{steps.version.outputs.version}}
type=schedule,pattern=${{inputs.branch}}-{{date 'YYYY.MM.DD'}}
type=schedule,pattern=${{inputs.branch}}-{{date 'YYYY.MM.DD-hhmmss'}}
- name: Log in to the Container registry
id: login-ghcr
uses: docker/login-action@v4.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.token != null && secrets.token || secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v7.2.0
with:
context: "."
# This is not conditional on pull_request as we want access to these if we are manually running it.
push: true
sbom: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Set Output Image
id: set_image
env:
REPO: ${{ steps.repo.outputs.name }}
VERSION: ${{ steps.version.outputs.version }}
run: |
echo "api_image=ghcr.io/${REPO}:$VERSION" >> $GITHUB_OUTPUT
- name: Setup Database Migration Image
id: migration
uses: ./.github/actions/database-migration-image
with:
base-image: ghcr.io/hydrologicengineeringcenter/cwms-database/cwms/schema_installer
tag: latest-dev
- name: Publish migration container
id: migration-publish
env:
REPO: ${{ steps.repo.outputs.name }}
VERSION: ${{ steps.version.outputs.version }}
run: |
IMAGE=ghcr.io/${REPO}-schema-migration:$VERSION
docker tag ${{steps.migration.outputs.image}} $IMAGE
docker push $IMAGE
echo "image=$IMAGE" >> $GITHUB_OUTPUT
- name: Logout of GH registry
if: ${{ always() }}
run: |
docker logout ${{ steps.login-ghcr.outputs.registry }}