Skip to content

[Gradle Release Plugin] - pre tag commit: 'laa-ccms-caab-ebs-api-0.… #43

[Gradle Release Plugin] - pre tag commit: 'laa-ccms-caab-ebs-api-0.…

[Gradle Release Plugin] - pre tag commit: 'laa-ccms-caab-ebs-api-0.… #43

Workflow file for this run

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: CI caab-data-api tag and deploy
on:
push:
tags:
- '*'
permissions:
contents: read
packages: write
jobs:
define-image-tag:
runs-on: ubuntu-latest
# map a step output to job output
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
assemble-publish:
runs-on: ubuntu-latest
outputs:
app_version: ${{ steps.capture_version.outputs.app_version }}
steps:
- uses: actions/checkout@v4
- 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
run: ./gradlew assemble
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish package
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Capture version
shell: bash
id: capture_version
run: |
VERSION=$(grep "version=" gradle.properties | cut -d'=' -f2)
echo "app_version=${VERSION}" >> $GITHUB_OUTPUT
echo "Captured version: $VERSION"
- 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
ecr:
needs: [ assemble-publish, define-image-tag ]
runs-on: ubuntu-latest
permissions:
id-token: write # for requesting jwt
contents: read # for actions/checkout
steps:
# Checkout github repo
- uses: actions/checkout@v4
# Assume role in cloud platform
- 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
# Build and push docker image to container repo
- 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.assemble-publish.outputs.app_version }}
run: |
echo "Captured version: ${{ env.APP_VERSION }}"
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: [ assemble-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:
REPO_NAME: ${{ needs.define-image-tag.outputs.repo_name }}
APP_VERSION: ${{ needs.assemble-publish.outputs.app_version }}
run: |
echo "${{ env.REPO_NAME }}-${{ env.APP_VERSION }}"
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 config --global user.email "github@justice.gov.uk"
git config --global user.name "GitHub Actions Bot"
git add .
git commit -m "update appVersion to ${{ env.REPO_NAME }}-${{ env.APP_VERSION }}"
git push origin