Merge pull request #2299 from hmcts/dinesh1patel-patch-1 #414
This file contains 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: Publish Swagger Specs | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Cache | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: ${{ runner.os }}-gradle- | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'temurin' | |
- name: Run Swagger Publisher | |
run: ./gradlew test --tests uk.gov.hmcts.ccd.swagger.SwaggerGeneratorTest | |
- name: Commit to repository | |
run: | | |
mkdir swagger-staging | |
cd swagger-staging | |
git init | |
git config user.email "[email protected]" | |
git config user.name "GitHub action" | |
git remote add upstream "https://jenkins-reform-hmcts:${{ secrets.GH_TOKEN }}@github.com/hmcts/cnp-api-docs.git" | |
git pull upstream master | |
repo=`echo "$GITHUB_REPOSITORY" | cut -f2- -d/` | |
echo "$(cat /tmp/ccd-data-store-api.v1_internal.json)" > "docs/specs/ccd-data-store-api.v1_internal.json" | |
echo "$(cat /tmp/ccd-data-store-api.v1_external.json)" > "docs/specs/ccd-data-store-api.v1_external.json" | |
echo "$(cat /tmp/ccd-data-store-api.v2_internal.json)" > "docs/specs/ccd-data-store-api.v2_internal.json" | |
echo "$(cat /tmp/ccd-data-store-api.v2_external.json)" > "docs/specs/ccd-data-store-api.v2_external.json" | |
git add "docs/specs/ccd-data-store-api.v1_internal.json" | |
git add "docs/specs/ccd-data-store-api.v1_external.json" | |
git add "docs/specs/ccd-data-store-api.v2_internal.json" | |
git add "docs/specs/ccd-data-store-api.v2_external.json" | |
# Only commit and push if we have changes. | |
git diff --quiet && git diff --staged --quiet || (git commit -m "Update spec for $repo#${GITHUB_SHA:7}"; git push --set-upstream upstream master) |