Calculate and Index Workflow Failure Rates #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Calculate and Index Workflow Failure Rates | |
on: | |
schedule: | |
- cron: "30 * * * *" | |
workflow_dispatch: | |
inputs: | |
name: | |
required: true | |
type: string | |
repository: | |
required: true | |
type: string | |
default: "cilium/cilium" | |
branch: | |
required: true | |
type: string | |
default: main | |
events: | |
required: false | |
type: string | |
default: push | |
env: | |
SOURCE_INDEX: runs-oss | |
TARGET_INDEX: rates-oss | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
setup-matrix: | |
runs-on: ubuntu-22.04 | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- if: ${{ github.event_name == 'workflow_dispatch' }} | |
name: Prepare workflow_dispatch inputs | |
env: | |
INPUTS_JSON: ${{ toJSON(inputs) }} | |
run: | | |
echo $INPUTS_JSON | jq -c '{ "include": [.] }' > /tmp/matrix.json | |
- if: ${{ github.event_name == 'schedule' }} | |
name: Clone scheduled inputs | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
.github/scheduled.json | |
- if: ${{ github.event_name == 'schedule' }} | |
name: Prepare scheduled inputs | |
run: | | |
cat .github/scheduled.json | jq -c . > /tmp/matrix.json | |
- if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} | |
run: | | |
exit 1 | |
- id: set-matrix | |
run: | | |
cat /tmp/matrix.json | |
echo "matrix=$(cat /tmp/matrix.json)" >> $GITHUB_OUTPUT | |
calculate-and-index: | |
needs: setup-matrix | |
strategy: | |
# GitHub API doesn't like concurrent requests. | |
# Additionally, since our token is limited in the | |
# number of requests we can make, just do one | |
# repository at a time. If it takes longer that's ok | |
# since it reduces the chance we run into a limit. | |
max-parallel: 1 | |
# Scrape jobs are independent, therefore one job's failure | |
# shouldn't impact another's. | |
fail-fast: false | |
matrix: ${{ fromJSON(needs.setup-matrix.outputs.matrix) }} | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Echo Matrix | |
run: | | |
echo '${{ toJSON(matrix) }}' | |
- name: Pull failure rates | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OPENSEARCH_USER: ${{ secrets.OPENSEARCH_USER }} | |
OPENSEARCH_PASS: ${{ secrets.OPENSEARCH_PASS }} | |
OPENSEARCH_URL: ${{ secrets.OPENSEARCH_URL }} | |
run: | | |
touch ./results.json | |
until=$(date '+%Y-%m-%d') | |
for n in 1 3 7; do | |
since=$(date -d '-'$n' days' '+%Y-%m-%d') | |
go run . failure-rate \ | |
--repository ${{ matrix.repository }} \ | |
--branch ${{ matrix.branch }} \ | |
--until $until \ | |
--since $since \ | |
--events ${{ matrix.events }} \ | |
--runs-index ${{ env.SOURCE_INDEX }} \ | |
--index ${{ env.TARGET_INDEX }} \ | |
--types workflow_run,job_run,step_run \ | |
--verbose >> ./results.json | |
done | |
- name: Export to OpenSearch | |
uses: ./.github/actions/index | |
with: | |
artifact-name: ${{ matrix.name }} | |
bulk-file: ./results.json | |
temp-dir: /tmp | |
opensearch-url: ${{ secrets.OPENSEARCH_URL }} | |
opensearch-user: ${{ secrets.OPENSEARCH_USER }} | |
opensearch-pass: ${{ secrets.OPENSEARCH_PASS }} |