I'd like to trigger automatically a GitHub Action Workflow for each [assigned, opened, synchronize, reopened] Git Pull Request from side-branch into master.
In addition, Is there a way to checkout the code from the private repository of a PR via branch name?
Below you can find my GitHub Action workflow that I've tried but unfortunately when I open a PR from side-branch into master it didn't trigger at all.
on:
workflow_dispatch:
pull_request:
types: [assigned, opened, synchronize, reopened]
branches:
- master
jobs:
build-image:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
with:
ref: ${{github.event.pull_request.head.sha}}
Is it possible, how can I do that?
Related
Currently, my GitHub workflow looks as follows:
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on:
push:
branches:
- main
jobs:
update-x:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout#v2
with:
# fetch depth is needed since we will be taking git diff with HEAD^1
fetch-depth: 2
- name: Run script
run: scripts/x/x-version-bump.sh
Instead of using git diff in my x-version-bump.sh script I would like to get the changes of the commit pushed via a GitHub action and pass it on to the script. I cannot find a way currently in Github actions to do the same.
I would expect for each triggered GitHub action, to be able to find it and understand what triggered it.
To be concrete, we have a changelog.ymlfile:
name: Changelog Updater
on:
push:
branches:
- master
paths:
- 'pyproject.toml' # When somebody update the toml file
jobs:
build:
name: Update changelog
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v2
with:
fetch-depth: 0
- name: Generate changelog
uses: orhun/git-cliff-action#v1
with:
config: .github/workflows/cliff.toml
env:
OUTPUT: CHANGELOG.md
- name: Commit changelog
uses: stefanzweifel/git-auto-commit-action#v4
with:
commit_message: "chore(changelog): update changelog to newest version"
file_pattern: CHANGELOG.md
That should be triggered when a push on master with a change on pyproject.toml occur.
But in some PR, like https://github.com/eclipse/kiso-testing/pull/185/commits, we see that the action is triggered because github_action[bot] committed something:
But I cannot find where it is...
I would expect here to find the workflow regarding the above triggered PR but it is simply not there.
I did try to check all forks or the checks of all PRs but I do not find what triggered or the location of this specific action. Some other PRs are not impacted. It feels strange.
Currently using the Submit Pull Request where it will automatically create a pull request for the branch but I wanted to it to run only for the first time I committed a branch, how do I stop it from running in other times?
name: create-pull-request workflow
on:
push:
branches:
- '*'
- '!master'
jobs:
SubmitPullRequest:
runs-on: ubuntu-latest
steps:
- name: Submit Pul Request
uses: shimewtr/submit_pull_request#master
env:
ASSIGN: false
GITHUB_ACCESS_TOKEN: ${{secrets.github_token}}
I have a publish workflow that is supposed to push the dists to PyPi if a commit on main is tagged with either frontend-v* or backend-v* (both are separate packages)
However, if a commit has changes on both the front- and backend and I add two tags to the commit, the workflow is triggered twice.
I understand that I could simply split the workflow into two, but I have another job that should run if either frontend or backend or both were updated which should only be ran once, thus I want to keep this in one workflow.
Can I somehow circumvent this to run this only once?
Thank you very much!
on:
workflow_dispatch:
push:
branches: [ main ]
tags:
- frontend*
- backend*
jobs:
backend:
name: Publish backend
if: ${{contains(github.ref_name, 'backend') }}
runs-on: ubuntu-latest
steps:
...
frontend:
name: Publish frontend
if: ${{contains(github.ref_name, 'frontend') }}
runs-on: ubuntu-latest
steps:
...
housekeeping: # this should only be ran once for the commit
name: House Keeping
runs-on: ubuntu-latest
steps:
...
name: blabla bacon n eggs
on:
pull_request:
branches:
- basickarl/gh-actions-pr
defaults:
run:
shell: bash
jobs:
somting:
runs-on: ubuntu-latest
steps:
- run: echo "testy"
I have pushed my code on the branch stated to the origin repo in github. I have created a pull request. I updated some code on the branch and pushed, but the actions is not triggering? How does one trigger a github action workflow when updating a pull request?
The updates to the branch I am making is the workflow file itself.
Here is an example repo: https://github.com/basickarl/github-actions/actions/workflows/test.yaml
For some reason only on: [pull_request] seems to work.
Use types: [synchronize] under on: pull-request: