diff --git a/.github/workflows/swagger-delete.yml b/.github/workflows/swagger-delete.yml new file mode 100644 index 000000000..d2fceb3c2 --- /dev/null +++ b/.github/workflows/swagger-delete.yml @@ -0,0 +1,31 @@ +name: Delete spec version from SwaggerHub +defaults: + run: + working-directory: . +on: + pull_request: + types: [closed] + branches: + - master + push: + branches: + - release/[0-9]+.[0-9]+.[0-9]+ + - master + +jobs: + removespec: + name: Delete api from SwaggerHub + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16.16.0' + - run: npm i --location=global swaggerhub-cli + - run: | + VERSION=`echo ${GITHUB_REF_NAME}| sed 's#[^a-zA-Z0-9_\.\-]#_#g'` + SWAGGERHUB_API_KEY=${{secrets.SWAGGERHUB_TOKEN}} swaggerhub api:unpublish "Moira/moira-alert/${VERSION}" || true + SWAGGERHUB_API_KEY=${{secrets.SWAGGERHUB_TOKEN}} swaggerhub api:delete "Moira/moira-alert/${VERSION}" || true +# The `|| true` at the end of the calls is necessary to keep the job from crashing +# when deleting documentation that hasn't been created yet, but if you see something wrong happening, +# remove `|| true` from the command diff --git a/.github/workflows/swagger-publish.yml b/.github/workflows/swagger-publish.yml new file mode 100644 index 000000000..03e623c36 --- /dev/null +++ b/.github/workflows/swagger-publish.yml @@ -0,0 +1,60 @@ +name: Publish spec version to SwaggerHub + +on: + push: + branches: + - master + - release/[0-9]+.[0-9]+.[0-9]+ + +jobs: + validate-spec: + name: Validate spec file + runs-on: ubuntu-22.04 + defaults: + run: + working-directory: . + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v4 + with: + go-version-file: go.mod + cache-dependency-path: go.sum + - run: make install-swag + + - uses: actions/setup-node@v3 + with: + node-version: '16.16.0' + - run: npm install --location=global @openapitools/openapi-generator-cli + - run: make spec + - run: make validate-spec + + - name: Save build artifact + uses: actions/upload-artifact@v3 + with: + name: specfile + path: docs/swagger.yaml + + publishspec: + name: Upload generated OpenAPI description + runs-on: ubuntu-22.04 + needs: validate-spec + defaults: + run: + working-directory: . + + steps: + - uses: actions/checkout@v3 + + - name: Download spec file artifact + uses: actions/download-artifact@v3 + with: + name: specfile + path: docs + + - uses: actions/setup-node@v3 + - run: npm i --location=global swaggerhub-cli + - run: | + VERSION=`echo ${GITHUB_REF_NAME}| sed 's#[^a-zA-Z0-9_\.\-]#_#g'` + SWAGGERHUB_API_KEY=${{secrets.SWAGGERHUB_TOKEN}} swaggerhub api:create "Moira/moira-alert/${VERSION}" -f ./docs/swagger.yaml --published=publish --visibility=public diff --git a/.github/workflows/swagger-validate.yml b/.github/workflows/swagger-validate.yml new file mode 100644 index 000000000..a39d7daba --- /dev/null +++ b/.github/workflows/swagger-validate.yml @@ -0,0 +1,28 @@ +name: Validate OpenAPI on PR + +on: + - pull_request + +jobs: + mergespec: + name: Validate spec file + runs-on: ubuntu-22.04 + defaults: + run: + working-directory: . + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v4 + with: + go-version-file: go.mod + cache-dependency-path: go.sum + - run: make install-swag + + - uses: actions/setup-node@v3 + with: + node-version: '16.16.0' + - run: npm install --location=global @openapitools/openapi-generator-cli + - run: make spec + - run: make validate-spec