I am working with new GitHub actions, idea of a workflow below is to run when pr is opened or synchronised, it should first check out and install dependencies and afterwards run few yarn scripts
name: PR to Master
on:
pull_request:
branches:
- master
jobs:
# Synchronize or Opened
synchronized_or_opened:
name: Synchronize or Opened
runs-on: ubuntu-latest
steps:
- uses: actions/bin/filter#master
with:
args: action 'opened|synchronize'
# Add Labels
add_labels:
name: Add Labels
runs-on: ubuntu-latest
steps:
- uses: actions/labeler#v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
needs: synchronized_or_opened
# Checkout
checkout:
name: Checkout
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
needs: synchronized_or_opened
# Install Dependencies
install_dependencies:
name: Install Dependencies
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- run: yarn dep:install-npm
needs: checkout
# Typecheck
typecheck:
name: Typecheck
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- run: yarn typecheck
needs: install_dependencies
# Prettier
prettier:
name: Prettier
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- run: yarn prettier
needs: install_dependencies
# ESLint
eslint:
name: ESlint
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- run: yarn eslint
needs: install_dependencies
# Danger
danger:
name: Danger
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- run: yarn danger
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
needs: install_dependencies
At the moment it successfully gets to a checkout stage, but once Install job is ran I get following error
error Couldn't find a package.json file in
"/home/runner/work/myRepo/myRepo"
Judging by this checkout either failed or I am in a wrong folder?
As mentioned in the Workflow syntax docs:
Each job runs in a fresh instance of the virtual environment specified by runs-on.
From what I can see here, you're doing the checkout step in a completely separate job from others. Doing it that way it does not affect other jobs in any way. It should actually be defined inside those jobs where your npm CLI commands are executed.
Here's an example of how it would look like in one of your jobs:
jobs:
# (...) Other jobs
# Install Dependencies
install_dependencies:
name: Install Dependencies
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- uses: actions/checkout#master
- run: yarn dep:install-npm
needs: checkout
# (...) Other jobs
There are some general examples in GitHub starter workflow templates.
Related
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).
I have the following two actions, how can I make the second action be executed at the end of the first after making the first one commit and push?
Action1
on:
workflow_dispatch:
inputs:
name: Scrape Data
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
- name: Build
run: npm install
- name: Scrape
run: npm run action
- uses: mikeal/publish-to-github-action#master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub sets this for you
Action2
on:
workflow_dispatch:
inputs:
name: Visit Data
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
- name: Build
run: npm install
- name: Scrape
run: npm run visit
- uses: mikeal/publish-to-github-action#master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub sets this for you
You could use the workflow_run trigger on the second workflow.
Example:
name: Visit Data
on:
workflow_run:
workflows: ['Scrape Data'] # First workflow name
types:
- completed # can also use 'requested'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
- name: Build
run: npm install
- name: Scrape
run: npm run visit
- uses: mikeal/publish-to-github-action#master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Note that you can't use workflow inputs in that case (I observed you had it set, and if it's necessary you would need to use another trigger, for example through the Github API using a workflow dispatch event with a payload).
I'm following the documentation but I don't see my check available in the search bar.
The documentation seems to think that the check will show up automatically but its not happening for me. It is a private repository but I also have Pro.
Do I need to have anything special in my yaml file? Or am I doing something else wrong? Do I just need to wait?
test.yml
name: Foo
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
timeout-minutes: 2
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install --immutable
- run: yarn lint
- run: yarn types
Searching on "build" worked.
I had only searched by "Foo" and "test". smh.
Thank you #rethab
As you may (or may not) know yesterday was a major incident of GitHub's services: https://www.githubstatus.com/incidents/tyc8wpsgr2r8.
Unfortunately I published a release during that time and the action responsible for building and publishing the code didn't trigger.
For actions which were executed at least once I have an option to "Re-run workflow" - but how can I proceed with an action which didn't even trigger - I can not see it anywhere whatsoever?
I think the last resort would be to just make another release, remove the problematic one etc. but I'd like to avoid that.
The workflow file:
name: Node.js CI
on:
push:
branches: [master]
release:
types: [published]
pull_request:
branches: [master]
jobs:
test:
name: Test Node.js v${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 16
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install --production=false --no-package-lock
- name: Lint 💅🏻
run: npm run lint
- run: npm test
release:
name: Publish NPM Package
if: startsWith(github.ref, 'refs/tags/')
needs:
- test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: npm install --production=false --no-package-lock
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
gh-pages:
name: Publish GitHub Pages
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
needs:
- test
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- name: Install ✔️
run: npm install --production=false --no-package-lock
- name: Build storybook 🏗️
run: npm run build-storybook
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action#4.1.3
with:
branch: gh-pages
folder: storybook-static
As you said in the comment, the easiest solution would be to remove the release and create it all over again.
Another option could be to add a workflow_dispatch event trigger to the workflow with a tag input, updating the jobs condition to use this input.tag variable if informed.
That way, if an automatic trigger failed (through push, release or pull_request), you could trigger it manually through the Github UI or the GH CLI as an alternative.
I have the following GitHub Actions config file (parts removed for simplicity).
name: CI
on: push
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x, 13.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
The major problem I'm running into is that lets say the test for Node.js version 8 fails. But the rest succeed. In that event GitHub Actions tends to cancel all the jobs if one job fails.
Is there a way to change this behavior so all jobs will continue to run even if one has a failure? This can be helpful in pinpointing an issue with a specific version.
Adding fail-fast: false under strategy works fines for me! :)
name: CI
on: push
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x, 13.x]
fail-fast: false
steps:
- uses: actions/checkout#v2
- name: Use Node.js
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test