Merge pull request #24 from hmcts/openapi-update #9
Workflow file for this run
This file contains hidden or 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
| 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}}" | |
| # } |