diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 259b099..2c11094 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,34 +9,16 @@ on: - main jobs: - build: + test: runs-on: ubuntu-latest steps: - name: Checkout Code uses: actions/checkout@v2 - - name: Build Application - run: echo "Building the application" - - final_job: - runs-on: ubuntu-latest - needs: - - build - steps: - - name: Checkout Code - uses: actions/checkout@v2 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '18' - - - name: Install Dependencies - run: npm install @google-cloud/logging - - - name: Final Job - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} - run: | - echo "Determining which workflow triggered the Final Job..." - node source/dump-ci-stats-to-gcp-logs.js "Build Job" \ No newline at end of file + - name: Test Application + run: echo "Testing the application" + + call_final_job: + needs: test # Ensures this job runs after the 'test' job + uses: ./.github/workflows/dump_ci_stats.yml # Calls the reusable workflow + with: + workflow_name: "Build Job" diff --git a/.github/workflows/dump_ci_stats.yml b/.github/workflows/dump_ci_stats.yml new file mode 100644 index 0000000..fb726ed --- /dev/null +++ b/.github/workflows/dump_ci_stats.yml @@ -0,0 +1,31 @@ +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 + +jobs: + final_job: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install GCP Logging Client + run: npm install @google-cloud/logging + + - name: Run Final Job and Send Logs to GCP + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} + run: | + node source/dump-ci-stats-to-gcp-logs.js "${{ inputs.workflow_name }}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5257b0e..8ab4257 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,27 +16,9 @@ jobs: uses: actions/checkout@v2 - name: Test Application run: echo "Testing the application" - - final_job: - runs-on: ubuntu-latest - needs: - - test - steps: - - name: Checkout Code - uses: actions/checkout@v2 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '18' - - - name: Install Dependencies - run: npm install @google-cloud/logging - - name: Final Job - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }} - run: | - echo "Determining which workflow triggered the Final Job..." - node source/dump-ci-stats-to-gcp-logs.js "Test Job" \ No newline at end of file + call_final_job: + needs: test # Ensures this job runs after the 'test' job + uses: ./.github/workflows/dump_ci_stats.yml # Calls the reusable workflow + with: + workflow_name: "Test Job"