简体   繁体   中英

Github actions: read branch changes on workflow_run

I have two workflows: CI (for continuous integration) and CD (for continuous delivery). My goal is if someone makes a changes to branches other than master branches, I want to execute CD as well on that branch

But its taking ref as master in CD

ci.yaml

name: CI

on:
  push:
    branches:
      - master
      - test
  pull_request:
    types: [opened, synchronize, ready_for_review]
    branches:
      - master

cd.yaml

name: CD

on:
  workflow_run:
    workflows: ["CI"]
    types: 
      - completed

jobs:
  deployment:
    name: CD
    runs-on: ubuntu-latest  
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.ref }}  

When I make changes to test branch, CD is not picking up the changes in test branch, instead working with defaul master config. How to make workflow_run to pick up branch changes

If I correctly understood what you are looking for, ie having the name of the original branch whose CI workflow triggered CD, changing

github.ref

with:

github.event.workflow_run.head_branch

will solve the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM