Thứ Tư, 25 tháng 12, 2024

Github workflow: How to checkout the same branch on a workflow that run after another workflow complete

 I have 2 github workflows: CreateRelease and Test. The Test workflow will run after CreateRelease workflow completed. How to make sure that the Test workflow will checkout the same branch with CreateRelease workflow?

Use ${{ github.event.workflow_run.head_branch }} in checkout action in Test workflow.

Here's CreateRelease workflow:

name: CreateRelease

on:
  workflow_dispatch:

jobs:
  ManageVariables:
    environment: 'QA Automation'
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
        with:
          lfs: true

Here's Test workflow:

name: Test

on:
  workflow_run:
    workflows: ["CreateRelease"]
    types:
      - completed
  workflow_dispatch:

jobs:
  ManageVariables:
    environment: 'QA Automation'
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.workflow_run.head_branch }}
          lfs: true


Read More »