From 8eb4be9be205730ac2a6a50cd63e0f0d0fbdec94 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Feb 2025 16:07:44 +0000 Subject: [PATCH 1/9] CLOUDP-298521: Decouple IPA Metrics Collection Job from FOAS Release GH Workflow --- .github/workflows/release-IPA-metrics.yml | 75 ++++++++--------------- .github/workflows/release-spec-runner.yml | 3 - .github/workflows/release-spec.yml | 15 +---- 3 files changed, 26 insertions(+), 67 deletions(-) diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index 6f504fd8b3..cb208c2877 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -2,56 +2,20 @@ # (number of adoptions, violations and exceptions) and upload the data to an S3 bucket. name: IPA Validation Metrics Release on: - workflow_call: - secrets: # all secrets are passed explicitly in this workflow - aws_access_key: - required: true - aws_secret_key: - required: true - aws_s3_bucket_prefix: - required: true - api_bot_pat: - required: true - inputs: - env: - description: 'Environment for the FOAS to use for IPA metrics collection' - required: true - type: string + schedule: + - cron: '0 22 * * *' # Runs daily at 22:00 UTC (10 PM UTC) workflow_dispatch: - permissions: issues: write +env: + NODE_VERSION: '20.x' + WORKING_DIR: ./tools/spectral/ipa/metrics/scripts + RELEASE_ENV: 'dev' jobs: - # Checks the last workflow run, and decides whether the IPA release metrics should be uploaded or - # skipped. The release-IPA-metrics job only runs if the last release was not today and did not fail. - pre-IPA-metrics-release-checks: - name: IPA Metrics Release Pre-Checks - runs-on: ubuntu-latest - outputs: - should_run_release: ${{ steps.get_previous_status.outputs.result }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Get Previous Run Date and Status - id: get_previous_status - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.api_bot_pat }} - script: | - const { default: getShouldRunMetricsRelease } = await import('${{ github.workspace }}/tools/spectral/ipa/metrics/scripts/getShouldRunMetricsRelease.js') - const shouldRunRelease = await getShouldRunMetricsRelease({github, context}).catch((error) => { - console.error(error.message); - process.exit(1) - }) - return shouldRunRelease - # Generates and uploads the IPA validation metrics to S3 release-IPA-metrics: name: Release IPA Validation Metrics - needs: [pre-IPA-metrics-release-checks] - if: ${{ needs.pre-IPA-metrics-release-checks.outputs.should_run_release == 'true' }} runs-on: ubuntu-latest steps: - name: Checkout @@ -60,7 +24,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: ${{ env.NODE_VERSION }} cache: 'npm' - name: Install npm dependencies @@ -69,18 +33,29 @@ jobs: - name: Download openapi-foas uses: actions/download-artifact@v4 with: - name: openapi-foas-${{ inputs.env }} - github-token: ${{ secrets.api_bot_pat }} + name: openapi-foas-${{ env.RELEASE_ENV }} + github-token: ${{ secrets.API_BOT_PAT }} run-id: ${{ github.run_id }} - name: Run Metric Collection Job - working-directory: ./tools/spectral/ipa/metrics/scripts + working-directory: ${{ env.WORKING_DIR }} run: node runMetricCollection.js ../../../../../openapi-foas.json - name: Dump Metric Collection Job Data to S3 env: - AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_key }} - S3_BUCKET_PREFIX: ${{ secrets.aws_s3_bucket_prefix }} - working-directory: ./tools/spectral/ipa/metrics/scripts + AWS_ACCESS_KEY_ID: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_USERNAME }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PASSWORD }} + S3_BUCKET_PREFIX: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PREFIX }} + working-directory: ${{ env.WORKING_DIR }} run: node dataDump.js + + failure-handler: + name: Failure Handler + needs: [ release-IPA-metrics ] + if: ${{ always() && contains(needs.*.result, 'failure') }} + uses: ./.github/workflows/failure-handler.yml + with: + env: ${{ env.RELEASE_ENV }} + release_name: "OpenAPI Spec" + secrets: + jira_api_token: ${{ secrets.JIRA_API_TOKEN }} diff --git a/.github/workflows/release-spec-runner.yml b/.github/workflows/release-spec-runner.yml index 0cb8487447..2079235da1 100644 --- a/.github/workflows/release-spec-runner.yml +++ b/.github/workflows/release-spec-runner.yml @@ -52,9 +52,6 @@ jobs: secrets: api_bot_pat: ${{ secrets.API_BOT_PAT }} jira_api_token: ${{ secrets.JIRA_API_TOKEN }} - ipa_aws_access_key: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_USERNAME}} - ipa_aws_secret_key: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PASSWORD}} - ipa_aws_s3_bucket_prefix: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PREFIX}} with: aws_default_region: ${{ vars.AWS_DEFAULT_REGION}} aws_s3_bucket: ${{ vars.S3_BUCKET_DEV}} diff --git a/.github/workflows/release-spec.yml b/.github/workflows/release-spec.yml index 8ad23058b6..176bbfbde0 100644 --- a/.github/workflows/release-spec.yml +++ b/.github/workflows/release-spec.yml @@ -184,22 +184,9 @@ jobs: branch: ${{ inputs.branch }} foascli_version: ${{ inputs.foascli_version }} - release-IPA-metrics: - name: Release IPA Validation Metrics - needs: release - if: ${{ inputs.env == 'dev' && needs.release.outputs.changes_detected == 'true' }} - uses: ./.github/workflows/release-IPA-metrics.yml - secrets: - aws_access_key: ${{ secrets.ipa_aws_access_key}} - aws_secret_key: ${{ secrets.ipa_aws_secret_key}} - aws_s3_bucket_prefix: ${{ secrets.ipa_aws_s3_bucket_prefix}} - api_bot_pat: ${{ secrets.api_bot_pat }} - with: - env: ${{ inputs.env }} - failure-handler: name: Failure Handler - needs: [ release, release-postman, release-changelog, release-IPA-metrics ] + needs: [ release, release-postman, release-changelog] if: ${{ always() && contains(needs.*.result, 'failure') }} uses: ./.github/workflows/failure-handler.yml with: From 8dc35052f7010393405b757b8ce02af82b5b061c Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Feb 2025 16:45:54 +0000 Subject: [PATCH 2/9] fix gh lint --- .github/workflows/release-IPA-metrics.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index cb208c2877..b9603a34ac 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -24,7 +24,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: ${{ env.NODE_VERSION }} + node-version: $NODE_VERSION cache: 'npm' - name: Install npm dependencies @@ -33,12 +33,11 @@ jobs: - name: Download openapi-foas uses: actions/download-artifact@v4 with: - name: openapi-foas-${{ env.RELEASE_ENV }} + name: openapi-foas-$RELEASE_ENV github-token: ${{ secrets.API_BOT_PAT }} - run-id: ${{ github.run_id }} - name: Run Metric Collection Job - working-directory: ${{ env.WORKING_DIR }} + working-directory: $WORKING_DIR run: node runMetricCollection.js ../../../../../openapi-foas.json - name: Dump Metric Collection Job Data to S3 @@ -46,16 +45,16 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_USERNAME }} AWS_SECRET_ACCESS_KEY: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PASSWORD }} S3_BUCKET_PREFIX: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PREFIX }} - working-directory: ${{ env.WORKING_DIR }} + working-directory: $WORKING_DIR run: node dataDump.js failure-handler: name: Failure Handler needs: [ release-IPA-metrics ] - if: ${{ always() && contains(needs.*.result, 'failure') }} + if: ${{ failure() }} uses: ./.github/workflows/failure-handler.yml with: - env: ${{ env.RELEASE_ENV }} + env: $RELEASE_ENV release_name: "OpenAPI Spec" secrets: jira_api_token: ${{ secrets.JIRA_API_TOKEN }} From e0f30dba69202dfa3136f0b1ce5b36e1291a9204 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Tue, 4 Feb 2025 17:30:15 +0000 Subject: [PATCH 3/9] address the comments --- .github/workflows/release-IPA-metrics.yml | 26 +++++++++++++++--- .../scripts/getShouldRunMetricsRelease.js | 27 ------------------- 2 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 tools/spectral/ipa/metrics/scripts/getShouldRunMetricsRelease.js diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index b9603a34ac..0ac63640cd 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -10,7 +10,8 @@ permissions: env: NODE_VERSION: '20.x' WORKING_DIR: ./tools/spectral/ipa/metrics/scripts - RELEASE_ENV: 'dev' + OAS_ENV: 'dev' + OAS_BRANCH: 'main' jobs: # Generates and uploads the IPA validation metrics to S3 @@ -30,10 +31,27 @@ jobs: - name: Install npm dependencies run: npm install + - name: Checkout repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + with: + ref: $OAS_BRANCH + token: ${{secrets.API_BOT_PAT}} + + - name: Upload current Specs and Changelog files + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 + with: + name: base-$OAS_ENV + retention-days: 1 + path: | + openapi/v2/openapi*.json + changelog/changelog.json + changelog/internal/changelog-all.json + changelog/internal/metadata.json + - name: Download openapi-foas uses: actions/download-artifact@v4 with: - name: openapi-foas-$RELEASE_ENV + name: openapi-foas-$OAS_ENV github-token: ${{ secrets.API_BOT_PAT }} - name: Run Metric Collection Job @@ -54,7 +72,7 @@ jobs: if: ${{ failure() }} uses: ./.github/workflows/failure-handler.yml with: - env: $RELEASE_ENV - release_name: "OpenAPI Spec" + env: $OAS_ENV + release_name: "IPA Metrics" secrets: jira_api_token: ${{ secrets.JIRA_API_TOKEN }} diff --git a/tools/spectral/ipa/metrics/scripts/getShouldRunMetricsRelease.js b/tools/spectral/ipa/metrics/scripts/getShouldRunMetricsRelease.js deleted file mode 100644 index 13e3cc3083..0000000000 --- a/tools/spectral/ipa/metrics/scripts/getShouldRunMetricsRelease.js +++ /dev/null @@ -1,27 +0,0 @@ -// Used in .github/workflows/release-IPA-metrics.yml -export default async function getShouldRunMetricsRelease({ github, context }) { - const response = await github.rest.actions.listWorkflowRuns({ - owner: context.repo.owner, - repo: context.repo.repo, - workflow_id: 'release-IPA-metrics.yml', - per_page: 2, - page: 1, - }); - - if (!response || !response.data) { - throw Error('listWorkFlowRuns response is empty'); - } - - const { workflow_runs: runs } = response.data; - - if (runs === undefined || runs.length === 0) { - throw Error('response.data.workflow_runs is empty'); - } - - const previousResult = runs[1].conclusion; - - const lastRunDate = new Date(runs[1].created_at); - const today = new Date(); - - return previousResult === 'failure' || today.toDateString() !== lastRunDate.toDateString(); -} From 7b96f33a7b19d0533230987fbf58e2cfc4f3f371 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 5 Feb 2025 11:26:04 +0000 Subject: [PATCH 4/9] address the comments --- .github/workflows/release-IPA-metrics.yml | 43 ++++++++--------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index 0ac63640cd..da19c9d29c 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -3,7 +3,7 @@ name: IPA Validation Metrics Release on: schedule: - - cron: '0 22 * * *' # Runs daily at 22:00 UTC (10 PM UTC) + - cron: '0 11 * * *' # Runs daily at 11:00 UTC (11 AM UTC) workflow_dispatch: permissions: issues: write @@ -11,7 +11,8 @@ env: NODE_VERSION: '20.x' WORKING_DIR: ./tools/spectral/ipa/metrics/scripts OAS_ENV: 'dev' - OAS_BRANCH: 'main' + OAS_BRANCH: 'dev' + OAS_FILE: 'openapi/v2.json' jobs: # Generates and uploads the IPA validation metrics to S3 @@ -19,8 +20,17 @@ jobs: name: Release IPA Validation Metrics runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Checkout repository (scripts) + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + with: + sparse-checkout: + tools/spectral/ipa + + - name: Checkout repository (dev branch) + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + with: + ref: $OAS_BRANCH + sparse-checkout: $OAS_FILE - name: Setup Node uses: actions/setup-node@v4 @@ -31,32 +41,9 @@ jobs: - name: Install npm dependencies run: npm install - - name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - with: - ref: $OAS_BRANCH - token: ${{secrets.API_BOT_PAT}} - - - name: Upload current Specs and Changelog files - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 - with: - name: base-$OAS_ENV - retention-days: 1 - path: | - openapi/v2/openapi*.json - changelog/changelog.json - changelog/internal/changelog-all.json - changelog/internal/metadata.json - - - name: Download openapi-foas - uses: actions/download-artifact@v4 - with: - name: openapi-foas-$OAS_ENV - github-token: ${{ secrets.API_BOT_PAT }} - - name: Run Metric Collection Job working-directory: $WORKING_DIR - run: node runMetricCollection.js ../../../../../openapi-foas.json + run: node runMetricCollection.js ../../../../../openapi/v2.json - name: Dump Metric Collection Job Data to S3 env: From d62d16d970aa65cdb5afde614915a8462db2ac0b Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 5 Feb 2025 11:42:50 +0000 Subject: [PATCH 5/9] address the comments --- .github/workflows/release-IPA-metrics.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index da19c9d29c..aadbda2dec 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -9,10 +9,11 @@ permissions: issues: write env: NODE_VERSION: '20.x' - WORKING_DIR: ./tools/spectral/ipa/metrics/scripts OAS_ENV: 'dev' OAS_BRANCH: 'dev' OAS_FILE: 'openapi/v2.json' + SCRIPTS_PATH: ${{ github.workspace }}/scripts + DEV_OAS_PATH: ${{ github.workspace }}/dev-oas jobs: # Generates and uploads the IPA validation metrics to S3 @@ -24,13 +25,15 @@ jobs: uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 with: sparse-checkout: - tools/spectral/ipa + tools/spectral/ipa/metrics/scripts + path: scripts - name: Checkout repository (dev branch) uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 with: ref: $OAS_BRANCH sparse-checkout: $OAS_FILE + path: dev-oas - name: Setup Node uses: actions/setup-node@v4 @@ -42,15 +45,15 @@ jobs: run: npm install - name: Run Metric Collection Job - working-directory: $WORKING_DIR - run: node runMetricCollection.js ../../../../../openapi/v2.json + working-directory: $SCRIPTS_PATH + run: node runMetricCollection.js $DEV_OAS_PATH/openapi/v2.json - name: Dump Metric Collection Job Data to S3 env: AWS_ACCESS_KEY_ID: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_USERNAME }} AWS_SECRET_ACCESS_KEY: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PASSWORD }} S3_BUCKET_PREFIX: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PREFIX }} - working-directory: $WORKING_DIR + working-directory: $SCRIPTS_PATH run: node dataDump.js failure-handler: From 902f3f3ebfaa536d82f68cb939c76e05996aa178 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 5 Feb 2025 11:49:59 +0000 Subject: [PATCH 6/9] address the comments --- .github/workflows/release-IPA-metrics.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index aadbda2dec..06499a76d7 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -12,7 +12,7 @@ env: OAS_ENV: 'dev' OAS_BRANCH: 'dev' OAS_FILE: 'openapi/v2.json' - SCRIPTS_PATH: ${{ github.workspace }}/scripts + IPA_PATH: ${{ github.workspace }}/ipa DEV_OAS_PATH: ${{ github.workspace }}/dev-oas jobs: @@ -25,8 +25,8 @@ jobs: uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 with: sparse-checkout: - tools/spectral/ipa/metrics/scripts - path: scripts + tools/spectral/ipa + path: ipa - name: Checkout repository (dev branch) uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 @@ -35,6 +35,11 @@ jobs: sparse-checkout: $OAS_FILE path: dev-oas + - name: Validate paths + run: | + ls -la $SCRIPTS_PATH + ls -la $DEV_OAS_PATH/openapi/v2.json + - name: Setup Node uses: actions/setup-node@v4 with: @@ -45,7 +50,7 @@ jobs: run: npm install - name: Run Metric Collection Job - working-directory: $SCRIPTS_PATH + working-directory: $IPA_PATH/metrics/scripts run: node runMetricCollection.js $DEV_OAS_PATH/openapi/v2.json - name: Dump Metric Collection Job Data to S3 @@ -53,7 +58,7 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_USERNAME }} AWS_SECRET_ACCESS_KEY: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PASSWORD }} S3_BUCKET_PREFIX: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PREFIX }} - working-directory: $SCRIPTS_PATH + working-directory: $IPA_PATH/metrics/scripts run: node dataDump.js failure-handler: From ef5446f86be7876abd38da9e9094de45c1244755 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 5 Feb 2025 11:53:26 +0000 Subject: [PATCH 7/9] address the comments --- .github/workflows/release-IPA-metrics.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index 06499a76d7..145e2926a1 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -37,8 +37,10 @@ jobs: - name: Validate paths run: | - ls -la $SCRIPTS_PATH - ls -la $DEV_OAS_PATH/openapi/v2.json + if [ ! -f "dev-oas/$OAS_FILE" ]; then + echo "::error::OAS file not found in $OAS_BRANCH branch" + exit 1 + fi - name: Setup Node uses: actions/setup-node@v4 From a14c9cace5f2a006c32c061a03290874dd9cbc89 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 5 Feb 2025 11:56:23 +0000 Subject: [PATCH 8/9] address the comments --- .github/workflows/release-IPA-metrics.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index 145e2926a1..7bc14edb92 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -35,7 +35,7 @@ jobs: sparse-checkout: $OAS_FILE path: dev-oas - - name: Validate paths + - name: Validate OAS file run: | if [ ! -f "dev-oas/$OAS_FILE" ]; then echo "::error::OAS file not found in $OAS_BRANCH branch" @@ -53,7 +53,7 @@ jobs: - name: Run Metric Collection Job working-directory: $IPA_PATH/metrics/scripts - run: node runMetricCollection.js $DEV_OAS_PATH/openapi/v2.json + run: node runMetricCollection.js "$DEV_OAS_PATH/openapi/v2.json" - name: Dump Metric Collection Job Data to S3 env: From 6ac05392ec2aa42ffac6c205ad6b8514a31ad806 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 5 Feb 2025 13:34:52 +0000 Subject: [PATCH 9/9] address the comments --- .github/workflows/release-IPA-metrics.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/release-IPA-metrics.yml b/.github/workflows/release-IPA-metrics.yml index 7bc14edb92..75a4279675 100644 --- a/.github/workflows/release-IPA-metrics.yml +++ b/.github/workflows/release-IPA-metrics.yml @@ -9,7 +9,6 @@ permissions: issues: write env: NODE_VERSION: '20.x' - OAS_ENV: 'dev' OAS_BRANCH: 'dev' OAS_FILE: 'openapi/v2.json' IPA_PATH: ${{ github.workspace }}/ipa @@ -69,7 +68,7 @@ jobs: if: ${{ failure() }} uses: ./.github/workflows/failure-handler.yml with: - env: $OAS_ENV + env: $OAS_BRANCH release_name: "IPA Metrics" secrets: jira_api_token: ${{ secrets.JIRA_API_TOKEN }}