Github action runs on pr unexpectedly - github

I have this deveopment.yml in .github/workflows:
name: Development
on:
push:
branches:
- dev
paths-ignore:
- '**.md'
jobs:
test:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout#v2
- name: "Test Suite"
uses: ./.github/actions/test_suite
lint:
[...lint stuff]
db_migrate:
[...db migrate stuff]
[etc]
[etc]
I would expect this workflow to only fire when I push to the branch named dev
I also have a pull_request.yml workflow. It's similar:
on:
pull_request:
branches:
- '*'
paths-ignore:
- '**.md'
jobs:
test:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout#v2
- name: "Test Suite"
uses: ./.github/actions/test_suite
lint:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout#v2
- name: "Lint Suite"
uses: ./.github/actions/linting
I would expect this to run on any pull request to any branch, before it merges.
So far so good. If I make a PR from a feature branch into dev, it runs test and lint. When I merge, it runs the development.yml actions like db_migrate.
My question is why when I make a PR of dev into prod, it seems to run the development.yml actions. As soon as the PR is opened, it runs db_migrate. Why is that, and how do I make it not do that?
There is a production.yml but that's set to on release, so I don't think that's relevant here
on:
release:
types: [published]
paths-ignore:
- '**.md'
I've been staring at the docs but I'm having a slow brain morning. It's a little tricky to debug this because it's tightly coupled to github and two important branches.

Related

Keyword secrets is not working in github actions workflow

Workflow that call reusable one:
name: Build only workflow
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: ./.github/workflows/build_job
with:
TARGET: lol
secrets: inherit
./.github/workflows/build_job folder contain action.yml file:
name: Build job
on:
workflow_call:
inputs:
TARGET:
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: webfactory/ssh-agent#v0.5.4
with:
ssh-private-key: ${{secrets.SSH_KEY}}
- run: echo "hello"
Error: The workflow is not valid. .github/workflows/build_workflow.yml (Line: 16, Col: 9): Unexpected value 'secrets'
You're including the reusable workflow as a step, but a reusable workflow is an entire job not just a step.
Therefore, what you need is:
jobs:
my-job:
uses: ./.github/workflows/my-reusable-workflow.yaml
And then, since you can't do the checkout from outside anymore, you're going to have to add the checkout to your reusable workflow.
Also see this other answer of mine on the distinction between composite actions and reusable workflows.

How to access files checked out by another workflow in GitHub Actions?

Can I access the files that are checked out or generated by a caller/called workflow?
I want to have a separate setup.yml workflow that checks out the repository code and then reuse that workflow in other workflows.
Here is an example called workflow file (setup.yml):
name: Set the project up
on: workflow_call
jobs:
setup:
name: Set the project up
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout#v3
- name: Set up Node
uses: actions/setup-node#v3
with:
node-version: '16'
Here is the caller workflow file (ci.yml):
name: CI
on:
push:
branches:
- main
jobs:
setup:
uses: ./.github/workflows/setup.yml
test-the-project:
needs: setup
uses: ./.github/workflows/test.yml

Invalid workflow file for GitHub actions

So I am just trying to learn how to use github workflow actions and made this simple starter test:
name: Basic test push
on:
push:
branches:
- 'autoupdate'
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: echo Test One Worked!
However, I get an error:
Invalid workflow file
You have an error in your yaml syntax on line 10'
Anyone know why?
You're indenting the steps, but it should be on the same level as runs-on:
name: Basic test push
on:
push:
branches:
- 'autoupdate'
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: echo Test One Worked!

Github action execute an action that calls other actions upon its completion

I have to do the following, every time a commit is done (so it can also be done by editing the file from the browser on Github), a Github action is called.
The Github action has to do the following:
Run the command found in the package.json or just run the ncc build command
What such a thing:
"build": "ncc build"
To then commit the build files.
After committing with the push, the 4 Github action test must be run.
How do you advise me to do?
I thought of such a thing:
on:
push:
branches:
- master
name: Build
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
name: Check out current commit
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Commit
run: |
git config --local user.email "41898282+github-actions[bot]#users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Build" -a
- name: Push
uses: ad-m/github-push-action#master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
At the moment the test is like this for example, how can I do?
Test.yml
on:
push:
branches:
- master
name: "Testing"
jobs:
test_the_action:
name: Test the action
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout#v2
- uses: suisei-cn/actions-download-file#master
id: downloadfile
name: Download a file
with:
url: "[API Endpoint](https://api.github.com/repos/suisei-cn/actions-download-file)"
target: public/
auto-match: true
- name: Display the file
run: head -n8 public/actions-download-file
There are two options. You can add jobs for each test in your main yml with the needs keyword or call your test yml with the workflow run event as trigger.
Option 1 with needs keyword:
on:
push:
branches:
- master
name: Build
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- <your-build-steps>
test1:
name: Test
runs-on: ubuntu-latest
needs: build
steps:
- <your-test-steps>
Option 2 with workflow run as trigger:
on:
workflow_run:
workflows: ["<name-of-your-main-workflow>"]
types:
- completed
name: "Testing"
jobs:
test_the_action:
This option works only on default branch.

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