From fad516cf9a4e0683ed5c21f6398267f9624bab34 Mon Sep 17 00:00:00 2001 From: Phil Payne Date: Tue, 17 Oct 2023 15:05:31 +0100 Subject: [PATCH] test --- .github/workflows/pr-merge-test.yml | 75 +++++++++++ .../{test.yml => push-branch-test.yml} | 119 ++++++++++-------- .github/workflows/push-branch.yml | 1 + gradle.properties | 2 +- 4 files changed, 141 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/pr-merge-test.yml rename .github/workflows/{test.yml => push-branch-test.yml} (62%) diff --git a/.github/workflows/pr-merge-test.yml b/.github/workflows/pr-merge-test.yml new file mode 100644 index 0000000..8d34502 --- /dev/null +++ b/.github/workflows/pr-merge-test.yml @@ -0,0 +1,75 @@ +# 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 + +on: + pull_request: + branches: [ task/ccls-1880_amend_package_versions ] + types: [ closed ] + +permissions: + contents: read + packages: write + +jobs: + define-image-tag: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + # map a step output to job output + outputs: + tag_name: ${{ steps.extract_tag_name.outputs.tag_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: derive tag name + shell: bash + run: echo "tag_name=${{ steps.extract_repo_name.outputs.repo_name }}-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT + id: extract_tag_name + + + build-test-publish: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # replace with main after + ref: task/ccls-1880_amend_package_versions + token: ${{ secrets.REPO_TOKEN }} + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Build with Gradle + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + with: + arguments: build + + - name: Test + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + with: + arguments: jacocoTestCoverageVerification + + - name: Integration Test + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + with: + arguments: integrationTest + + - name: Set to github user + run: | + git config --global user.email "github@justice.gov.uk" + git config --global user.name "GitHub Actions Bot" + + - name: Update version + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + with: + arguments: release -Prelease.useAutomaticVersion=true + diff --git a/.github/workflows/test.yml b/.github/workflows/push-branch-test.yml similarity index 62% rename from .github/workflows/test.yml rename to .github/workflows/push-branch-test.yml index 0354741..75df1dd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/push-branch-test.yml @@ -17,20 +17,21 @@ permissions: 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 }} - 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: derive tag name - shell: bash - run: echo "tag_name=${{ steps.extract_repo_name.outputs.repo_name }}-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT - id: extract_tag_name + define-image-tag: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + # map a step output to job output + outputs: + tag_name: ${{ steps.extract_tag_name.outputs.tag_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: derive tag name + shell: bash + run: echo "tag_name=${{ steps.extract_repo_name.outputs.repo_name }}-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT + id: extract_tag_name build-test-publish: runs-on: ubuntu-latest @@ -38,23 +39,32 @@ jobs: app_version: ${{ steps.capture_version.outputs.app_version }} steps: - uses: actions/checkout@v3 - with: - token: ${{ secrets.REPO_TOKEN }} - name: Set up JDK 17 uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' + - name: Build with Gradle + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + with: + arguments: build - - name: Set to github user - run: | - git config --global user.email "github@justice.gov.uk" - git config --global user.name "GitHub Actions Bot" + - name: Test + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + with: + arguments: jacocoTestCoverageVerification + + - name: Integration Test + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + with: + arguments: integrationTest - - name: Update version + - name: Publish package uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 with: - arguments: release -Prelease.useAutomaticVersion=true + arguments: publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Capture version id: capture_version @@ -68,17 +78,11 @@ jobs: uses: actions/upload-artifact@v3 with: name: data-api-jar - path: data-service/build/libs/data-service-${{ steps.capture-version.outputs.version }}.jar - - - name: Publish package - uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 - with: - arguments: publish - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + path: data-service/build/libs/data-service-${{ steps.capture-version.outputs.app_version }}.jar ecr: - needs: [build-test-publish, define-image-tag] + if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main' + needs: [ build-test-publish, define-image-tag ] runs-on: ubuntu-latest permissions: id-token: write # for requesting jwt @@ -118,28 +122,33 @@ jobs: with: name: data-api-jar -# update-helm-chart: -# needs: [ecr, define-image-tag] -# runs-on: ubuntu-latest -# environment: development -# 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: update helm chart -# env: -# IMAGE_TAG: ${{ needs.define-image-tag.outputs.tag_name }} -# run: | -# echo "$IMAGE_TAG" -# cd laa-ccms-caab-helm-charts/laa-ccms-caab-service/charts/laa-ccms-caab-ebs-api/ -# yq eval-all "( .appVersion = \"${{ env.IMAGE_TAG }}\" )" -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.IMAGE_TAG }}" -# git push origin + - name: delete artifact + uses: geekyeggo/delete-artifact@v2 + with: + name: data-api-jar + + update-helm-chart: + needs: [ ecr, define-image-tag ] + runs-on: ubuntu-latest + environment: development + 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: update helm chart + env: + IMAGE_TAG: ${{ needs.define-image-tag.outputs.tag_name }} + run: | + echo "$IMAGE_TAG" + cd laa-ccms-caab-helm-charts/laa-ccms-caab-service/charts/laa-ccms-caab-ebs-api/ + yq eval-all "( .appVersion = \"${{ env.IMAGE_TAG }}\" )" -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.IMAGE_TAG }}" + git push origin diff --git a/.github/workflows/push-branch.yml b/.github/workflows/push-branch.yml index dbe3661..c21ff21 100644 --- a/.github/workflows/push-branch.yml +++ b/.github/workflows/push-branch.yml @@ -12,6 +12,7 @@ on: branches-ignore: - main - task/ccls-1880_amend_package_versions + - test permissions: contents: read diff --git a/gradle.properties b/gradle.properties index 454590a..01d8469 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=0.0.6-SNAPSHOT +version=0.0.7 group='uk.gov.laa.ccms' \ No newline at end of file