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?
Related
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.
How would I check for a label added on a pull request when I merge to main branch from a pull request.
I tried using the below but didn't work:
name: Publish
on:
push:
branches:
- main
jobs:
Publish:
runs-on: ubuntu-latest
steps:
if: ${{github.event.label.name == 'release'}}
.......
How about like this?
name: Create Release
on:
pull_request:
branches:
- main
types:
- closed
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') # detect when pull request is merged since there's no merged event.
steps:
- name: Create release
...
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.
Workflow that call reusable one:
name: Build only workflow
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: ./.github/workflows/build_job
with:
TARGET: lol
secrets: inherit
./.github/workflows/build_job folder contain action.yml file:
name: Build job
on:
workflow_call:
inputs:
TARGET:
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: webfactory/ssh-agent#v0.5.4
with:
ssh-private-key: ${{secrets.SSH_KEY}}
- run: echo "hello"
Error: The workflow is not valid. .github/workflows/build_workflow.yml (Line: 16, Col: 9): Unexpected value 'secrets'
You're including the reusable workflow as a step, but a reusable workflow is an entire job not just a step.
Therefore, what you need is:
jobs:
my-job:
uses: ./.github/workflows/my-reusable-workflow.yaml
And then, since you can't do the checkout from outside anymore, you're going to have to add the checkout to your reusable workflow.
Also see this other answer of mine on the distinction between composite actions and reusable workflows.
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