|
| 1 | +name: 'Release OpenAPI Spec for a given environment' |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + aws_default_region: |
| 6 | + description: 'AWS Default Region.' |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + aws_s3_bucket: |
| 10 | + description: 'AWS S3 Bucket.' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + env: |
| 14 | + description: 'Environment to generate the OpenAPI Spec for.' |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + spectral_version: |
| 18 | + description: 'Version of Spectral to use.' |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + secrets: # all secrets are passed explicitly in this workflow |
| 22 | + api_bot_pat: |
| 23 | + required: true |
| 24 | + aws_access_key_id: |
| 25 | + required: true |
| 26 | + aws_secret_access_key: |
| 27 | + required: true |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: write |
| 31 | + issues: write |
| 32 | + |
| 33 | +jobs: |
| 34 | + generate-spec: |
| 35 | + name: Generate the OpenAPI Spec |
| 36 | + uses: ./.github/workflows/generate-openapi.yml |
| 37 | + secrets: |
| 38 | + api_bot_pat: ${{ secrets.api_bot_pat }} |
| 39 | + aws_access_key_id: ${{ secrets.aws_access_key_id }} |
| 40 | + aws_secret_access_key: ${{ secrets.aws_secret_access_key }} |
| 41 | + with: |
| 42 | + aws_default_region: ${{ inputs.aws_default_region}} |
| 43 | + aws_s3_bucket: ${{ inputs.aws_s3_bucket}} |
| 44 | + env: ${{ inputs.env }} |
| 45 | + |
| 46 | + # Required validations will stop the release if they fail |
| 47 | + run-required-validations: |
| 48 | + name: Run Required Validations |
| 49 | + needs: generate-spec |
| 50 | + uses: ./.github/workflows/required-spec-validations.yml |
| 51 | + secrets: |
| 52 | + api_bot_pat: ${{ secrets.api_bot_pat }} |
| 53 | + with: |
| 54 | + spectral_version: ${{ inputs.spectral_version }} |
| 55 | + env: ${{ inputs.env }} |
| 56 | + |
| 57 | + # Optional validations won't stop the release but only open a GH issue if they fail |
| 58 | + run-optional-validations: |
| 59 | + name: Run Optional Validations |
| 60 | + needs: generate-spec |
| 61 | + uses: ./.github/workflows/optional-spec-validations.yml |
| 62 | + secrets: |
| 63 | + api_bot_pat: ${{ secrets.api_bot_pat }} |
| 64 | + with: |
| 65 | + env: ${{ inputs.env }} |
| 66 | + spectral_version: ${{ vars.SPECTRAL_VERSION }} |
| 67 | + |
| 68 | + release: |
| 69 | + name: Release OpenAPI Spec |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: [run-required-validations] |
| 72 | + steps: |
| 73 | + - name: Checkout repository |
| 74 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 |
| 75 | + with: |
| 76 | + ref: ${{ inputs.env }} |
| 77 | + - name: Download openapi-foas |
| 78 | + uses: actions/download-artifact@v4 |
| 79 | + with: |
| 80 | + name: openapi-foas-${{ inputs.env }} |
| 81 | + github-token: ${{ secrets.api_bot_pat }} |
| 82 | + run-id: ${{ github.run_id }} |
| 83 | + - name: Install FOASCLI |
| 84 | + run: | |
| 85 | + 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 |
| 86 | + tar -xzvf foascli.tar.gz |
| 87 | + pushd mongodb-foas-cli_* |
| 88 | + echo "$(pwd)/bin" >> "${GITHUB_PATH}" |
| 89 | + popd |
| 90 | + - name: Run foascli split command |
| 91 | + env: |
| 92 | + target_env: ${{ inputs.env }} |
| 93 | + run: | |
| 94 | + foascli split -s openapi-foas.json --env "${target_env}" -o ./openapi/v2/openapi.json |
| 95 | + cp -rf "openapi-foas.json" "./openapi/v2.json" |
| 96 | + |
| 97 | + foascli split -s openapi-foas.yaml --env "${target_env}" -o ./openapi/v2/openapi.yaml |
| 98 | + cp -rf "openapi-foas.yaml" "./openapi/v2.yaml" |
| 99 | + - name: Create Issue |
| 100 | + if: ${{ failure() }} |
| 101 | + uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd |
| 102 | + env: |
| 103 | + target_env: ${{ inputs.env }} |
| 104 | + with: |
| 105 | + labels: failed-release |
| 106 | + title: "(${{env.target_env}}) Release: `foascli split` command failed :scream_cat:" |
| 107 | + body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 108 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + - name: Commit changes |
| 110 | + uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 |
| 111 | + env: |
| 112 | + target_env: ${{ inputs.env }} |
| 113 | + with: |
| 114 | + commit_message: "(${{env.target_env}}) Release OpenAPI Spec :rocket:" |
| 115 | + commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>" |
| 116 | + branch: ${{env.target_env}} |
| 117 | + file_pattern: "openapi/*" |
| 118 | + - name: Create Issue |
| 119 | + if: ${{ failure() }} |
| 120 | + uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd |
| 121 | + env: |
| 122 | + target_env: ${{ inputs.env }} |
| 123 | + with: |
| 124 | + labels: failed-release |
| 125 | + title: "(${{env.target_env}}) Release: the Commit Changes step failed :scream_cat:" |
| 126 | + body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 127 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments