Skip to content

Commit e680b73

Browse files
Merge pull request #33 from hmcts/update-build
update build to publish after all tests have completed
2 parents ad2837f + 603d991 commit e680b73

File tree

10 files changed

+328
-205
lines changed

10 files changed

+328
-205
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @hmcts/cp-case-administration

.github/CONTRIBUTING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contribution guidelines
2+
3+
We're happy to accept 3rd-party contributions. Please make sure you read this document before you do any work though,
4+
as we have some expectations related to the content and quality of change sets.
5+
6+
## What you should know about this application
7+
8+
This project is a template Spring Boot application. It aims to speed up the creation of new Spring APIs in HMCTS
9+
projects, by serving as the initial setup of each API.
10+
11+
## Before contributing
12+
13+
Any ideas on the user journeys and general service experience you may have **should be first consulted
14+
with us by submitting a new issue** to this repository. Ideas are always welcome, but if something is divergent or unrelated
15+
to what we're trying to achieve we won't be able to accept it. Please keep this in mind as we don't want to waste anybody's time.
16+
17+
In the interest of creating a friendly collaboration environment, please read and adhere to an open source contributor's
18+
[code of conduct](http://contributor-covenant.org/version/1/4/).
19+
20+
## Making a contribution
21+
22+
After your idea has been accepted you can implement it. We don't allow direct changes to the codebase from the public,
23+
they have to go through a review first.
24+
25+
Here's what you should do:
26+
1. [fork](https://help.github.com/articles/fork-a-repo/) this repository and clone it to your machine,
27+
2. create a new branch for your change:
28+
* use the latest *master* to branch from,
29+
3. implement the change in your branch:
30+
* if the change is non-trivial it's a good practice to split it into several logically independent units and deliver
31+
each one as a separate commit,
32+
* make sure the commit messages use proper language and accurately describe commit's content, e.g. *"Unify postcode lookup elements spacing"*.
33+
More information on good commit messages can be found [here](http://chris.beams.io/posts/git-commit/),
34+
4. test if your feature works as expected and does not break any existing features, this may include implementing additional automated tests or amending existing ones,
35+
5. push the change to your GitHub fork,
36+
6. submit a [pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) to our repository:
37+
* ensure that the pull request and related GitHub issue reference each other.
38+
39+
At this point the pull request will wait for someone from our team to review. It may be accepted straight away,
40+
or we may ask you to make some additional amendments before incorporating it into the main branch.

.github/ISSUE_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### What would you like to change?
2+
3+
### How do you think that would improve the project?
4+
5+
### If this entry is related to a bug, please provide the steps to reproduce it

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Before creating a pull request make sure that:**
2+
3+
- [ ] commit messages are meaningful and follow good commit message guidelines
4+
- [ ] README and other documentation has been updated / added (if needed)
5+
- [ ] tests have been updated / new tests has been added (if needed)
6+
7+
Please remove this line and everything above and fill the following sections:
8+
9+
10+
### JIRA link (if applicable) ###
11+
12+
13+
14+
### Change description ###
15+
16+
17+
18+
**Does this PR introduce a breaking change?** (check one with "x")
19+
20+
```
21+
[ ] Yes
22+
[ ] No
23+
```

.github/workflows/ci-draft.yml

Lines changed: 81 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Build and Publish Increments Draft
1+
name: Build and Publish (DRAFT CANDIDATE VERSION)
22

33
on:
44
pull_request:
@@ -17,79 +17,94 @@ jobs:
1717
Artefact-Version:
1818
runs-on: ubuntu-latest
1919
outputs:
20-
draft_version: ${{ steps.vars.outputs.draft_version }}
21-
latest_tag: ${{ steps.vars.outputs.latest_tag }}
20+
artefact_version: ${{ steps.artefact.outputs.draft_version }}
2221
steps:
2322
- name: Checkout code
2423
uses: actions/checkout@v4
2524
with:
26-
fetch-depth: 0
25+
fetch-depth: 0 # Necessary to fetch all history for accurate versioning
2726

28-
# - name: Show Git tags and commit context (diagnostic/debug)
29-
# run: git tag --list && git log --oneline --decorate
30-
31-
- name: Get short SHA for versioning
32-
id: vars
33-
run: |
34-
if LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null); then
35-
:
36-
else
37-
LATEST_TAG="v0.0.0"
38-
fi
39-
echo "🏷️ Latest Git tag resolved to: $LATEST_TAG"
40-
LATEST_TAG="${LATEST_TAG#v}"
41-
42-
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
43-
44-
SHORT_SHA=$(git rev-parse --short HEAD)
45-
DRAFT_VERSION="${LATEST_TAG}-${SHORT_SHA}"
46-
47-
echo "draft_version=$DRAFT_VERSION"
48-
echo "draft_version=$DRAFT_VERSION" >> $GITHUB_OUTPUT
27+
- name: Generate Artefact Version
28+
id: artefact
29+
uses: hmcts/artefact-version-action@v1
30+
with:
31+
release: false
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4934

5035
Update-Spec-Version:
5136
needs: [Artefact-Version]
5237
runs-on: ubuntu-latest
5338
outputs:
54-
openapi_file: ${{ steps.find_spec.outputs.openapi_file }}
39+
upload_artifact_name: ${{ steps.update_spec.outputs.upload_artifact_name }}
5540
steps:
5641
- name: Checkout code
5742
uses: actions/checkout@v4
5843

59-
- name: Find OpenAPI file
60-
id: find_spec
61-
run: |
62-
FILE=$(find "${FILE_PATH_OPENAPI}" -name "*.openapi.yml" | head -n 1)
63-
if [ -z "$FILE" ]; then
64-
echo "⚠️ *** No OpenAPI spec (*.openapi.yml) found. Skipping publishing draft. ***"
65-
exit 1
66-
fi
67-
echo "openapi_file=$FILE" >> $GITHUB_OUTPUT
68-
69-
- name: Update info.version in OpenAPI spec using yq
70-
env:
71-
API_NAME: ${{ github.event.repository.name }}
72-
API_VERSION: ${{ needs.Artefact-Version.outputs.draft_version }}
73-
uses: mikefarah/[email protected]
44+
- name: Update OpenAPI Spec Version
45+
id: update_spec
46+
uses: hmcts/update-openapi-version@main
7447
with:
75-
cmd: |
76-
yq '
77-
.info.version = strenv(API_VERSION) |
78-
.servers[0].url = "https://virtserver.swaggerhub.com/HMCTS-DTS/" + strenv(API_NAME) + "/" + strenv(API_VERSION)
79-
' "${{ steps.find_spec.outputs.openapi_file }}" > openapi-versioned.yml
48+
openapi_path: ${{ env.FILE_PATH_OPENAPI }}
49+
api_name: ${{ github.event.repository.name }}
50+
api_version: ${{ needs.Artefact-Version.outputs.artefact_version }}
51+
52+
Test:
53+
name: Test - Java ${{ matrix.java }}
54+
strategy:
55+
matrix:
56+
java: [17, 21, 23]
57+
runs-on: ubuntu-latest
58+
needs: [Artefact-Version, Update-Spec-Version]
8059

81-
- name: Replace original OpenAPI file
82-
run: mv openapi-versioned.yml "${{ steps.find_spec.outputs.openapi_file }}"
60+
steps:
61+
- name: Checkout source code
62+
uses: actions/checkout@v4
8363

84-
- name: Upload updated OpenAPI file
85-
uses: actions/upload-artifact@v4
64+
- name: Set up JDK
65+
uses: actions/setup-java@v4
8666
with:
87-
name: updated-openapi-spec
88-
path: ${{ steps.find_spec.outputs.openapi_file }}
67+
distribution: 'temurin'
68+
java-version: ${{ matrix.java }}
8969

90-
Build:
91-
needs: [Artefact-Version, Update-Spec-Version]
70+
- name: Set up Gradle
71+
uses: gradle/actions/setup-gradle@v4
72+
with:
73+
gradle-version: current
74+
75+
- name: Download updated OpenAPI file
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: ${{ needs.Update-Spec-Version.outputs.upload_artifact_name }}
79+
path: ${{ env.FILE_PATH_OPENAPI }}
80+
81+
- name: Gradle Build
82+
env:
83+
ARTEFACT_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }}
84+
JAVA_VERSION: ${{ matrix.java }}
85+
run: |
86+
echo "Building with ARTEFACT_VERSION=$ARTEFACT_VERSION using Java $JAVA_VERSION"
87+
gradle build -DAPI_SPEC_VERSION=$ARTEFACT_VERSION
88+
89+
Push-Draft-OpenAPI-Spec:
90+
needs: [ Test ]
91+
uses: ./.github/workflows/publish-openapi-spec.yml
92+
secrets:
93+
SWAGGERHUB_API_KEY: ${{ secrets.APIHUB_API_KEY }}
94+
with:
95+
upload_artifact_name: ${{ needs.Update-Spec-Version.outputs.upload_artifact_name }}
96+
apihub_owner: ${{ vars.APIHUB_ORGANISATION }}
97+
api_name: ${{ github.event.repository.name }}
98+
api_version: ${{ needs.Artefact-Version.outputs.artefact_version }}
99+
100+
Publish:
101+
name: Publish Artefact - Java ${{ matrix.java }}
102+
if: github.event_name == 'push'
92103
runs-on: ubuntu-latest
104+
needs: [Artefact-Version, Push-Draft-OpenAPI-Spec]
105+
strategy:
106+
matrix:
107+
java: [17]
93108

94109
steps:
95110
- name: Checkout source code
@@ -99,63 +114,31 @@ jobs:
99114
uses: actions/setup-java@v4
100115
with:
101116
distribution: 'temurin'
102-
java-version: '21'
117+
java-version: ${{ matrix.java }}
103118

104119
- name: Set up Gradle
105120
uses: gradle/actions/setup-gradle@v4
106-
with:
107-
gradle-version: current
108121

109122
- name: Download updated OpenAPI file
110123
uses: actions/download-artifact@v4
111124
with:
112-
name: updated-openapi-spec
125+
name: ${{ needs.Update-Spec-Version.outputs.upload_artifact_name }}
113126
path: ${{ env.FILE_PATH_OPENAPI }}
114127

115-
# - name: Set Sonar Project Key and Name
116-
# id: sonar_vars
117-
# run: |
118-
# repo_sanitized="${GITHUB_REPOSITORY//\//_}"
119-
# echo "project_key=$repo_sanitized" >> $GITHUB_OUTPUT
120-
# echo "project_name=$repo_sanitized" >> $GITHUB_OUTPUT
121-
#
122-
# - name: Analyze with SonarCloud
123-
# uses: SonarSource/[email protected]
124-
# with:
125-
# args: >
126-
# -Dsonar.organization=hmcts
127-
# -Dsonar.projectKey=${{ steps.sonar_vars.outputs.project_key }}
128-
# -Dsonar.projectName=${{ steps.sonar_vars.outputs.project_name }}
129-
# -Dsonar.projectVersion=${{ needs.Artefact-Version.outputs.draft_version }}
130-
# -Dsonar.sources=src
131-
# -Dsonar.java.binaries=build/classes
132-
# env:
133-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134-
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
135-
136-
- name: Gradle Build and Publish on Push [Merge]
128+
- name: Gradle Publish
137129
env:
130+
ARTEFACT_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }}
138131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139132
AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
140133
AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
134+
JAVA_VERSION: ${{ matrix.java }}
141135
run: |
142-
VERSION=${{ needs.Artefact-Version.outputs.draft_version }}
143-
144-
gradle build \
145-
-DAPI_SPEC_VERSION=$VERSION \
136+
echo "Publishing artefact for ARTEFACT_VERSION=$ARTEFACT_VERSION using Java $JAVA_VERSION"
137+
138+
gradle build -x test publish \
139+
-DAPI_SPEC_VERSION=$ARTEFACT_VERSION \
146140
-DGITHUB_REPOSITORY=${{ github.repository }} \
147141
-DGITHUB_ACTOR=${{ github.actor }} \
148-
-DGITHUB_TOKEN=$GITHUB_TOKEN
149-
150-
if [ "${{ github.event_name }}" == "push" ]; then
151-
echo "Push event trigger - Publishing artefact"
152-
gradle publish \
153-
-DAPI_SPEC_VERSION=$VERSION \
154-
-DGITHUB_REPOSITORY=${{ github.repository }} \
155-
-DGITHUB_ACTOR=${{ github.actor }} \
156-
-DGITHUB_TOKEN=$GITHUB_TOKEN \
157-
-DAZURE_DEVOPS_ARTIFACT_USERNAME=$HMCTS_ARTEFACT_ACTOR \
158-
-DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN
159-
else
160-
echo "Skipping publish because this is a pull_request"
161-
fi
142+
-DGITHUB_TOKEN=$GITHUB_TOKEN \
143+
-DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \
144+
-DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN

0 commit comments

Comments
 (0)