|
1 | | -name: CI Build and Publish Increments Draft |
| 1 | +name: Build and Publish (Non-Release) |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
|
11 | 11 | - main |
12 | 12 |
|
13 | 13 | jobs: |
14 | | - Artefact-Version: |
15 | | - runs-on: ubuntu-latest |
16 | | - outputs: |
17 | | - draft_version: ${{ steps.vars.outputs.draft_version }} |
18 | | - latest_tag: ${{ steps.vars.outputs.latest_tag }} |
19 | | - steps: |
20 | | - - name: Checkout code |
21 | | - uses: actions/checkout@v4 |
22 | | - with: |
23 | | - fetch-depth: 0 |
| 14 | + ci-draft: |
| 15 | + uses: ./.github/workflows/ci-build-publish.yml |
| 16 | + secrets: |
| 17 | + AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }} |
| 18 | + AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }} |
| 19 | + HMCTS_ADO_PAT: ${{ secrets.HMCTS_ADO_PAT }} |
| 20 | + with: |
| 21 | + is_publish: ${{ github.event_name == 'push' }} |
| 22 | + trigger_docker: ${{ github.event_name == 'push' }} |
| 23 | + trigger_deploy: ${{ github.event_name == 'push' }} |
24 | 24 |
|
25 | | - - name: Get short SHA for versioning |
26 | | - id: vars |
27 | | - run: | |
28 | | - if LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null); then |
29 | | - : |
30 | | - else |
31 | | - LATEST_TAG="v0.0.0" |
32 | | - fi |
33 | | - echo "🏷️ Latest Git tag resolved to: $LATEST_TAG" |
34 | | - LATEST_TAG="${LATEST_TAG#v}" |
35 | | -
|
36 | | - echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT |
37 | | -
|
38 | | - SHORT_SHA=$(git rev-parse --short HEAD) |
39 | | - DRAFT_VERSION="${LATEST_TAG}-${SHORT_SHA}" |
40 | | -
|
41 | | - echo "draft_version=$DRAFT_VERSION" |
42 | | - echo "draft_version=$DRAFT_VERSION" >> $GITHUB_OUTPUT |
43 | | -
|
44 | | - Build: |
45 | | - needs: [Artefact-Version] |
46 | | - runs-on: ubuntu-latest |
47 | | - outputs: |
48 | | - repo_name: ${{ steps.repo_vars.outputs.repo_name }} |
49 | | - artefact_name: ${{ steps.repo_vars.outputs.artefact_name }} |
50 | | - |
51 | | - steps: |
52 | | - - name: Checkout source code |
53 | | - uses: actions/checkout@v4 |
54 | | - |
55 | | - - name: Set up JDK |
56 | | - uses: actions/setup-java@v4 |
57 | | - with: |
58 | | - distribution: 'temurin' |
59 | | - java-version: '21' |
60 | | - |
61 | | - - name: Set up Gradle |
62 | | - uses: gradle/actions/setup-gradle@v4 |
63 | | - with: |
64 | | - gradle-version: current |
65 | | - |
66 | | - - name: Gradle Build and Publish on Push [Merge] |
67 | | - env: |
68 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
69 | | - AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }} |
70 | | - AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }} |
71 | | - run: | |
72 | | - VERSION=${{ needs.Artefact-Version.outputs.draft_version }} |
73 | | -
|
74 | | - gradle build -DAPI_SPEC_VERSION=$VERSION |
75 | | -
|
76 | | - if [ "${{ github.event_name }}" == "push" ]; then |
77 | | - echo "Push event trigger - Publishing artefact" |
78 | | - gradle publish \ |
79 | | - -DAPI_SPEC_VERSION=$VERSION \ |
80 | | - -DGITHUB_REPOSITORY=${{ github.repository }} \ |
81 | | - -DGITHUB_ACTOR=${{ github.actor }} \ |
82 | | - -DGITHUB_TOKEN=$GITHUB_TOKEN \ |
83 | | - -DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \ |
84 | | - -DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN |
85 | | - else |
86 | | - echo "Skipping publish because this is a pull_request" |
87 | | - fi |
88 | | -
|
89 | | - - name: Extract repo name |
90 | | - if: github.event_name == 'push' |
91 | | - id: repo_vars |
92 | | - run: | |
93 | | - repo_name=${GITHUB_REPOSITORY##*/} |
94 | | - echo "repo_name=${repo_name}" >> $GITHUB_OUTPUT |
95 | | - echo "artefact_name=${repo_name}-${{ needs.Artefact-Version.outputs.draft_version }}" >> $GITHUB_OUTPUT |
96 | | -
|
97 | | - - name: Upload JAR Artefact |
98 | | - uses: actions/upload-artifact@v4 |
99 | | - if: github.event_name == 'push' |
100 | | - with: |
101 | | - name: app-jar |
102 | | - path: build/libs/${{ steps.repo_vars.outputs.artefact_name }}.jar |
103 | | - |
104 | | - Build-Docker: |
105 | | - needs: [ Build, Artefact-Version ] |
106 | | - runs-on: ubuntu-latest |
107 | | - if: github.event_name == 'push' |
108 | | - |
109 | | - steps: |
110 | | - - name: Checkout Code |
111 | | - uses: actions/checkout@v4 |
112 | | - |
113 | | - - name: Download JAR Artefact |
114 | | - uses: actions/download-artifact@v4 |
115 | | - with: |
116 | | - name: app-jar |
117 | | - path: build/libs |
118 | | - |
119 | | - - name: Set up Docker Buildx |
120 | | - uses: docker/setup-buildx-action@v3 |
121 | | - |
122 | | - - name: Log in to GitHub Packages |
123 | | - uses: docker/login-action@v3 |
124 | | - with: |
125 | | - registry: ghcr.io |
126 | | - username: ${{ github.actor }} |
127 | | - password: ${{ secrets.GITHUB_TOKEN }} |
128 | | - |
129 | | - - name: Build and Push Docker Image to GitHub |
130 | | - uses: docker/build-push-action@v6 |
131 | | - with: |
132 | | - context: . |
133 | | - file: Dockerfile |
134 | | - push: true |
135 | | - tags: | |
136 | | - ghcr.io/${{ github.repository }}:${{ needs.Artefact-Version.outputs.draft_version }} |
137 | | - build-args: | |
138 | | - BASE_IMAGE=openjdk:21-jdk-slim |
139 | | - JAR_FILENAME=${{ needs.Build.outputs.artefact_name }}.jar |
140 | | -
|
141 | | - Deploy: |
142 | | - needs: [ Build, Artefact-Version ] |
143 | | - runs-on: ubuntu-latest |
144 | | - if: github.event_name == 'push' |
145 | | - |
146 | | - steps: |
147 | | - - name: Trigger ADO pipeline |
148 | | - env: |
149 | | - ADO_ORG: 'hmcts-cpp' |
150 | | - ADO_PROJECT: 'cpp-apps' |
151 | | - PIPELINE_ID: 460 #cp-gh-artifact-to-acr |
152 | | - ADO_PAT: ${{ secrets.HMCTS_ADO_PAT }} |
153 | | - run: | |
154 | | - ARTEFACT_VERSION="${{ needs.Artefact-Version.outputs.draft_version }}" |
155 | | - REPO_NAME="${GITHUB_REPOSITORY##*/}" |
156 | | - TARGET_REPOSITORY="${GITHUB_REPOSITORY}" |
157 | | -
|
158 | | - curl -X POST \ |
159 | | - -u ":${ADO_PAT}" \ |
160 | | - -H "Content-Type: application/json" \ |
161 | | - https://dev.azure.com/${ADO_ORG}/${ADO_PROJECT}/_apis/pipelines/${PIPELINE_ID}/runs?api-version=7.0 \ |
162 | | - -d "{ |
163 | | - \"resources\": { |
164 | | - \"repositories\": { |
165 | | - \"self\": { |
166 | | - \"refName\": \"refs/heads/main\" |
167 | | - } |
168 | | - } |
169 | | - }, |
170 | | - \"templateParameters\": { |
171 | | - \"GROUP_ID\": \"uk.gov.hmcts.cp\", |
172 | | - \"ARTIFACT_ID\": \"${REPO_NAME}\", |
173 | | - \"ARTIFACT_VERSION\": \"${ARTEFACT_VERSION}\", |
174 | | - \"TARGET_REPOSITORY\": \"${TARGET_REPOSITORY}\" |
175 | | - } |
176 | | - }" |
0 commit comments