From 5be2d23790969acd817aa44b8d1ac3b975261984 Mon Sep 17 00:00:00 2001 From: Andrea Angiolillo Date: Wed, 31 Jul 2024 11:07:36 +0100 Subject: [PATCH] fix: FOAS Prod GH Action creates wrong issue (#125) --- .github/workflows/optional-spec-validations.yml | 3 ++- .github/workflows/release-spec-prod.yml | 6 ++++-- .github/workflows/release-spec-runner.yml | 3 +++ .github/workflows/release-spec.yml | 14 +++++++++++--- .github/workflows/required-spec-validations.yml | 8 +++++--- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/optional-spec-validations.yml b/.github/workflows/optional-spec-validations.yml index e69889946..e0dec8530 100644 --- a/.github/workflows/optional-spec-validations.yml +++ b/.github/workflows/optional-spec-validations.yml @@ -32,6 +32,7 @@ jobs: github-token: ${{ secrets.api_bot_pat }} run-id: ${{ github.run_id }} - name: Validate the FOAS can be used to generate Postman collection + id: spectral-validation env: SPECTRAL_VERSION: ${{ inputs.spectral_version }} run: | @@ -41,7 +42,7 @@ jobs: npx -- @stoplight/spectral-cli@"${SPECTRAL_VERSION}" lint ./tmp/collection.json --ruleset=./validation/spectral.yaml popd - name: Create Issue - if: ${{ failure() }} + if: ${{ failure() && steps.spectral-validation.outcome == 'failure' }} uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd env: target_env: ${{ inputs.env }} diff --git a/.github/workflows/release-spec-prod.yml b/.github/workflows/release-spec-prod.yml index e33935a20..d084831ad 100644 --- a/.github/workflows/release-spec-prod.yml +++ b/.github/workflows/release-spec-prod.yml @@ -65,6 +65,7 @@ jobs: working-directory: tools/cli run: make build - name: Run foascli split command + id: split run: | ./tools/cli/bin/foascli split -s openapi-foas.json --env prod -o ./openapi/v2/openapi.json cp -rf "openapi-foas.json" "./openapi/v2.json" @@ -72,7 +73,7 @@ jobs: ./tools/cli/bin/foascli split -s openapi-foas.yaml --env prod -o ./openapi/v2/openapi.yaml cp -rf "openapi-foas.yaml" "./openapi/v2.yaml" - name: Create Issue - if: ${{ failure() }} + if: ${{ failure() && steps.split.outcome == 'failure' }} uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd with: labels: failed-release @@ -82,6 +83,7 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c + id: create-pr with: token: ${{ secrets.GITHUB_TOKEN }} title: "release: (prod) Release OpenAPI Spec :rocket:" @@ -94,7 +96,7 @@ jobs: Automatic Release for MongoDB Atlas OpenAPI Specification. PR contains autogenerated changes of the OpenAPI specification based on the latest services deployed in production. - name: Create Issue - if: ${{ failure() }} + if: ${{ failure() && steps.create-pr.outcome == 'failure' }} uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd with: labels: failed-release diff --git a/.github/workflows/release-spec-runner.yml b/.github/workflows/release-spec-runner.yml index d02e5f8cd..9e4b50173 100644 --- a/.github/workflows/release-spec-runner.yml +++ b/.github/workflows/release-spec-runner.yml @@ -21,6 +21,7 @@ jobs: aws_s3_bucket: ${{ vars.S3_BUCKET_DEV}} env: dev spectral_version: ${{ vars.SPECTRAL_VERSION }} + foascli_version: ${{ vars.FOASCLI_VERSION }} release-spec-qa: name: Release OpenAPI Spec for QA uses: ./.github/workflows/release-spec.yml @@ -33,6 +34,7 @@ jobs: aws_s3_bucket: ${{ vars.S3_BUCKET_QA}} env: qa spectral_version: ${{ vars.SPECTRAL_VERSION }} + foascli_version: ${{ vars.FOASCLI_VERSION }} release-spec-staging: name: Release OpenAPI Spec for STAGING uses: ./.github/workflows/release-spec.yml @@ -45,3 +47,4 @@ jobs: aws_s3_bucket: ${{ vars.S3_BUCKET_STAGING}} env: staging spectral_version: ${{ vars.SPECTRAL_VERSION }} + foascli_version: ${{ vars.FOASCLI_VERSION }} diff --git a/.github/workflows/release-spec.yml b/.github/workflows/release-spec.yml index 0a7479fc7..37e1488c0 100644 --- a/.github/workflows/release-spec.yml +++ b/.github/workflows/release-spec.yml @@ -18,6 +18,10 @@ on: description: 'Version of Spectral to use.' required: true type: string + foascli_version: + description: 'Version of FOASCLI to use.' + required: true + type: string secrets: # all secrets are passed explicitly in this workflow api_bot_pat: required: true @@ -81,13 +85,16 @@ jobs: github-token: ${{ secrets.api_bot_pat }} run-id: ${{ github.run_id }} - name: Install FOASCLI + env: + foascli_version: ${{ inputs.foascli_version }} run: | - wget https://github.com/mongodb/openapi/releases/download/v0.0.8/mongodb-foas-cli_0.0.8_linux_x86_64.tar.gz -O foascli.tar.gz + wget https://github.com/mongodb/openapi/releases/download/v"${foascli_version}"/mongodb-foas-cli_"${foascli_version}"_linux_x86_64.tar.gz -O foascli.tar.gz tar -xzvf foascli.tar.gz pushd mongodb-foas-cli_* echo "$(pwd)/bin" >> "${GITHUB_PATH}" popd - name: Run foascli split command + id: split env: target_env: ${{ inputs.env }} run: | @@ -97,7 +104,7 @@ jobs: foascli split -s openapi-foas.yaml --env "${target_env}" -o ./openapi/v2/openapi.yaml cp -rf "openapi-foas.yaml" "./openapi/v2.yaml" - name: Create Issue - if: ${{ failure() }} + if: ${{ failure() && steps.split.outcome == 'failure' }} uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd env: target_env: ${{ inputs.env }} @@ -107,6 +114,7 @@ jobs: body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} token: ${{ secrets.GITHUB_TOKEN }} - name: Commit changes + id: commit uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 env: target_env: ${{ inputs.env }} @@ -116,7 +124,7 @@ jobs: branch: ${{env.target_env}} file_pattern: "openapi/*" - name: Create Issue - if: ${{ failure() }} + if: ${{ failure() && steps.commit.outcome == 'failure' }} uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd env: target_env: ${{ inputs.env }} diff --git a/.github/workflows/required-spec-validations.yml b/.github/workflows/required-spec-validations.yml index 38fb2bc80..4b0dd129d 100644 --- a/.github/workflows/required-spec-validations.yml +++ b/.github/workflows/required-spec-validations.yml @@ -30,12 +30,13 @@ jobs: name: openapi-foas-${{ inputs.env }} github-token: ${{ secrets.api_bot_pat }} run-id: ${{ github.run_id }} - - name: Run Spectral + - name: Run + id: spectral-validation env: SPECTRAL_VERSION: ${{ inputs.spectral_version }} run: npx -- @stoplight/spectral-cli@"${SPECTRAL_VERSION}" lint openapi-foas.yaml --ruleset=.spectral.yaml # we will update this to lint the FOAS in CLOUDP-263186 - name: Create Issue - if: ${{ failure() }} + if: ${{ failure() && steps.spectral-validation.outcome == 'failure' }} uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd env: target_env: ${{ inputs.env }} @@ -62,13 +63,14 @@ jobs: github-token: ${{ secrets.api_bot_pat }} run-id: ${{ github.run_id }} - name: Validate the FOAS can be used with the Go SDK + id: go-sdk-validation run: | cp -rf "openapi-foas.yaml" "atlas-sdk-go/openapi/atlas-sdk.yaml" pushd atlas-sdk-go make -e openapi-pipeline popd - name: Create Issue - if: ${{ failure() }} + if: ${{ failure() && steps.go-sdk-validation.outcome == 'failure' }} uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd env: target_env: ${{ inputs.env }}