I have setup Github action for python app, it's located at
.github/workflows/python-app.yml
with details as
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
...
This executes fine however, We want to block if actions fails,
I'm unable to search this status under
Status checks that are required.
It was issue of name inside build which was not there in template
jobs:
build:
name: syntax-check
runs-on: ubuntu-latest
Related
I am trying to create a GitHub action that will rebuild a dockerfile if a change is made to specific branch then pushed to main. If I remove the branch/specific the GitHub action works.
on:
push:
branches: [ main ], [ branch/specific/** ]
paths:
- '**.sh'
have also tried:
on:
push:
branches:
- main
- 'branch/specific/**'
paths:
- '**.sh'
I want to learn how to use a self-hosted github runner with labels. I installed a self-hosted github runner on a server and assigned it the label prj1. I then made a github project and included this .github/workflows/deploy.yml file.
name: Environment
on:
push:
branches:
- master
jobs:
p1:
runs-on: self-hosted
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event." >> deploy-log.txt
When I push to master branch, my self-hosted github runner says SUCCESS. This is perfect so far.
Then I changed my .github/workflows/deploy.yml to include a label like this:
name: Environment
on:
push:
types: [prj1]
branches:
- master
jobs:
p1:
runs-on: self-hosted
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event." >> deploy-log.txt
Then I pushed to master. But the github runner does not show any indication it detected anything. The github website actions says "This check was skipped". So then I tried this:
name: Environment
on:
push:
branches:
- master
jobs:
p1:
if: ${{ github.event.label.name == 'prj1' }}
runs-on: self-hosted
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event." >> deploy-log.txt
Again, when i push changes to master, the git hub runner does not show any indication it detected anything. The github website actions says "This check was skipped".
How do I get my self-hosted runner to deploy a project only on jobs with label prj1?
FOund the answer on : https://docs.github.com/en/actions/hosting-your-own-runners/using-self-hosted-runners-in-a-workflow#using-custom-labels-to-route-jobs
Basically I can use the runs-on to specify which label. SO my yml file looks liek this now
name: Environment
on:
push:
branches:
- master
jobs:
p1:
runs-on: prj1
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event." >> deploy-log.txt
This means on self-hosted github runners tagged with prj1 will run the job.
I'm using Github actions with two workflows: CI and CD. The CI workflow is triggered for new tags like v1.1.1 and pull requests to develop and hotfix branches.
name: CI
on:
push:
tags: v[1-9]+.[0-9]+.[0-9]+
pull_request:
branches: [develop, hotfix*]
The CD workflow is triggered when the previous workflow (CI) is completed.
name: CD
on:
workflow_run:
workflows: ['CI']
push:
tags: v[1-9]+.[0-9]+.[0-9]+
types:
- completed
Currently, my goal is to generate packages (Docker images) based on the name of the new tag. I'm trying to read the new tag name in the CD workflow using the action dawidd6/action-get-tag#v1:
- name: Get tag
id: tag
uses: dawidd6/action-get-tag#v1
- name: Use tag
run: echo ${{steps.tag.outputs.tag}}
But I'm getting the following error:
Run dawidd6/action-get-tag#v1
env:
IMAGE_NAME: open-tuna-api
Error: Not a tag ref (refs/heads/master)
My question is: how to read the tag name in my CD workflow that is triggering after the CI workflow?
First of all, you can get the tag without using an action, with ${GITHUB_REF##*/}.
Sample test workflow:
name: Experiment
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Debug
run: echo "Works. Tag is ${GITHUB_REF##*/}"
As for the chained workflows you mention - I am not sure it is possible to get the tag of the ancestor workflow, since the documentation mentions it is triggered on the default branch, and the last commit on that branch.
I have two workflows: CI (for continuous integration) and CD (for continuous delivery). Both are working fine individually. My goal is to run the CD workflow only when:
A new tag like v1.1.1 is created on the master branch
The CI workflow is finished
To achieve my goal I'm using the workflow_run event. These are the snippets of my workflows files:
ci.yml:
name: CI
on:
push:
tags: v[1-9]+.[0-9]+.[0-9]+
pull_request:
branches: [develop, hotfix*]
cd.yml
name: CD
on:
workflow_run:
workflows: [CI]
branches: [master]
types:
- completed
The current behavior is: when a tag is created in the master branch only the CI workflow run. I've tried putting tags: v[1-9]+.[0-9]+.[0-9]+ in the workflow_run but the behavior is the same.
My question is: how can I achieve my goal? Is it possible?
According to docs you can only use branches option and not tags for workflow_run so I'm afraid that's why your current setting doesn't work.
You have some alternatives though:
You can turn your CD workflow into action and run it as part of your CI with condition:
.github/actiond/cd/action.yml:
name: CD
description: Run CD
runs:
using: composite
steps:
- run: echo "Success!"
shell: bash
CI:
name: CI
on:
push:
tags: v[1-9]+.[0-9]+.[0-9]+
pull_request:
branches: [develop, hotfix*]
jobs:
sucess:
name: Log success
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: echo "Success!"
- name: Run CD
if: github.event_name == 'push' && contains(github.event.ref, '/tags/')
uses: ./.github/actions/cd
Have it as a separate job that is dependant on CI job using needs option
Converting it to action makes for better encapsulation IMO although requires some work.
You need to put "" around the name of the triggering workflow in cd.yml:
name: CD
on:
workflow_run:
workflows: ["CI"]
Github actions is still in beta and pretty new, but I hope someone can help regardless. I thought it would be possible to run github actions on the master branch and on pull requests, like this:
on:
pull_request
push:
branches: master
But this doesn't work, and throws the error
yaml: line 4: mapping values are not allowed in this context
. Instead I can only get it to work like this:
on: [pull_request, push]
What am I doing wrong? Thanks.
I think you are just missing a colon after pull_request. This works for me.
on:
pull_request:
push:
branches: master
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Test
run: echo "done"
Explanation
Each trigger has to be defined as a property that defines an object.
Each object defines overrides for default settings.
There are 3 possible syntax you can use:
Minimal syntax:
on:
pull_request:
push: { branches: [master] }
Explicit syntax:
on:
pull_request: {}
push: { branches: [master] }
Extendable syntax:
on:
pull_request:
push:
branches:
- master
When using a version control system the latter may be most useful as diff viewers can always easily distinguish* between different lines.
*Although modern diff viewers can also easily distinguish inline differences.