My repo has multiple branches that all accept pull requests. I want to be able to see which branch got changes merged to it after a PR is merged and then do some stuff accordingly. Is there a way in my GH Actions yaml file to see which branch got changes merged to it?
I'm thinking something like this but unsure:
jobs: build: runs-on: ubuntu-latest steps: # Fetch all branches - uses: actions/checkout@v2 - run: | git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* .
<do some stuff>
- name: Publish commits to gh-pages
if: github.ref == 'refs/remotes/origin/development/v2.2' && github.event.pull_request.merged
run: do something
I'm not sure if I can use github.ref for this or if I can string together if expressions. If not, should I be nesting them?
Thanks in advance!
There are several properties of github context you need to know:
So, if you want to see the source branch where the commits merged from, call github.head_ref in the workflow. And if you want to see the target branch where the commits merged into, call github.base_ref in the workflow.
More details you can reference here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-express...