generated from hmcts/service-hmcts-crime-springboot-template
-
Notifications
You must be signed in to change notification settings - Fork 1
164 lines (140 loc) · 5.01 KB
/
ci-draft.yml
File metadata and controls
164 lines (140 loc) · 5.01 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
name: CI Build and Publish Increments Draft
on:
pull_request:
branches:
- master
- main
push:
branches:
- master
- main
jobs:
Artefact-Version:
runs-on: ubuntu-latest
outputs:
draft_version: ${{ steps.vars.outputs.draft_version }}
latest_tag: ${{ steps.vars.outputs.latest_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get short SHA for versioning
id: vars
run: |
if LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null); then
:
else
LATEST_TAG="v0.0.0"
fi
echo "🏷️ Latest Git tag resolved to: $LATEST_TAG"
LATEST_TAG="${LATEST_TAG#v}"
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
SHORT_SHA=$(git rev-parse --short HEAD)
DRAFT_VERSION="${LATEST_TAG}-${SHORT_SHA}"
echo "draft_version=$DRAFT_VERSION"
echo "draft_version=$DRAFT_VERSION" >> $GITHUB_OUTPUT
Build:
needs: [Artefact-Version]
runs-on: ubuntu-latest
outputs:
repo_name: ${{ steps.repo_vars.outputs.repo_name }}
artefact_name: ${{ steps.repo_vars.outputs.artefact_name }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: current
- name: Gradle Build and Publish on Push [Merge]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
run: |
VERSION=${{ needs.Artefact-Version.outputs.draft_version }}
gradle build \
-DAPI_SPEC_VERSION=$VERSION \
-DGITHUB_REPOSITORY=${{ github.repository }} \
-DGITHUB_ACTOR=${{ github.actor }} \
-DGITHUB_TOKEN=$GITHUB_TOKEN
if [ "${{ github.event_name }}" == "push" ]; then
echo "Push event trigger - Publishing artefact"
gradle publish \
-DAPI_SPEC_VERSION=$VERSION \
-DGITHUB_REPOSITORY=${{ github.repository }} \
-DGITHUB_ACTOR=${{ github.actor }} \
-DGITHUB_TOKEN=$GITHUB_TOKEN \
-DAZURE_DEVOPS_ARTIFACT_USERNAME=$HMCTS_ARTEFACT_ACTOR \
-DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN
else
echo "Skipping publish because this is a pull_request"
fi
- name: Extract repo name
if: github.event_name == 'push'
id: repo_vars
run: |
repo_name=${GITHUB_REPOSITORY##*/}
echo "repo_name=${repo_name}" >> $GITHUB_OUTPUT
echo "artefact_name=${repo_name}-${{ needs.Artefact-Version.outputs.draft_version }}" >> $GITHUB_OUTPUT
- name: Upload JAR Artefact
uses: actions/upload-artifact@v4
if: github.event_name == 'push'
with:
name: app-jar
path: build/libs/${{ steps.repo_vars.outputs.artefact_name }}.jar
Build-Docker:
needs: [ Build, Artefact-Version ]
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Download JAR Artefact
uses: actions/download-artifact@v4
with:
name: app-jar
path: build/libs
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image to GitHub
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ needs.Artefact-Version.outputs.draft_version }}
build-args: |
BASE_IMAGE=openjdk:21-jdk-slim
JAR_FILENAME=${{ needs.Build.outputs.artefact_name }}.jar
# https://github.com/marketplace/actions/azure-pipelines-action
Deploy:
needs: [ Build, Artefact-Version ]
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Trigger ADO pipeline
uses: Azure/pipelines@v1.2
with:
azure-devops-project-url: 'https://dev.azure.com/hmcts-cpp/cpp-apps'
azure-pipeline-name: 'cp-gh-artifact-to-acr'
azure-devops-token: ${{ secrets.HMCTS_ADO_PAT }}
azure-pipeline-variables: >-
{
"GROUP_ID" : "uk.gov.hmcts.cp",
"ARTIFACT_ID" : "${{ github.repository }}",
"ARTIFACT_VERSION" : "${{ needs.Artefact-Version.outputs.draft_version}}"
}