Is it possible to not run github action for readme updates? - github

I have the following action on Github actions that automatically packs and deploy a package to nuget.org every time a PR gets merged into master.
name: Nuget Deploy
on:
push:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: 3.1.101
- name: Generate Nuget package
run: dotnet pack
working-directory: DateOverride
- name: Deploy to nuget.org
run: dotnet nuget push *.nupkg -k ${{ secrets.NUGET_DEPLOY_KEY }} -s https://api.nuget.org/v3/index.json
working-directory: DateOverride/DateOverride/bin/Debug
But I would like that it was not run if my update is only a README.md update, is it possible to do so?

I'd think the paths-ignore setting should help:
on:
push:
branches:
- master
paths-ignore:
- '**/README.md'

You might want to combine your current GitHiub Action with another like MarceloPrado/has-changed-path
This action outputs whether a path or combination of paths has changed in the previous commit.
[This] action is meant to be used inside your job steps, not at the root of your workflow file
Or (opposite filter): dorny/paths-filter
With this Github Action you can execute your workflow steps only if relevant files are modified.

Related

Working directory is not working in my Github action

I'm starting to use Github actions. When I ran the process in my Ubuntu server, one of the config options was to select the work folder, by default, I leave _work. But previously, I had my repository in another folder.
So, I'm trying to add a specific value for working-directory to my yml, file but is not using the value in the build process.
YML File:
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
defaults:
run:
working-directory: /../../../../var/www/mysite.com
jobs:
deployment:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Use Node.js
uses: actions/setup-node#v3
with:
node-version: '14.x'
- name: Install dependencies
run: yarn
- name: Build
run: yarn build
- name: Restart server application
run: pm2 restart pm2_script.json
The process ran ok, but is doing all the process (checkout, build, etc) inside _work and not inside working-directory
What I'm doing wrong?
Thanks!!

Github action for pull request not running

Github actions on pull request were working yesterday. Today they are not running.
.github/workflows/pull_request.yml looks like
name: Pull Request
on:
pull_request:
paths-ignore:
- '.github/**'
jobs:
black_and_flake8:
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout#v3
- name: "Lint project"
uses: ./.github/actions/lint_project
test_common:
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout#v3
- name: "Test common"
uses: ./.github/actions/test_common
test_dags:
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout#v3
- name: "Test dags"
uses: ./.github/actions/test_dags
[etc there are a lot of jobs for different parts of this repo]
For example, ./github/actions/test_dags has a single action.yml file inside that looks like this
name: "test_dags"
description: "Tests for code that lives in /dags"
runs:
using: "composite"
steps:
- name: Run pytest
working-directory: dags
run: |
docker build -t dagtest -f Dockerfile.airflow_dags_test .
docker run --name=dagtestimage dagtest
docker cp dagtestimage:/tmp/htmlcov .
shell: bash
- uses: actions/upload-artifact#v3
with:
name: dags_htmlcov
path: /home/runner/work/processing/processing/dags/htmlcov/
Putting aside that there may be a smarter way to run these tests, why are no actions being fired at all when I make a pull request now? It happily ran all my checks yesterday. Nothing has merged into main related to github actions- just some pytest stuff for one of the modules, and that ran the checks.
My PR is changing the dockerfile referenced in the action above, updating requirements.txt, and to debug I changed a python file (in case those file types were magically excluded).
The GUI for the PR doesn't show any checks. Nothing new shows up in the Actions tab.
How do I figure out why this isn't working?
Turns out github is having an issue - https://www.githubstatus.com/ said everything was green when I posted this, but it has since updated to
Incident with GitHub Actions, API Requests, Codespaces, Git Operations, GitHub Packages, and GitHub Pages

error "gatsby-source-github-api" threw an error while running the sourceNodes lifecycle: token is undefined

I am new to Gatsby and just tried a GH Actions workflow for my site today. I see this error at the build stage:
error "gatsby-source-github-api" threw an error while running the
sourceNodes lifecycle: token is undefined
I am using this to pull all repos on my Github into the site.
What I have tried so far:
Checked the Github personal access token
the build is working locally
Versions:
"gatsby-source-github-api": "^0.2.1" "gatsby": "^2.26.1"
This is my node.js.yml GH Actions workflow file:
name: Node.js CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [13.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
PS: I have used a .env file to hold the value of the token that the plugin 'gatsby-source-github-api' requires. And it is in my .gitignore file. So which means it is not sent to GH and hence can't find it?
So that was it -- the .env file which wasn't being pushed to Github.
So I needed to make the token available to the GH Action build somehow.
I tried the action SpicyPizza/create-envfile#v1. It isn't supported by Github but seemed to do the job. It creates a .env file at build with the keys you provide it.
You could also create a .env file manually. See thread.

Github actions: Can the effects of one job trigger another?

I want to define a workflow as follows, for a node.js repo:
When new code is merged into master AND version in package.json is changed, create a new Github release for that version
When a new Github release is created, publish package to NPM
What I hope to achieve is that in our most typical workflow (PR merged to master) a release s created and package is automatically uploaded to NPM but to also be able to trigger an upload to NPM directly from a feature branch (usually a pre-release version, 1.0.3-rc1) by manually creating a release from such branch.
I've set up two Github workflows, each with a single job.
The first:
name: Create release on new version merge
on:
push:
branches:
- master
jobs:
release-on-new-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Check for version change
id: check
uses: EndBug/version-check#v1
with:
file-url: ::before
static-checking: localIsNew
token: ${{ secrets.GITHUB_TOKEN }}
- name: Log when changed
if: steps.check.outputs.changed == 'true'
run: 'echo "Version change found: ${{ steps.check.outputs.version }}"'
- name: Create Release
if: steps.check.outputs.changed == 'true'
id: create_release
uses: actions/create-release#v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.check.outputs.version }}
release_name: v${{ steps.check.outputs.version }}...
The second:
name: Publish on new release
on:
release:
types: created
jobs:
publish-on-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: 10
registry-url: https://registry.npmjs.org/
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Individually these workflows work as expected: When I merge some work onto master that changes the version number a release is created, and when I manually create a release it gets published to NPM. However I would also expect the release created as the effect of the first workflow to trigger the second flow and therefore when I merge a version change into master eventually automatically see it published to NPM. But to my amazement that does not happen. Is there some sort of mechanism that prevents the effects of one job to (indirectly) trigger another? Or am I missing something?
You might consider to explicitly mention the dependency of one job needed another job, using needs.
You can see that approach illustrated with:
"GitHub Actions: Dependent Jobs" from Edward Thomson (who is also on Stack Overflow)
That would allow to define a third action which would need the first two, forcing them to be chained in their execution.

github action: run a test file on pull request

I want to run a test file when someone sends a pull request.
This is my action.yml file.
name: "GitHub Actions Test"
on:
pull_request:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
# - uses: actions/checkout#v1
- name: 'Install Node'
uses: actions/setup-node#v1
- name: Install mocha
run: npm install -g mocha
- name: Install dependencies
run: npm install
- name: "Run Test"
run: mocha test-mocha.test.js
but when running the test from github, I got the following error:
Error: No test files found: "test-mocha.test.js"
I wonder something is wrong on the last line of my yml file.
how to fix this?
This is because you've commented out the line that checks out your code:
# - uses: actions/checkout#v1 # Remove the comment from this line
By default, your code is not checked out in the workflow's directory. As such, you have to use the Checkout GitHub Action to check out your code.
From the README:
This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.