Skip to content

S28-3556 - Create GET /audit API endpoint #2638

S28-3556 - Create GET /audit API endpoint

S28-3556 - Create GET /audit API endpoint #2638

name: Publish Swagger V2
on:
pull_request:
branches:
- master
jobs:
publish-swagger-v2:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: npm install -g api-spec-converter
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
cache: 'gradle'
- name: Run OpenAPI Publisher
run: ./gradlew integration --tests 'uk.gov.hmcts.reform.preapi.openapi.OpenAPIPublisherTest'
- name: Convert OpenAPI to Swagger v2
run: |
api-spec-converter \
--to=swagger_2 \
--from=openapi_3 \
--syntax=yaml \
--order=alpha /tmp/openapi-specs.json > pre-api.yaml
sed 's/basePath\: \//basePath\: \/pre-api/g' pre-api.yaml > pre-api2.yaml && \
sed 's/\- http/\- https/g' pre-api2.yaml > pre-api.yaml && \
rm -f pre-api2.yaml
- name: Save swagger for staging
run: |
sed -E "s/(host\: .+)/host\: 'sds-api-mgmt.staging.platform.hmcts.net'/g" pre-api.yaml > pre-api-stg.yaml
- name: wget master main.tf
uses: wei/wget@v1
with:
args: -O main.tf https://raw.githubusercontent.com/hmcts/pre-api/master/infrastructure/main.tf
- name: wget master pre-api-stg.yaml
uses: wei/wget@v1
with:
args: -O master.pre-api-stg.yaml https://raw.githubusercontent.com/hmcts/pre-api/master/pre-api-stg.yaml
- name: Increment APIm revision
run: |
git config --global user.name 'PRE DevOps'
git config --global user.email '138598290+pre-devops@users.noreply.github.com'
CHANGED=$(git diff --name-only pre-api-stg.yaml)
commit_message=""
if [ "$CHANGED" = "pre-api-stg.yaml" ]; then
echo "spec has been updated this commit"
git add pre-api-stg.yaml
commit_message="Update Swagger v2 Spec"
fi
# get the revision number from the main.tf file in master
master_revision=$(grep -i 'revision' main.tf | grep -oE '[0-9]+')
branch_revision=$(grep -i 'revision' infrastructure/main.tf | grep -oE '[0-9]+')
if cmp "master.pre-api-stg.yaml" "pre-api-stg.yaml"; then
echo "No changes to pre-api-stg.yaml"
if [[ $master_revision -gt $branch_revision ]]; then
echo "Master revision is greater than branch revision"
awk -v new_revision="$master_revision" 'BEGIN{FS=OFS="\""} /revision/{$2=new_revision}1' infrastructure/main.tf > temp && mv temp infrastructure/main.tf
git add infrastructure/main.tf
commit_message="${commit_message} Bump APIm revision to $master_revision"
fi
else
echo "API Spec has changed compared to master, ensure revision is incremented"
if [[ $master_revision -ge $branch_revision ]]; then
new_revision=$((master_revision + 1))
awk -v new_revision="$new_revision" 'BEGIN{FS=OFS="\""} /revision/{$2=new_revision}1' infrastructure/main.tf > temp && mv temp infrastructure/main.tf
git add infrastructure/main.tf
commit_message="${commit_message} Bump APIm revision to $new_revision"
fi
fi
# cleanup
rm -f main.tf master.pre-api-stg.yaml
# commit and push if there are changes
if [ -n "$commit_message" ]; then
git config --global user.name 'PRE DevOps'
git config --global user.email '138598290+pre-devops@users.noreply.github.com'
git commit -m "$commit_message"
git push
fi
echo "done"