workflow_run only on push - github

I have the following workflow:
name: ci
on:
push:
branches: [main, develop]
pull_request:
jobs:
....
name: deploy
on:
release:
types: [released]
workflow_run:
workflows: ["ci"]
branches: [develop]
types: [completed]
The problem I have is that when I create a PR from the develop to the main branch it also runs the deploy workflow. Is there any way to prevent this? and just run the deploy workflow on push after the CI finishes?
Thanks

Related

Github action runs on pr unexpectedly

I have this deveopment.yml in .github/workflows:
name: Development
on:
push:
branches:
- dev
paths-ignore:
- '**.md'
jobs:
test:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout#v2
- name: "Test Suite"
uses: ./.github/actions/test_suite
lint:
[...lint stuff]
db_migrate:
[...db migrate stuff]
[etc]
[etc]
I would expect this workflow to only fire when I push to the branch named dev
I also have a pull_request.yml workflow. It's similar:
on:
pull_request:
branches:
- '*'
paths-ignore:
- '**.md'
jobs:
test:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout#v2
- name: "Test Suite"
uses: ./.github/actions/test_suite
lint:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout#v2
- name: "Lint Suite"
uses: ./.github/actions/linting
I would expect this to run on any pull request to any branch, before it merges.
So far so good. If I make a PR from a feature branch into dev, it runs test and lint. When I merge, it runs the development.yml actions like db_migrate.
My question is why when I make a PR of dev into prod, it seems to run the development.yml actions. As soon as the PR is opened, it runs db_migrate. Why is that, and how do I make it not do that?
There is a production.yml but that's set to on release, so I don't think that's relevant here
on:
release:
types: [published]
paths-ignore:
- '**.md'
I've been staring at the docs but I'm having a slow brain morning. It's a little tricky to debug this because it's tightly coupled to github and two important branches.

workflow_run is never trigged by pull_request

I have two very simple GitHub workflows for testing proposes. deploy-test-first which runs always on pull_request and deploy-test-second which should run on completion of deploy-test-first
The deploy-test-second however never runs. What Am I missing? How do I make it work?
name: deploy-test-first
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
deploy-test-first:
runs-on: ubuntu-20.04
steps:
- name: deploy-test-first
run: echo 'deploy-test-first'
name: deploy-test-second
on:
workflow_run:
workflows: [deploy-test-first]
types: [completed]
branches: [develop]
jobs:
test-deploy-second:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-20.04
steps:
- name: test-deploy-second
run: echo 'deploy-test-second'
Both workflows are suppose to run on non-default branch develop in PR.

Dependencies Between Workflows on Github Actions not working

I have two workflows and i do from this manual - https://docs.github.com/en/github-ae#latest/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_runbranchesbranches-ignore but dependent workflow not starting..
name: Tests
on:
push:
branches:
- '**' # matches every branch
- '!main' # excludes master
jobs:
setup-tests-job:
runs-on: ubuntu-latest
and dependent workflow
name: Build
on:
workflow_run:
workflows:
- 'Tests'
branches:
- '**'
types:
- completed
jobs:
setup-tests-job:
runs-on: ubuntu-latest
Maybe i do smthg wrong?

The workflow that should be executed after automatically creating a pull request is not executed

I created a workflow using the actions repo-sync/pull-request, but the workflow I already created is no longer executed.
Workflow that is executed when pull_request is created in develop and main. An example is shown below.
name: example
on:
workflow_run:
workflows: ["Create Pull Request"]
types:
- completed
pull_request:
branches:
- main
- develop
jobs:
...
The workflow using repo-sync/pull-request looks like this.
name: Create Pull Request
on:
push:
branches:
- feature/*
jobs:
create-pull-request:
name: create-pull-request
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Create Pull Request
id: open-pr
uses: repo-sync/pull-request#v2
with:
destination_branch: "develop"
pr_title: "[example] test_summary"
pr_body: "test body."
github_token: ${{ secrets.GITHUB_TOKEN }}
If you know any solution, please let me know.
I look forward to working with you : )

Run particular jobs while creating pull request in githubactions

I have implemented ci/cd using GitHub actions. In ci/cd I have three jobs are there when I want to release a tag I want to build these three jobs and when I raise a pull request to a particular branch only two jobs should be executed for health check purposes. for example, I have a feature branch I want to merge this feature branch to the devel branch. when I raise a PR should be run only two jobs. how can I achieve this? below is my sample code.
name: CI
on:
pull_request:
branches:
- master
- devel
push:
tags:
- '*'
jobs:
build:
name: build
runs-on: self-hosted
steps:
--------------
deploy:
name: deploy
runs-on: self-hosted
steps:
------------
automation-test:
name: test
runs-on: self-hosted
steps:
------------
here when I raise a PR I want to run build and automation-test jobs.
You have two options here:
Have separate workflow files that run for the right branches.
Use conditionals in your job
The first option is likely the one you want. The only problem here is if the output from one job is used in another, but it doesn't sound like that's the case for you. I would recommend you simply break out your yaml workflows into two separate workflows:
name: CI
on:
pull_request:
branches:
- master
push:
tags:
- '*'
jobs:
build:
name: build
runs-on: self-hosted
steps:
--------------
deploy:
name: deploy
runs-on: self-hosted
steps:
------------
automation-test:
name: test
runs-on: self-hosted
steps:
------------
name: PR Builder
on:
pull_request:
branches:
- devel
jobs:
whatever_testing_jobs_you_like:
The second option might look something like this:
name: CI
on:
pull_request:
branches:
- master
push:
tags:
- '*'
jobs:
build:
name: build
runs-on: self-hosted
steps:
--------------
deploy:
if: "github.ref != devel" # you might tweak the condition based on your needs
name: deploy
runs-on: self-hosted
steps:
------------
automation-test:
name: test
runs-on: self-hosted
steps:
------------
These context values / conditions are well documented