"Can't find 'action.yml'" in reusable workflow - github

I have below structure:
.github
└── workflows
└── main.yml
└── send_alerts.yml
Now in main, I am using
jobs:
main:
steps:
- name: Git Checkout
uses: actions/checkout#v3
- name: some job
run: |
......
send_alerts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: ./.github/workflows/send_alerts.yml#feature/workflow1
with:
provision_status: "Success"
in my send_alerts.yml
name: Creating and Sending Alerts/Status
on:
workflow_call:
provision_status:
required: true
type: string
jobs:
create_send_alerts:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout#v3
- name: Some other jobs
run: |
.....
so this thorws me error:
Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/git-repo/.github/workflows/send_alerts.yml#feature/workflow1'. Did you forget to run actions/checkout before running your local action?
So my question is why it is complaining about action in send_alerts for main? while in the main.yml same actions/checkout#v3 works just fine?
I tried both actions/checkout#v2 and v3 in all cases I have same error

There are at least three things wrong:
You're calling a reusable workflow like an action. The call to a reusable workflow replaces the entire job, not just one step.
When you reference a workflow (or an action) that's in the same repository, with a relative path, you must not add an #version suffix. If you look at the error message, the runner is interpreting that as a directory name.
Both together result in something like this:
send_alerts:
uses: ./.github/workflows/send_alerts.yml
with:
provision_status: "Success"
You have to declare the parameter in an inputs object in the reusable workflow:
on:
workflow_call:
inputs:
provision_status:
required: true
type: string

Related

Github Action add "needs" with separate workflow file

I have got two workflows:
workflow1.yaml
workflow2.yaml
I need in workflow2.yaml add something like:
jobs:
build_kotlin:
runs-on: [server1, server2, server3]
needs: [workflow1]
steps:
- name: Checkout code
uses: actions/checkout#v2
Currently "needs" doesn't work properly. How can reference separate workflow yaml file?
needs is only used to establish relationships between jobs -- not entire workflows.
If you want to run "workflow2.yaml" after "workflow1.yaml" has been completed, then add a trigger like so:
on:
workflow_run:
workflows: [workflow1]
types:
- completed
jobs:
build_kotlin
# ...
Read more on Events That Trigger Workflows
Alternatively, you could make workflow1 a reusable workflow and then make sure it is executed before workflow2 like so:
jobs:
workflow1:
uses: octo-org/example-repo/.github/workflows/workflow1.yaml#main
build_kotlin:
runs-on: [server1, server2, server3]
needs: [workflow1]
steps:
- name: Checkout code
uses: actions/checkout#v2

github composite action error: An action could not be found at the URI

Created a github repo for a composite action, in the root of the repo i have a action.yml with the below code:
name: "semver-tag-release"
description: "Creates a semver release/tag on push to master"
runs:
using: "composite"
steps:
- name: Automated Version Bump
id: version-bump
uses: 'phips28/gh-action-bump-version#master'
env:
GITHUB_TOKEN: ${{ secrets.BYPASS }}
with:
skip-tag: 'false'
I added it to the existing push pipeline
name: Push
on:
push:
branches: [ master ]
workflow_dispatch:
jobs:
push:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: 'actions/checkout#v2'
with:
persist-credentials: false
fetch-depth: 50
- name: composite-semver-tag-release
uses: company/composite-semver-tag-release#0.1.4
When i run the push pipeline i get the error:
Download action repository 'company/composite-semver-tag-release#0.1.4' (SHA:dd280586e6409ee58fe59bd95d63dbefa19e2e13)
Error: An action could not be found at the URI 'https://api.github.com/repos/company/composite-semver-tag-release/tarball/dd280586e6409ee58fe59bd95d63dbefa19e2e13'
Any ideas on what im doing wrong?
My issue was that had the composite repo set to private. You have to make a public repo to use it as a composite (which im i dont really like to be honest)..
https://docs.github.com/en/actions/creating-actions/creating-a-composite-action#prerequisites
Prerequisites
Before you begin, you'll create a repository on GitHub.com.
Create a new public repository on GitHub.com.

Github action test if a commit containing a specific word was previously made

I need to make sure to test with github action, if a commit has previously been made that contains the word build.
If the commit does not contain the word build then tests with github action should not be run.
Can you give me some advice?
Test:
name: "Testing"
on:
push:
branches:
- master
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
From a push event, it's possible to extract the commit message by using github.event.commit.message
Here is an example of the github context for a push event.
Note that if there are several commit messages:
commit[0] contains the oldest commit
${{ github.event.commits[0].message }}
head_commit contains the youngest commit
${{ github.event.head_commit.message }}
Then, you can check in your job if the commit message contains or not the word you want, for example by using:
if: "!contains(github.event.head_commit.message, 'build')"
Therefore, your workflow could look like this if you don't want the job to be run if the commit message contains the 'build' word:
name: "Testing"
on:
push:
branches:
- master
jobs:
test_the_action:
if: "!contains(github.event.head_commit.message, 'build')"
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
Finally, you now also have the option to skip ci workflows with key words in the commit messages.

GitHub Actions get from API to create pull request

Is there a way to tell GitHub to automatically create a pull request from an API providing JSON content and merge it into my project?
I want to:
Edit files on a platform (I control the platform) using my own production editors/tools.
Have GitHub request it (REST), then create a PR or a commit, so people can collaborate on it with forks/GitHub project management.
Push from GitHub back to the platform for publishing.
3 is no problem, but 2 I can't find documentation for if it's even possible.
name: Manual workflow
on:
workflow_dispatch:
jobs:
makefiles:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout#v2
- name: Getting
uses: fjogeleit/http-request-action#master
id: myRequest
with:
url: 'https://domain/api/file'
method: 'GET'
- name: Show File
run: echo ${{ steps.myRequest.outputs.response }}
- name: Create A File
uses: 1arp/create-a-file-action#0.2
with:
path: 'src'
file: 'foo.bar'
content: ${{steps.myRequest.outputs.response}}
- name: final commit
uses: zwaldowski/git-commit-action#v1
id: git_commit
- name: show
run: echo "${{ steps.git_commit.outputs.sha }}"

How to trigger a new workflow from another workflow based on a path filter?

I have one workflow (that I want to be triggered by any commit with no path filter)
name: workflow1
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
...
that triggers another workflow
name: workflow2
on:
workflow_run:
workflows: ["workflow1"]
types:
- completed
jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
...
which is working fine with the workflow_run event. Now is it possible somehow to restrict workflow2 from being triggered even further (like with a path filter)? E.g. I make a commit to folder folder1 -> workflow1 triggered -> workflow2 triggered and if it's not a commit to the folder folder1, e.g. folder2 -> workflow1 triggered -> workflow2 not triggered. Is there something like the following I can add to workflow2?
name: workflow2
on:
paths:
- 'folder1/**'
workflow_run:
workflows: ["workflow1"]
types:
- completed
jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
...
Or another way to achieve that?
Thanks in advance for any help.
First option: Did you consider using the action verify-changed-files in your workflow run to execute the jobs only if specific files are updated?
Second option: It's more verbose, but you could save the path from the first workflow in an artifact to download in the second workflow.
Using the variable GITHUB_EVENT_PATH that returns the path of the file with the complete webhook event payload. For example, /github/workflow/event.json
It would look like this
In the FIRST workflow, you extract the path, then you save that number into a file and upload it as an artifact.
- name: Save the PATH in an artifact
shell: bash
env:
- PATH: {{ github.event.path}} ## If it's not specific enough, you can extract the $PATH variable on a previous step using the shell.
run: echo $PATH > path.txt
- name: Upload the PATH
uses: actions/upload-artifact#v2
with:
name: path
path: ./path.txt
In the SECOND workflow, you get the artifact and the path from the FIRST workflow, using the following GitHub Apps:
- name: Download workflow artifact
uses: dawidd6/action-download-artifact#v2.11.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: <first_workflow_name>.yml
run_id: ${{ github.event.workflow_run.id }}
- name: Read the path.txt file
id: path_reader
uses: juliangruber/read-file-action#v1.0.0
with:
path: ./path/path.txt
- name: Step to check the path output from the step above with an if condition to perform an operation (or not)
[...]
This link can also help to understand how to extract the PATH depending on the event.