Skip to content

Commit 1118fdc

Browse files
CLOUDP-290416: Add workflow for releasing IPA metrics (#386)
1 parent 1fd23d2 commit 1118fdc

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: IPA Validation Metrics Release
2+
on:
3+
workflow_call:
4+
secrets: # all secrets are passed explicitly in this workflow
5+
# aws_access_key:
6+
# required: true
7+
# aws_secret_key:
8+
# required: true
9+
# aws_s3_bucket_prefix:
10+
# required: true
11+
api_bot_pat:
12+
required: true
13+
IPA_S3_BUCKET_DW_STAGING_USERNAME:
14+
required: true
15+
IPA_S3_BUCKET_DW_STAGING_PASSWORD:
16+
required: true
17+
IPA_S3_BUCKET_DW_STAGING_PREFIX:
18+
required: true
19+
# inputs:
20+
# env:
21+
# description: 'Environment for the FOAS to use for IPA metrics collection'
22+
# required: true
23+
# type: string
24+
workflow_dispatch:
25+
26+
permissions:
27+
issues: write
28+
29+
jobs:
30+
release-IPA-metrics:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
36+
- name: Get Previous Run Date and Status
37+
id: get_previous_status
38+
uses: actions/github-script@v7
39+
with:
40+
github-token: ${{ secrets.api_bot_pat }}
41+
script: |
42+
const script = require('tools/spectral/ipa/metrics/scripts/getShouldRunMetricsRelease.js')
43+
const shouldRunRelease = await getShouldRunMetricsRelease({github, context})
44+
return shouldRunRelease
45+
46+
- name: Skip Metric Collection Job
47+
if: ${{steps.get_previous_status.outputs.result == 'false' }}
48+
run: echo "Skipping IPA metrics release!"
49+
50+
- name: Setup Node
51+
if: ${{steps.get_previous_status.outputs.result == 'true' }}
52+
uses: actions/setup-node@v4
53+
with:
54+
node-version: '20.x'
55+
cache: 'npm'
56+
57+
- name: Install npm dependencies
58+
if: ${{steps.get_previous_status.outputs.result == 'true' }}
59+
run: npm install
60+
61+
- name: Download openapi-foas
62+
if: ${{steps.get_previous_status.outputs.result == 'true' }}
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: openapi-foas-dev # TODO: Change to passed input env
66+
github-token: ${{ secrets.api_bot_pat }}
67+
run-id: ${{ github.run_id }}
68+
69+
- name: Run Metric Collection Job
70+
if: ${{steps.get_previous_status.outputs.result == 'true' }}
71+
working-directory: ./tools/spectral/ipa/metrics/scripts
72+
run: node runMetricCollection.js ../../../../../openapi-foas.json
73+
74+
- name: Dump Metric Collection Job Data to S3
75+
if: ${{steps.get_previous_status.outputs.result == 'true' }}
76+
env:
77+
AWS_ACCESS_KEY_ID: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_USERNAME }} # TODO: Change to passed secret
78+
AWS_SECRET_ACCESS_KEY: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PASSWORD }} # TODO: Change to passed secret
79+
S3_BUCKET_PREFIX: ${{ secrets.IPA_S3_BUCKET_DW_STAGING_PREFIX }} # TODO: Change to passed secret
80+
working-directory: ./tools/spectral/ipa/metrics/scripts
81+
run: node dataDump.js ../../../../../openapi-foas.json
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Used in .github/workflows/release-IPA-metrics.yml
2+
export default async function getShouldRunMetricsRelease({ github, context }) {
3+
const response = await github.actions.listWorkflowRuns({
4+
owner: context.repo.owner,
5+
repo: context.repo.repo,
6+
workflow_id: context.workflow,
7+
per_page: 2,
8+
page: 1,
9+
});
10+
11+
if (response === undefined) {
12+
return true;
13+
}
14+
15+
const { data: runs } = response;
16+
17+
if (runs === undefined || runs.length === 0) {
18+
return true;
19+
}
20+
21+
const previousStatus = runs[1].status;
22+
23+
const lastRunDate = new Date(runs[1].created_at);
24+
const today = new Date();
25+
26+
return previousStatus === 'failure' || today.toDateString() !== lastRunDate.toDateString();
27+
}

0 commit comments

Comments
 (0)