-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (143 loc) · 5.26 KB
/
feature-branch.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
164
165
166
167
168
169
name: CI feature branch and deploy
on:
push:
branches:
- 'feature-dev/**'
- 'feature-test/**'
permissions:
contents: read
packages: write
jobs:
define-image-tag:
runs-on: ubuntu-latest
outputs:
repo_name: ${{ steps.extract_repo_name.outputs.repo_name }}
steps:
- name: Extract short repo name
shell: bash
run: echo "repo_name=caab-ebs${GITHUB_REPOSITORY#*\/laa-ccms-data}" >> $GITHUB_OUTPUT
id: extract_repo_name
build-test-publish:
runs-on: ubuntu-latest
outputs:
app_version: ${{ steps.capture_version.outputs.app_version }}
steps:
- uses: actions/checkout@v4
- name: Capture version
shell: bash
id: capture_version
run: |
BRANCH_NAME=${GITHUB_REF_NAME#feature-*/}
COMMIT_HASH=$(git rev-parse --short HEAD)
echo "${BRANCH_NAME}-${COMMIT_HASH}-SNAPSHOT"
echo "app_version=${BRANCH_NAME}-${COMMIT_HASH}-SNAPSHOT" >> $GITHUB_OUTPUT
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build & test
run: ./gradlew build -Pversion=${{ steps.capture_version.outputs.app_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test coverage verification
run: ./gradlew jacocoTestCoverageVerification
- name: Integration test
run: ./gradlew integrationTest -Pversion=${{ steps.capture_version.outputs.app_version }}
- name: Publish package
run: ./gradlew publish -Pversion=${{ steps.capture_version.outputs.app_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload jarfile
uses: actions/upload-artifact@v4
with:
name: data-api-jar
path: data-service/build/libs/data-service-${{ steps.capture_version.outputs.app_version }}.jar
- name: Upload checkstyle report
if: always()
uses: actions/upload-artifact@v4
with:
name: checkstyle-report
path: data-service/build/reports/checkstyle
retention-days: 14
- name: Upload test report
if: always()
uses: actions/upload-artifact@v4
with:
name: test-report
path: data-service/build/reports/tests
retention-days: 14
- name: Upload jacoco coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: jacoco-coverage-report
path: data-service/build/reports/jacoco
retention-days: 14
ecr:
needs: [ build-test-publish, define-image-tag ]
runs-on: ubuntu-latest
permissions:
id-token: write # for requesting jwt
contents: read # for actions/checkout
steps:
- uses: actions/checkout@v4
- name: Download jar
uses: actions/download-artifact@v4
with:
name: data-api-jar
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }}
aws-region: ${{ vars.ECR_REGION }}
- name: Login ECR
uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- name: Build and push image
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.ECR_REPOSITORY }}
REPO_NAME: ${{ needs.define-image-tag.outputs.repo_name }}
APP_VERSION: ${{ needs.build-test-publish.outputs.app_version }}
run: |
docker build --build-arg app_version=${{ env.APP_VERSION }} -t $REGISTRY/$REPOSITORY:${{ env.REPO_NAME }}-${{ env.APP_VERSION }} .
docker push $REGISTRY/$REPOSITORY:${{ env.REPO_NAME }}-${{ env.APP_VERSION }}
- name: Delete artifact
uses: geekyeggo/delete-artifact@v5
with:
name: data-api-jar
update-helm-chart:
needs: [ build-test-publish, ecr, define-image-tag ]
runs-on: ubuntu-latest
steps:
- name: Checkout charts repo
uses: actions/checkout@v4
with:
repository: ministryofjustice/laa-ccms-caab-helm-charts
ref: development
path: laa-ccms-caab-helm-charts
token: ${{ secrets.REPO_TOKEN }}
- name: Update Helm chart
env:
FEATURE_BRANCH: ${{ github.ref_name }}
REPO_NAME: ${{ needs.define-image-tag.outputs.repo_name }}
APP_VERSION: ${{ needs.build-test-publish.outputs.app_version }}
run: |
cd laa-ccms-caab-helm-charts
git config --global user.email "github@justice.gov.uk"
git config --global user.name "GitHub Actions Bot"
git fetch origin
if git rev-parse --verify origin/$FEATURE_BRANCH; then
git checkout $FEATURE_BRANCH
git pull origin $FEATURE_BRANCH
else
git checkout -b $FEATURE_BRANCH
fi
cd laa-ccms-caab-service/charts/caab-ebs-api/
yq eval "( .appVersion = \"${REPO_NAME}-${APP_VERSION}\" )" -i Chart.yaml
git add .
git commit -m "Update appVersion to ${REPO_NAME}-${APP_VERSION}"
git push --set-upstream origin $FEATURE_BRANCH