Similar tho this question How to run Github Actions with the 'deployment_status' kitty and only on the QAS branch?
I want to execute a workflow only on a specific branch but combined with the deployment_status trigger.
So I want to execute my end to end test only if the deployment is done and we are on the develop branch.
The problem here is: On the trigger deployment_status the github.ref variable is not set. It is also written in docs. So I can not do a manual check if I am on the right branch.
name: E2E
on:
deployment_status:
# does not work because it is ignored on deployment_status
branches:
- develop
- stage
- master
- main
jobs:
chrome:
if: github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Run Cypress
uses: cypress-io/github-action#v2
with:
browser: chrome
cache-key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
env:
CYPRESS_BASE_URL: ${{ github.event.deployment_status.target_url }}
On the other way: If i use the deployment_status trigger I can not use branches or branches-ignore in combination. This is not working at all.
name: E2E
on:
deployment_status:
jobs:
chrome:
# does not work because github.ref is not defined
if: github.event.deployment_status.state == 'success' && github.ref == 'refs/heads/develop' /
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Run Cypress
uses: cypress-io/github-action#v2
with:
browser: chrome
cache-key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
env:
CYPRESS_BASE_URL: ${{ github.event.deployment_status.target_url }}
Any ideas how to solve this?
Related
As you may (or may not) know yesterday was a major incident of GitHub's services: https://www.githubstatus.com/incidents/tyc8wpsgr2r8.
Unfortunately I published a release during that time and the action responsible for building and publishing the code didn't trigger.
For actions which were executed at least once I have an option to "Re-run workflow" - but how can I proceed with an action which didn't even trigger - I can not see it anywhere whatsoever?
I think the last resort would be to just make another release, remove the problematic one etc. but I'd like to avoid that.
The workflow file:
name: Node.js CI
on:
push:
branches: [master]
release:
types: [published]
pull_request:
branches: [master]
jobs:
test:
name: Test Node.js v${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 16
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install --production=false --no-package-lock
- name: Lint 💅🏻
run: npm run lint
- run: npm test
release:
name: Publish NPM Package
if: startsWith(github.ref, 'refs/tags/')
needs:
- test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: npm install --production=false --no-package-lock
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
gh-pages:
name: Publish GitHub Pages
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
needs:
- test
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- name: Install ✔️
run: npm install --production=false --no-package-lock
- name: Build storybook 🏗️
run: npm run build-storybook
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action#4.1.3
with:
branch: gh-pages
folder: storybook-static
As you said in the comment, the easiest solution would be to remove the release and create it all over again.
Another option could be to add a workflow_dispatch event trigger to the workflow with a tag input, updating the jobs condition to use this input.tag variable if informed.
That way, if an automatic trigger failed (through push, release or pull_request), you could trigger it manually through the Github UI or the GH CLI as an alternative.
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"
My use case is, to trigger docs build when there is a trigger word in Pull Request Comments.
I am using pull-request-comment-trigger to know if a Trigger word is present in the code.
After knowing Action is triggered, I want to run some commands inside the repo. So, I have to use actions/checkout for that.
My doubt is, inside the run command, Only Shell Commands are valid, Right? I want to run another job if above condition satisfies.
My Current Yaml File
name: Testing GH Actions
on:
pull_request:
types: [opened]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: khan/pull-request-comment-trigger#master
id: check
with:
trigger: "AppajiC"
reaction: rocket
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- run:
# Generally Anything here runs if below condition satisfies.
# I want to run another job here, which uses actions/checkout#v2 action
if: steps.check.outputs.triggered == 'true'
How can I achieve this ?
You can use the condition for your checkout step and the following steps:
- name: Checkout
uses: actions/checkout#v2
if: steps.check.outputs.triggered == 'true'
- name: Following step1
if: steps.check.outputs.triggered == 'true'
...
Alternatively, you can create a new job and use that if condition once:
jobs:
deploy:
runs-on: ubuntu-latest
outputs:
deploy-status: ${{ steps.check.outputs.triggered }}
steps:
- uses: khan/pull-request-comment-trigger#master
id: check
with:
trigger: 'AppajiC'
reaction: rocket
env:
GITHUB_TOKEN: ${{ github.token }}
# this job will only run if steps.check.outputs.triggered == 'true'
# you just need to write the if once
after-deploy:
runs-on: ubuntu-latest
needs: [deploy]
if: needs.deploy.outputs.deploy-status == 'true'
steps:
- name: Checkout
uses: actions/checkout#v2
...
The workflow in file inrisk.packages.ci.yml generates a tag and a realise of the code when a push is done in the develop branch. The below works as expected.
name: Code Int
on:
push:
paths:
- 'infra/**'
jobs:
ci:
runs-on: ubuntu-latest
steps:
# Checks-out to $GITHUB_WORKSPACE
- uses: actions/checkout#v2
- name: Basic Checks
run: |
whoami
ls -lah
pwd
- uses: actions/setup-node#v1
# Create a new release when on develop which triggers the deployment
- name: Bump version and push tag
if: github.ref == 'refs/heads/develop'
uses: mathieudutour/github-tag-action#v4.5
id: tag_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
if: github.ref == 'refs/heads/develop'
id: create_release
uses: actions/create-release#v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
draft: false
prerelease: false
The below workflow in file inrisk.packages.cd.yml and is suppose to be triggered when ever a tag/realise is created/published.
name: Code Deploy
on:
push:
tags:
- 'v*'
release:
types:
- published
- created
- released
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Checks-out to $GITHUB_WORKSPACE
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
- name: Install Yarn
run: npm install -g yarn
- uses: chrislennon/action-aws-cli#v1.1
- name: Install, Build and Deploy
run: |
whoami
ls -lah
pwd
The second workflow Code Deploy dose not get trigger after Code Int publishes/created a tag/realise
However when I manually create a realise/tag the second workflow Code Deploy get triggered
This seems to be by design as stated here .This is to stop recursive workflow runs.
I used this article to get around the problem
In the following workflow, I want to add cache functionality so that, every time it will build from scratch. this is the workflow:
# This workflow will do
# a clean install of node deps
# build the source code
# run test across different versions of node
name: Conflict Check
on:
push:
branches:
- staging
pull_request:
branches:
- staging
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: mschilde/auto-label-merge-conflicts#master
with:
CONFLICT_LABEL_NAME: 'has conflicts'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
How can I achieve this?
You can use actions/cache action for purposes of caching in Github Actions.
jobs:
triage:
runs-on: ubuntu-latest
steps:
- name: Cache build files
uses: actions/cache#v2
with:
path: ${{ PATH_TO_CACHE }}
key:${{ runner.os }}-${{ hashFiles(<glob_pattern_for_files>) }}
- uses: mschilde/auto-label-merge-conflicts#master
with:
CONFLICT_LABEL_NAME: 'has conflicts'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
The example above assumes you want to cache your files between runs on different refs but your actual key declaration would depend on what you are trying to do.
For example if you are trying to cache between jobs or workflow runs on same ref:
key: ${{ runner.os }}-${{ github.sha }}