I'm using the cache GitHub action and I'm generating a cache key with the built-in hashFiles function:
key: ${{ runner.os }}-${{ hashFiles('./packages/protocol/{,!(node_modules)}**/*') }}-coverage-lcov
The command above does not work, however. What I see in the GitHub Actions logs is this:
Cache saved with key: Linux--coverage-lcov
There is no hash generated, presumably because the glob is incorrect. How can I correctly ignore the node_modules folder in the path provided to the hashFiles function?
Your paths need to be in separate parameters, as shown in the example given on the hashFiles docs page you linked:
hashFiles('**/package-lock.json', '**/Gemfile.lock')
Aditionally you seem to be missing Some * after the end of the { and maybe before the node_modules depending on your directory setup.
Related
I'm quite a rookie with GitHub Actions so this might be a stupid question: Is there a way to link pull requests with issues (in the UI linked PRs are shown under Development) in Github Actions using Github CLI or octokit/rest.js via actions/github-script?
enter image description here
Background: there is a workflow that creates pull requests. That works fine, only thing missing is the link between issues and corresponding pull requests. I would prefer not to use keywords nor other custom actions from the marketplace.
I've searched in the octokit/rest.js documentation https://octokit.github.io/rest.js/v19 under Issues and Pulls as well as in the GitHub cli documentation https://cli.github.com/manual/gh but couldn't find a solution.
I would like to have a solution either using GitHub Script https://github.com/marketplace/actions/github-script
or the command line.
You can use the Add an issue link Action for that.
This Action allows linking issues to Pull Requests. For example:
name: 'Issue Links'
on:
pull_request:
types: [opened]
jobs:
issue-links:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: tkt-actions/add-issue-links#v1.8.1
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}' # required
branch-prefix: 'issue-' # required
This workflow will trigger on Pull Request open and link related issues mentioned in the PR body.
Make sure to set the corresponding permission for the job:
permissions:
pull-requests: write
For more about these permissions visit the Permissions for the GITHUB_TOKEN.
Does anyone know what this does ?
uses: ./
I see it used in quite a few places but cannot seem to find any reference for it.
The uses keyword of github actions is used to specify the action that should be executed as part of a workflow. The ./ value tells GitHub to use the action defined in the current repository, rather than referencing a pre-built action.
It's also possible to specify the path to the action within the repository, rather than using ./. For example:
steps:
- uses: ./path
with:
parameter1: value1
parameter2: value2
This would execute the action located at ./path within the repository.
In Github Actions composite actions, you must specify the branch where the composite action is located, e.g.,
- uses: /username/repo-name/.github/composite-actions#main
Is there a way to specify the current branch instead rather than hardcode #main?
After checking further, it seems using the relative path works. For example:
- uses: ./.github/composite-actions
I can't for the life of me figure out why my GitHub Action isn't triggering on push. For context: I have a data file that is updated daily and pushed to the test branch with a timestamp commit message. I am trying to use this timestamp in a Dynamic Badge for my README. Everything works fine when the workflow is run manually (except, of course, I don't get the event data I am hoping to obtain when the action runs on the trigger.)
on:
push:
branches:
- test
paths:
- 'data/Sales.csv'
env:
BADGE_MESSAGE: ${{ github.event.commits[0].message }}
jobs:
create-badge-test:
runs-on: ubuntu-latest
steps:
- name: Create Dynamic Badge
uses: schneegans/dynamic-badges-action#v1.1.0
with:
auth: ${{ secrets.GIST_PAT }}
gistID: 0123456789 #Not actual gist ID
filename: test.json
label: Last Refresh
message: $BADGE_MESSAGE
color: orange
And yes, I've tried putting the branch name in quotes and updating the paths: to - '**.csv' and the action still does not trigger.
There must be something else wrong - all you have here in this workflows is just fine.
You can see it working here:
https://github.com/grzegorzkrukowski/stackoverflow_tests/actions/runs/1860382530
For this commit:
https://github.com/grzegorzkrukowski/stackoverflow_tests/commit/f3f8dd20fa780746441c7b6623b6a2a9929aa70d
It's exact copy of workflow from your question.
I would expect you are pushing a file with different name - keep in mind some systems will be case-sensitive - so pushing data/sales.csv won't work properly.
Another idea is that you pushing it to wrong branch or you have wrong path to the file.
You have to push to test branch and with data/Sales.csv - it only triggers workflow if both are true.
Short answers is - workflow is fine as it is - no brackets needed.
I could help more seeing the repository with this workflow and exact commits being done.
The action is not running because you also need to satisfy the paths condition as explained on GitHub docs
Note: If you use both the branches filter and the paths filter, the workflow will only run when both filters are satisfied.
If you want the action to run when you push to test you have to remove the paths condition
on:
push:
branches:
- 'test'
Is it possible to split a GitHub Actions workflow file and reference it from other? I need to deploy an application into multiple environments i.e. staging and production and would like to share half of the steps to minimize maintenance.
You can split each action in the following file format:
folder named "test-action"
.github/test-action/action.yml
with contents
name: test-action
description: test action
inputs:
test_input:
description: key
required: true
runs:
using: composite
steps:
- name: echo test
shell: bash
run: |
echo ${{inputs.test_input}}
then you can refer to the action from any yml:
- name: test-action
uses: ./.github/test-action
with:
test_input: "test-string-value"
the key here was to make sure that the file within your named action folder would be called "action.yml"
It seems like there is no way as CircleCI allows defining commands that are a set of steps: https://github.community/t5/GitHub-Actions/reusing-sharing-inheriting-steps-between-jobs-declarations/td-p/37849
At this moment, I guess we can use repository_dispatch as a workaround.
In this example, it handles events between repositories, but I think we can apply this in same repository: https://blog.marcnuri.com/triggering-github-actions-across-different-repositories/