Github Actions automerge not working as expected - github

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'

Related

Github actions token workflow not set error

Hello everyone I am currently writing a workflow to auto merge when a pull request is made but I am stuck at an error telling me my token is not set more specifically: 2023-02-19T02:09:08.581Z ERROR environment variable GITHUB_TOKEN not set!. I have set all my tokens in my repo and settings tab. Any help would be appreciated.
name: CI/CD
on:
pull_request:
branches: [ master ]
jobs:
super-linter:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Super-Linter
uses: github/super-linter#v4.10.1
with:
files: ${{ join(github.event.pull_request.changed_files, ',') }}
Merge:
runs-on: ubuntu-latest
needs: super-linter
steps:
- name: Checkout Code
uses: actions/checkout#v2
- name: Merge pull requests
uses: pascalgn/automerge-action#v0.14.1
with:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
deploy:
runs-on: self-hosted
needs: Merge
steps:
#- uses: actions/checkout#v2 #this is used for if you want to push all source code into runner
- name: update code base
working-directory: /test_pipe/www/html
run: sudo git pull origin master
- name: restart
working-directory: /test_pipe/www/html
run: sudo systemctl restart nginx
image of error
pascalgn/automerge-action accepts GITHUB_TOKEN as an env variable, not as an argument. So it should be:
- name: Merge pull requests
uses: pascalgn/automerge-action#v0.14.1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
Refer to the documentation: https://github.com/pascalgn/automerge-action#usage

Versions and Tags Not Being Created Properly on Github

I have modified the Github workflow on a practice app to make it change version and patch with every push to the master branch.
In Github workflows - it says this process has been successful:
However when I check under releases and tags - no releases or tags are listed.
Is there something I'm missing, here is my pipeline.yml
name: Deployment pipeline
on:
push:
branches:
- master
pull_request:
branches: [master]
types: [opened, synchronize]
jobs:
simple_deployment_pipeline:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: '16'
- name: npm install
run: npm install
- name: lint
run: npm run eslint
- name: build
run: npm run build
- name: test
run: npm run test
- name: e2e tests
uses: cypress-io/github-action#v4
with:
build: npm run
start: npm run start-prod
wait-on: http://localhost:5000
tag_release:
needs: [simple_deployment_pipeline]
runs-on: ubuntu-20.04
steps:
- name: Bump version and push tag
uses: anothrNick/github-tag-action#1.36.0
if: ${{ github.event_name == 'push' && !contains(join(github.event.commits.*.message, ' '), '#skip') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BUMP: patch
RELEASE_BRANCHES: master
The log under tag_release looks like this:
Your problem, which can be inferred by the error message, is that you haven't checked out the code inside the job. This is noted in the readme of the dependent action.
name: Bump version
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout#v3
with:
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/github-tag-action#v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
This is a common mistake, many assume that the code should exist in the job by default, but once you get varying type of workflows you will understand some use cases where you don't actually need to checkout the local git repo.
Take a look at the action you are using and consider sticking to the #v1 tag or at the very least pick a more recent version (1.36 is over a year old).

Github Actions workflow not triggered although schedule should trigger the job

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

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.

Is there any way to send an email to myself when gh-pages branch deployed(no matter whether successful or fail)?

I desire to receieve an email notification when my website deployed on Github Pages, but I am struggled on Github Actions configuration. I use Github Actions (.github/workflows/gh-pages.ym in my main branch). And it looks like as below:
name: github pages
on:
push:
branches:
- main # Set a branch to deploy
pull_request:
jobs:
deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout#v2
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo
uses: peaceiris/actions-hugo#v2
with:
hugo-version: 'latest'
# extended: true
- name: Build
run: hugo --minify
- name: Deploy
uses: peaceiris/actions-gh-pages#v3
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
What can I do more in this workflow configration file?
Thank you very much!
P.S.
I just want a notification when the deployment job finished, so I don't care the content of the notification email.