diff --git a/.github/workflows/validate-openapi.yml b/.github/workflows/validate-openapi.yml new file mode 100644 index 0000000..c60ea4a --- /dev/null +++ b/.github/workflows/validate-openapi.yml @@ -0,0 +1,21 @@ +name: Validate and Publish OpenAPI Spec + +on: + push: + branches: + - add-new-gha-action-for-publishing-to-readme + workflow_dispatch: # allows manual triggering + +jobs: + validate-and-publish: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Validate and Publish OpenAPI + uses: ./publish-openapi + with: + openapi-file: https://api.portal.flipdish.com/menuManagement/openapi.json # Update this path to your OpenAPI spec file + readme-api-key: ${{ secrets.README_API_KEY }} + # spectral-rules: '.spectral.yaml' # Uncomment if you want to use custom rules \ No newline at end of file diff --git a/publish-openapi/action.yml b/publish-openapi/action.yml new file mode 100644 index 0000000..01f25df --- /dev/null +++ b/publish-openapi/action.yml @@ -0,0 +1,36 @@ +name: Validate and Publish OpenAPI Spec +description: Validates OpenAPI spec using Spectral and publishes to ReadMe +inputs: + openapi-file: + description: Path to the OpenAPI specification file + required: true + readme-api-key: + description: ReadMe API key for publishing (optional - defaults to Flipdish Readme API key) + required: false + spectral-rules: + description: Path to custom Spectral rules file (optional - defaults to Flipdish rules) + required: false +runs: + using: composite + steps: + - name: Download default Spectral rules + if: ${{ !inputs.spectral-rules }} + shell: bash + run: | + curl -o .spectral.yaml https://raw.githubusercontent.com/flipdishbytes/spectral-rules/main/.spectral.yaml + + - name: Lint OpenAPI with Spectral + uses: stoplightio/spectral-action@v0.8.11 + with: + file_glob: ${{ inputs.openapi-file }} + spectral_ruleset: ${{ inputs.spectral-rules || '.spectral.yaml' }} + + - name: Validate OpenAPI spec with ReadMe + uses: readmeio/rdme@v10 + with: + rdme: openapi validate ${{ inputs.openapi-file }} + + - name: Publish to ReadMe + uses: readmeio/rdme@v10 + with: + rdme: openapi upload ${{ inputs.openapi-file }} --key=${{ inputs.readme-api-key }} \ No newline at end of file