Skip to content

Commit

Permalink
workflow_run logic used;
Browse files Browse the repository at this point in the history
  • Loading branch information
Muneeb147 committed Oct 24, 2024
1 parent 0f352fd commit 8758d92
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,3 @@ jobs:
uses: actions/checkout@v2
- name: Test Application
run: echo "Testing the application"

call_final_job:
needs: test # Ensures this job runs after the 'test' job
if: always()
uses: ./.github/workflows/dump_ci_stats.yml # Calls the reusable workflow
with:
workflow_name: "Build Job"
secrets: inherit
12 changes: 5 additions & 7 deletions .github/workflows/dump_ci_stats.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: Dum GH CI Stats

on:
workflow_call: # This allows the workflow to be reused
inputs:
workflow_name:
description: 'Name of the CI workflow that triggered this job'
required: true
type: string
workflow_run: # This allows the workflow to be reused
workflows: ['Build Job', 'Test Job']
types:
- completed

jobs:
final_job:
Expand All @@ -28,4 +26,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
run: |
node source/dump-ci-stats-to-gcp-logs.js "${{ inputs.workflow_name }}"
node source/dump-ci-stats-to-gcp-logs.js ${{ github.event.workflow_run.id }}
10 changes: 1 addition & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,4 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v2
- name: Test Application
run: echo "Testing the application"

call_final_job:
needs: test # Ensures this job runs after the 'test' job
if: always()
uses: ./.github/workflows/dump_ci_stats.yml # Calls the reusable workflow
with:
workflow_name: "Test Job"
secrets: inherit
run: echo "Testing the application"
5 changes: 1 addition & 4 deletions source/dump-ci-stats-to-gcp-logs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

// Capture input parameter (e.g., "Test Job")
const jobName = process.argv[2];

// GitHub Actions environment variables
const githubToken = process.env.GITHUB_TOKEN; // GitHub token for API access
const repo = process.env.GITHUB_REPOSITORY; // The repository (owner/repo)
const runId = process.env.GITHUB_RUN_ID; // Run ID for this particular workflow execution
const runId = process.argv[2]; // Run ID for this particular workflow execution

// API endpoint to get the workflow run details and jobs
const workflowUrl = `https://api.github.com/repos/${repo}/actions/runs/${runId}`;
Expand Down

0 comments on commit 8758d92

Please sign in to comment.