Github Actions workflow not triggered although schedule should trigger the job - github

I'm trying to auto-assign issues and PRs in Github from a Github Actions workflow. The respective steps work fine when an issue / a PR is opened. So this trigger is fine.
Recently I added Dependabot to my repo. Since Dependabot cannot access my secrets I cannot assign any issue in a Dependabot-triggeres pipeline. So I just thought I run this pipeline with a scheduler one per day to "clean up" every issue and PR which is unassigned. But this schedule config does not trigger the pipeline. It simply does nothing, not even show as a pipeline run which does nothing (with all jobs skipped). Seems like the trigger is completely ignored.
This is my workflow file.
---
name: "Organize: Assign Issues + Pull Requests"
on:
issues:
types:
- opened
pull_request:
types:
- opened
schedule:
- cron: '0 9 * * *' # https://crontab.guru/#0_11_*_*_*
permissions:
contents: read
issues: write
pull-requests: write
jobs:
add-to-project:
name: Add to project
runs-on: ubuntu-latest
steps:
- name: Add to project (issues and PRs)
uses: actions/add-to-project#main
with:
project-url: https://github.com/users/sebastian-sommerfeld-io/projects/1
github-token: ${{ secrets.GH_TOKEN_REPO_AND_PROJECT }}
assign-to-user:
name: Assign to user
runs-on: ubuntu-latest
steps:
- name: Assign issue to user when moved into column
uses: pozil/auto-assign-issue#v1
# https://github.com/marketplace/actions/auto-assign-issue
with:
assignees: ${{ github.actor }}
numOfAssignee: 1
allowSelfAssign: true
abortIfPreviousAssignees: true
new-pull-request-chat-message:
runs-on: ubuntu-latest
needs: ['add-to-project', 'assign-to-user']
if: github.event_name == 'pull_request'
steps:
- name: Send message to Google Chat
uses: Co-qn/google-chat-notification#releases/v1
with:
name: New Pull Request "${{ github.event.pull_request.title }}" (raised by ${{ github.actor }})
url: ${{ secrets.GOOGLE_CHAT_WEBHOOK }}
status: ${{ job.status }}
on-failure:
runs-on: ubuntu-latest
needs: ['add-to-project', 'assign-to-user', 'new-pull-request-chat-message']
if: failure()
steps:
- name: Send Pipeline Status to Google Chat
if: always()
uses: Co-qn/google-chat-notification#releases/v1
with:
name: ${{ github.workflow }}
url: ${{ secrets.GOOGLE_CHAT_WEBHOOK }}
status: failure
What bugs me is that the scheduler setting is copied from another workflow where it works just fine. So I cannot think of a reason why this pipeline is not triggered at 09:00 in the morning.

Found a way :-)
I use the Github CLI to get all PRs with a certain label and assign a user. This is a new dedicated pipeline.
---
name: "Organize: Dependabot Pull Requests"
on:
schedule:
- cron: '30 * * * *' # https://crontab.guru
permissions:
contents: read
issues: write
pull-requests: write
jobs:
assign-user:
name: Aassign PRs with label 'dependencies'
runs-on: ubuntu-latest
steps:
- name: Get PR and assign user (filtered by github cli)
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO_AND_PROJECT }}
label: dependencies
assignee: sebastian-sommerfeld-io
run: |
OUTPUT=""
pr_ids="$(gh pr list --repo "$GITHUB_REPOSITORY" --label "$label" --json number --jq '.[].number')"
for id in $pr_ids; do
gh pr edit "$id" --repo "$GITHUB_REPOSITORY" --add-assignee "$assignee"
done
Then I updated the triggers of my original pipeline to
on:
issues:
types:
- opened
pull_request:
types:
- opened
- assigned

Related

GitHub Actions Reuse Workflow Definitions

I have a project where I have two GitHub actions yml file where the first file is called build.yml and it contains instructions to compile, build and test the project. It is as simple as this:
name: build my-project
on:
push:
paths-ignore:
- 'images/**'
- README.md
branches:
- master
pull_request:
branches:
- master
release:
types: [ created ]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: cache ivy2
uses: actions/cache#v1
with:
path: ~/.ivy2/cache
key: ${{ runner.os }}-sbt-ivy-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
- name: sbt Test
run: sbt clean test
I now have another yml file that contains the instructions to do a release based on annotated tags. It is like this:
name: release my-project
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build:
uses: ./.github/workflows/build.yml
publish:
runs-on: ubuntu-latest
needs: test # See build.yml file where the test job is defined
# If there is a tag and if that tag comes from master branch
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: checkout
uses: actions/checkout#v3
- name: capture changelog
id: changelog
uses: metcalfc/changelog-generator#v4.0.1
with:
myToken: ${{ secrets.GITHUB_TOKEN }}
- name: sbt ci-publish-github
run: sbt publish
- name: ci-release-github
id: create-release
uses: actions/create-release#latest
with:
allowUpdates: true
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
## What's Changed
${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
I just created an annotated tag which then resulted in an error like this:
Invalid workflow file: .github/workflows/publish.yml#L14
error parsing called workflow "./.github/workflows/build.yml": workflow is not reusable as it is missing a `on.workflow_call` trigger
So basically what I want is, when I push an annotated tag, I want to first run the test job from build.yml and then once that succeeds, I would like to run the publish job. Any suggestions on how to get this straight?
So basically what I want is, when I push an annotated tag, I want to first run the test job from build.yml and then once that succeeds, I would like to run the publish job. Any suggestions on how to get this straight?
You almost got it right with your implementation. You just need a few modifications:
The build job needs to depends on the publish job:
name: release my-project
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]*'
jobs:
publish:
[ ... ]
build:
needs:
- publish
uses: ./.github/workflows/build.yml
The build needs the workflow_call trigger (as stated by the error message - Reference):
on:
workflow_call:
push:
[ ... ]
Note: You could even share the tag value from the previous workflow, sending it as input to the second one by using:
on:
workflow_call:
inputs:
tag:
required: true
type: string
Calling the reusable workflow that way from the main workflow:
build:
needs:
- publish
uses: ./.github/workflows/build.yml
with:
tag: 'MY TAG'
I was able to fix it by adding the following in my publish.yml:
jobs:
tests:
uses: ./.github/workflows/build.yml
publish:
runs-on: ubuntu-latest
needs: [tests] # See build.yml file where the test job is defined
In my build.yml, I had to add the following:
on:
push:
paths-ignore:
- 'images/**'
- README.md
branches:
- master
pull_request:
branches:
- master
release:
types: [ created ]
workflow_call:
Notice that workflow_call: entry that needs to be added explicitly.

How to associate status of a Github action workflow with a commit or PR

I have a Github action workflow which is set to trigger on issue_comment, for example the following
name: Testing actions
on:
issue_comment:
types: [created, edited]
jobs:
testing-actions:
if: github.event.issue.pull_request && contains(github.event.comment.body, '#test')
name: Just testing
runs-on: ubuntu-latest
steps:
- uses: xt0rted/pull-request-comment-branch#v1
id: comment-branch
- uses: actions/checkout#v3
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
- name: Print stuff
run: echo "Hello dudes!"
The workflow is working, it is getting triggered when I comment "#test" on a PR. But I have to check it from the actions tab, the workflow doesn't get associated with any commit or PR, so it doesn't get shown in the checks tab in the PR, or the commits don't show any commit status.
How do I get the workflow status and details in the PR page, so that I don't have to go to actions tab manually to see the results?
I solved this by manually setting the commit status using #myrotvorets/set-commit-status-action. The workflow file ended up being like the following
name: Testing actions
on:
issue_comment:
types: [created, edited]
jobs:
testing-actions:
if: github.event.issue.pull_request && contains(github.event.comment.body, '#test')
name: Just testing
runs-on: ubuntu-latest
steps:
- name: Get PR details
uses: xt0rted/pull-request-comment-branch#v1
id: comment-branch
- name: Set commit status as pending
uses: myrotvorets/set-commit-status-action#master
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
- uses: actions/checkout#v3
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
- name: Print stuff
run: echo "Hello dudes!"
- name: Set final commit status
uses: myrotvorets/set-commit-status-action#master
if: always()
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
This works pretty well, the workflow runs get associated with the PR's head commit, and thus it shows up on the PR page as a check too. Thanks #rethab for the alpha.

GitHub Actions re-run and who is the author

I need an additional field with information on who is the author of the trigger re-run button in GitHub actions.Any help + bless you 🙏
Below is an example.
name: CI
#Only for master
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
check_run:
types: [rerequested]
#Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
notify:
runs-on: ubuntu-latest
steps:
# Ms Teams Deploy Cards step linked to repository in a dedicated created Ms teams channel
- name: teams notification
uses: patrickpaulin/ms-teams-deploy-card#master
if: always()
with:
github-token: ${{ github.token }}
webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
and this part of the code
check_run:
types: [requested]
This step is to identify re-run action but in this example just duplicate MS Deployment Card and provide all information with was when the author did push or pull request.
P.S
Friendly advice: Don't use toko-bifrost repo because do not work
correct, explaining in the link below.
https://github.com/toko-bifrost/ms-teams-deploy-card/issues/44
SOLVED
- name: teams notification
uses: patrickpaulin/ms-teams-deploy-card#master
if: always()
with:
github-token: ${{ github.token }}
webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
custom-facts: |
- name: GiitHub Action
value: ${{ github.actor }}

github `registry_package` event doesn’t trigger

I managed to create two actions on 1 private repository:
The first one builds the image and push the docker image to GitHub
Container Registry
The second one needs to be triggered when newer
image is published to the GitHub container registry and deploy the
image
The issue is that the second one it doesn't get triggered and doesn't run. I use GitHub Repo Token, and I found this that says triggering new workflows should be done using a personal access token. Is this the real issue or there is some workaround? Personally I don't want to put my github token there.
As reference here is the yml code for the fist github action:
name: Build Docker Image
on:
push:
branches:
- feature/ver-64/service-template
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout#v2
-
name: Docker meta
id: meta
uses: docker/metadata-action#v3
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action#v1
-
name: Login to Github Container Repository
if: github.event_name != 'pull_request'
uses: docker/login-action#v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action#v2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
And this is the yml for the second one that needs to be trigered once the first one publish new image to the registry:
name: Deploy to Azure
on:
registry_package:
types: [ published, updated ]
jobs:
debug:
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action#v2
GitHub actions prevents triggering more actions. Sort of to protect against infinite loops. Hence why the token used by GitHub Actions has a special flag on it which causes the 2nd workflow not to trigger.
You have a few options:
Use a PAT to push to GitHub Container Registry. (as per the docs)
Have a 2nd stage that depends on the first one in your existing workflow to perform the deployment.
A variation on 2, use a template to extract the deploy logic to a single template, use the same template action in both the workflow that pushes the image as well as the workflow that triggers when an image is pushed

Github Actions automerge not working as expected

I have a yml file with 5 jobs as below
build - working
unit tests - working
regression tests - working
create pull request - working
merge pull request - not working
The first 3 jobs work on my development branch so my file begins with
name: Spicethedeploy
on:
push:
branches:
- development
jobs:
Job 4 I specify this
source_branch: "development"
destination_branch: "master"
But when job 5 runs it looks for a pull request for development not master and does not complete. The code for this job is:
automerge:
needs: pull-request
runs-on: ubuntu-latest
steps:
- name: automerge
uses: pascalgn/automerge-action#v0.13.1
env:
GITHUB_TOKEN: ${{ secrets.ghp_xxxxxxxxxxxxxxxxxxxx }}
Can someone tell me how to make this job look to the master branch?
I have created a second yml file called automerge.yml, contents below
name: automerge
on:
pull_request:
branches:
- master
jobs:
automerge:
runs-on: ubuntu-latest
steps:
- name: automerge
uses: pascalgn/automerge-action#v0.13.1
env:
GITHUB_TOKEN: ${{ secrets.ghp_xxxxxxxxxxxxxxxxxxxxxxxx }}
MERGE_LABELS: "automerge"
The pull request has also been removed from the first yml file which now stops after creating the pull request. The new yml file then kicks in and tries to merge but skips with this message
Run pascalgn/automerge-action#v0.13.1
2021-04-04T18:36:14.889Z INFO Event name: pull_request
2021-04-04T18:36:15.102Z INFO Skipping PR update, required label missing: automerge
2021-04-04T18:36:15.102Z INFO Skipping PR merge, required label missing: automerge
The documentation on MERGE_LABELS: here says -
When an empty string ("") is given, all pull requests will be merged.
Following that, this worked for me
- id: automerge
name: automerge
uses: "pascalgn/automerge-action#v0.15.3"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: ""
Thanks to GuiFalourd for the tips which pointed me in the right direction on this. Following his advice led me to this solution which works well
merge:
needs: pull-request
name: merge
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout#v2
- name: merge
uses: mtanzi/action-automerge#v1
id: merge
with:
github_token: ${{ secrets.ghp_xxxxxxxxxxxxxxxxxxxxxxxxx }}
source: 'development'
target: 'master'