Skip to content

Commit f3d39a9

Browse files
committed
Implement a Github Action Workflow Log Processor Workflow
1 parent 96173b1 commit f3d39a9

File tree

2 files changed

+36
-42
lines changed

2 files changed

+36
-42
lines changed

.github/workflows/fetch_and_log.yaml

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fetch-workflows:
1010
runs-on: ubuntu-latest
1111
outputs:
12-
workflow_ids: ${{ steps.fetch-ids.outputs.workflow_ids }}
12+
workflow_ids: ${{ steps.fetch-unprocessed-run-ids.outputs.workflow_ids }}
1313

1414
steps:
1515
- name: Get Last Processed Run ID
@@ -24,54 +24,48 @@ jobs:
2424
- name: Fetch Unprocessed Workflow Runs
2525
id: fetch-unprocessed-run-ids
2626
run: |
27-
HOURS=1
28-
# WORKFLOW_IDS=$(gh run list --repo $GITHUB_REPOSITORY --limit 100 --json databaseId,status,createdAt --jq '[.[] | select(.createdAt > (now - (1 * 3600))) | .databaseId] | @json')
29-
# LAST_RUN_ID=$(echo $WORKFLOW_IDS | jq '.[-1]')
30-
31-
WORKFLOW_IDS=$(gh run list --repo $GITHUB_REPOSITORY --limit 100 --json databaseId,createdAt --jq "[.[] | select(.databaseId > $LAST_PROCESSED_RUN_ID) | .databaseId] | @json")
32-
LAST_RUN_ID=$(echo $WORKFLOW_IDS | jq '.[-1]') # Store the highest run ID
33-
34-
echo "LAST_RUN_ID=$LAST_RUN_ID" >> $GITHUB_ENV
27+
# TODO: We need to address an important issue where workflow runs that are currently in progress may be included.
28+
# These should be excluded from processing, and we should revisit them in the next run once they have finished.
29+
WORKFLOW_IDS=$(gh run list --repo $GITHUB_REPOSITORY --limit 100 --json databaseId,createdAt,displayTitle --jq "[.[] | select(.databaseId > $LAST_PROCESSED_RUN_ID and .displayTitle != \"Fetch and Log Workflow Runs\")] | sort_by(.databaseId) | [.[].databaseId] | @json")
30+
echo "Workflow runs to process: $WORKFLOW_IDS"
3531
echo "workflow_ids=$WORKFLOW_IDS" >> $GITHUB_OUTPUT
3632
env:
3733
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
process-workflows:
36+
needs: fetch-workflows
37+
runs-on: ubuntu-latest
38+
if: ${{ needs.fetch-workflows.outputs.workflow_ids != '[]' && needs.fetch-workflows.outputs.workflow_ids != '' }}
39+
strategy:
40+
matrix:
41+
run_id: ${{ fromJson(needs.fetch-workflows.outputs.workflow_ids || '[]') }}
42+
max-parallel: 1
43+
steps:
44+
- name: Workflow Run to Process
45+
run:
46+
echo ${{ matrix.run_id }}
47+
48+
# - name: Send Workflow Logs to Splunk
49+
# uses: ykoer/github-workflow-splunk-logger@dev
50+
# with:
51+
# github_token: ${{ secrets.GITHUB_TOKEN }}
52+
# splunk_url: ${{ vars.HEC_URL }}
53+
# splunk_token: ${{ secrets.HEC_TOKEN }}
54+
# run_id: ${{ matrix.run_id }}
3855

39-
- name: Save Last Processed Run ID
56+
- name: Save Processed Run ID
4057
if: success()
4158
run: |
42-
gh secret set LAST_PROCESSED_ID --repo $GITHUB_REPOSITORY --body "$LAST_RUN_ID"
59+
gh variable set LAST_PROCESSED_RUN_ID --repo $GITHUB_REPOSITORY --body "${{ matrix.run_id }}"
4360
env:
4461
GH_TOKEN: ${{ secrets.GH_PAT }}
45-
46-
process-logs:
62+
63+
64+
# Add a fallback job that runs when there are no workflow Run's to process
65+
process-workflows-empty:
4766
needs: fetch-workflows
4867
runs-on: ubuntu-latest
49-
# strategy:
50-
# matrix:
51-
# run_id: ${{ fromJson(needs.fetch-workflows.outputs.workflow_ids || '[]') }}
68+
if: ${{ needs.fetch-workflows.outputs.workflow_ids == '[]' || needs.fetch-workflows.outputs.workflow_ids == '' }}
5269
steps:
53-
# - run:
54-
# echo ${{ matrix.run_id }}
55-
- run: |
56-
echo "processing logs...."
57-
echo "-----------------"
58-
echo ${{ needs.fetch-workflows.outputs.workflow_ids }}
59-
echo "-----------------"
60-
echo ${{ fromJson(needs.fetch-workflows.outputs.workflow_ids || '[]') }}
61-
echo "-----------------"
62-
63-
# process-logs:
64-
# needs: fetch-workflows
65-
# runs-on: ubuntu-latest
66-
# strategy:
67-
# matrix:
68-
# run_id: ${{ fromJson(needs.fetch-workflows.outputs.workflow_ids) }}
69-
70-
# steps:
71-
# - name: Send Workflow Logs to Splunk
72-
# uses: ykoer/github-workflow-splunk-logger@dev
73-
# with:
74-
# github_token: ${{ secrets.GITHUB_TOKEN }}
75-
# splunk_url: ${{ vars.HEC_URL }}
76-
# splunk_token: ${{ secrets.HEC_TOKEN }}
77-
# run_id: ${{ matrix.run_id }}
70+
- name: No workflows to process
71+
run: echo "No new workflow runs to process"

.github/workflows/log_to_splunk.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ jobs:
1515
github_token: ${{ secrets.GITHUB_TOKEN }}
1616
splunk_url: ${{ vars.HEC_URL }}
1717
splunk_token: ${{ secrets.HEC_TOKEN }}
18-
run_id: 13309230902
18+
run_id: 13593560361
1919

0 commit comments

Comments
 (0)