How to run a github action step if it has a label - github

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
...

Related

How to trigger a github workflow job only for specific branch using patterns

I would like to trigger a github action wf for a specific branch.
My branch has the name
refs/heads/release/rc22-15.0.0
I would like to trigger the wf or a specific step for all releases refs/heads/release/**
The execution of the wf triggers both steps.
name: wf_logic_test_releasebranch
on:
workflow_dispatch:
push:
branches:
- 'release/**'
- 'feature/**'
- 'main'
jobs:
test_condition:
name: job_test_condition
runs-on: [atc-ubuntu-20.04]
environment: sandbox
steps:
- name: Branch name
if: github.ref == 'refs/heads/release/rc22-15.0.0'
run: echo running on branch ${GITHUB_REF##*/}
- run: echo ${{github.ref}}
By changing the code to:
name: wf_logic_test_releasebranch
on:
workflow_dispatch:
push:
branches:
- 'release/**'
- 'feature/**'
- 'main'
jobs:
test_condition:
name: job_test_condition
runs-on: [atc-ubuntu-20.04]
environment: sandbox
steps:
- name: Branch name
if: github.ref == 'refs/heads/release/**'
run: echo running on branch ${GITHUB_REF##*/}
- run: echo ${{github.ref}}
The execution of the above wf triggers only the second step.
This is what worked for me:
name: wf_logic_test_releasebranch
on:
workflow_dispatch:
push:
branches:
- 'release/**'
- 'feature/**'
- 'main'
jobs:
test_condition:
name: job_test_condition
runs-on: [atc-ubuntu-20.04]
environment: sandbox
steps:
- name: Always call branch name
run: echo running on branch ${GITHUB_REF##*/}
#WF executes step only if branch name is main
- name: Determine IP of runner only for release branch
if:
contains(github.ref, 'release')
run: curl https://api.ipify.org
- name: Show branch name for main and feature branch only
if:
contains(github.ref, 'main') || contains(github.ref, 'feature')
run: echo running on branch ${GITHUB_REF##*/}
job_only_for_main:
name: job_test_only_for_main
runs-on: [atc-ubuntu-20.04]
environment: sandbox
if:
contains(github.ref, 'main')
steps:
- name: Always call branch name
run: echo running on branch ${GITHUB_REF##*/}

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 : )

Github Action triggered by success of a different action

I am trying to trigger a Github action to run after a successful run of a different action.
the 2 workflows are:
Unit Test Action (Which runs first, and should trigger the Follow on Test action below
name: unit-tests
on:
push:
branches:
- '**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: "3.1.x"
- name: Test
run: dotnet test src/XXXXXXXXXX
Follow on Test Action (This is just a test action)
name: Test action triggered by previous action success
on:
workflow_run:
workflows:
- unit-tests
types:
- completed
jobs:
test-job:
name: Test Step
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
ref: ${{ github.event.workflow_run.head_branch }}
- run: echo "The follow on works!!"
The issue is that when this is triggered on a feature branch and not the default branch (as it should be because I want the actions to run all all branches) it doest work?
Any ideas?
As discussed in the comments:
First: It is necessary to have both workflows on the branch and to first merge the branch into your default branch, then onwards it will work.
Second: It is possible to use if: ${{ github.event.workflow_run.conclusion == 'success' }} to only run the jobs if the previous workflow was successful.
Example:
on:
workflow_run:
workflows: ["Other Workflow Name"]
types: [completed] #requested
jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- run: echo "First workflow was a success"
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo "First workflow was a failure"