-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6116ba3
commit 5dd1938
Showing
1 changed file
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
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: | ||
tag_name: ${{ steps.extract_tag_name.outputs.tag_name }} | ||
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 | ||
|
||
- name: Extract branch name and commit hash | ||
id: extract_tag_name | ||
shell: bash | ||
run: | | ||
BRANCH_NAME=${GITHUB_REF_NAME#feature-*/} | ||
COMMIT_HASH=$(git rev-parse --short HEAD) | ||
echo "tag_name=${BRANCH_NAME}-${COMMIT_HASH}-SNAPSHOT" >> $GITHUB_OUTPUT | ||
build-test-publish: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
app_version: ${{ steps.capture_version.outputs.app_version }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
- name: Build with Gradle | ||
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 | ||
with: | ||
arguments: build | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Test | ||
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 | ||
with: | ||
arguments: jacocoTestCoverageVerification | ||
|
||
- name: Integration Test | ||
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 | ||
with: | ||
arguments: integrationTest | ||
|
||
- name: Publish package | ||
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 | ||
with: | ||
arguments: publish | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Capture version | ||
shell: bash | ||
id: capture_version | ||
run: | | ||
echo "app_version=${{ needs.define-image-tag.outputs.tag_name }}" >> $GITHUB_OUTPUT | ||
echo "Captured version: ${{ needs.define-image-tag.outputs.tag_name }}" | ||
- name: Upload jarfile | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: data-api-jar | ||
path: data-service/build/libs/data-service-${{ steps.capture_version.outputs.app_version }}.jar | ||
|
||
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@v3 | ||
|
||
- name: Download jar | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: data-api-jar | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }} | ||
aws-region: ${{ vars.ECR_REGION }} | ||
|
||
- name: Login ECR | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
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@v2 | ||
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@v3 | ||
with: | ||
repository: ministryofjustice/laa-ccms-caab-helm-charts | ||
ref: development | ||
path: laa-ccms-caab-helm-charts | ||
token: ${{ secrets.REPO_TOKEN }} | ||
|
||
- name: Create or switch to feature branch | ||
env: | ||
FEATURE_BRANCH: ${{ github.ref_name }} | ||
run: | | ||
cd laa-ccms-caab-helm-charts | ||
git fetch origin $FEATURE_BRANCH || true | ||
git checkout -b $FEATURE_BRANCH || git checkout $FEATURE_BRANCH | ||
- name: Update helm chart | ||
env: | ||
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/laa-ccms-caab-service/charts/caab-ebs-api/ | ||
yq eval-all "( .appVersion = \"${{ env.REPO_NAME }}-${{ env.APP_VERSION }}\" )" -i Chart.yaml | ||
git add . | ||
git commit -m "Update appVersion to ${{ env.REPO_NAME }}-${{ env.APP_VERSION }}" | ||
git push origin $FEATURE_BRANCH |