Skip to content

Commit

Permalink
DTSPO-13135 OpenAPI reusable workflow (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored Mar 28, 2023
1 parent f4805ec commit caa170c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @hmcts/platform-operations
13 changes: 13 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"schedule": "after 7am and before 11am every weekday",
"extends": [
"config:base"
],
"labels": [
"dependencies"
],
"platformAutomerge": true,
"automerge": true,
"automergeType": "pr"
}
44 changes: 44 additions & 0 deletions .github/workflows/publish-openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish OpenAPI Spec

on:
workflow_call:
inputs:
test_to_run:
required: true
type: string
description: The full path to the test to run, e.g. uk.gov.hmcts.reform.myapp.openapi.OpenAPIPublisherTest
java_version:
required: true
type: string
secrets:
SWAGGER_PUBLISHER_API_TOKEN:
required: true
description: GitHub API token that can publish to the cnp-api-docs repository

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ inputs.java_version }}
uses: actions/setup-java@v3
with:
java-version: ${{ inputs.java_version }}
distribution: 'temurin'
cache: 'gradle'
- name: Run OpenAPI Publisher
run: ./gradlew integration --tests ${{ inputs.test_to_run }}
- name: Commit to repository
run: |
mkdir openapi-staging
cd openapi-staging
git init
git config user.email "[email protected]"
git config user.name "HMCTS Platform Operations"
git remote add upstream https://apitoken:${{ secrets.SWAGGER_PUBLISHER_API_TOKEN }}@github.com/hmcts/cnp-api-docs.git
git pull upstream master
repo=`echo "$GITHUB_REPOSITORY" | cut -f2- -d/`
echo "$(cat /tmp/openapi-specs.json)" > "docs/specs/$repo.json"
git add "docs/specs/$repo.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)
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# github-reusable-workflows
# workflow-publish-openapi-spec

This reusuable workflow can be used to published OpenAPI specs to the [HMCTS CNP API repository](https://github.com/hmcts/cnp-api-docs).

## Usage

There's a workflow template at https://github.com/hmcts/.github/blob/master/workflow-templates/publish-openapi.yml.

To use it from your repository go to:

Actions -> New workflow

Click Configure under "Publish OpenAPI specs"

Update the `test_to_run` input variable
Check the `java_version` variable is right for your project

0 comments on commit caa170c

Please sign in to comment.