Please describe the behavior you are expecting
What is the current behavior?
When utilizing nx tools like affected:test and affected:build within a github action, it always returns "no affected projects to run". I cannot find any information on why this functionality would not work from within a github action.
running nx 8.3.
Sorry, I'm afraid I am not too familiar with Github Actions but I will try to answer anyways.
By default, affected compares to master. If your action runs on the latest commit of master.. there are no differences to affect projects.
I assume you want to use Github actions for things like pull requests.
Github seems to provide some environment variables: https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables
The following are particularly interesting:
GITHUB_REF This is which branch/commit the PR is based onGITHUB_SHA This is the commit of the PRThese values may or may not be set to helpful values depending on the type of action: https://developer.github.com/actions/managing-workflows/workflow-configuration-options/#events-supported-in-workflow-files
When they are defined, you would probably want to run affected with --base $GITHUB_REF --head $GITHUB_SHA.
@jimdubbs any progress with this?
@jimdubbs this works... Uses the target branch when is a MR and the previous commit in the case of push event 馃槃
name: ci
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [10.x, 12.x]
os: [ubuntu-18.04, windows-2019, macOS-10.14]
steps:
- uses: actions/checkout@v1
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: |
npm install
- name: Run lint
shell: bash
run: |
if [[ $GITHUB_BASE_REF ]]
then
export NX_BASE=remotes/origin/$GITHUB_BASE_REF
else
export NX_BASE=$(git rev-parse HEAD~1)
fi
echo "Base => $NX_BASE"
npm run format:check -- --base=$NX_BASE
npm run affected:lint -- --base=$NX_BASE
@gperdomor thank you!
It looks like there is a way to get the base SHA. So I'm going to close this issue.
Sadly, this approach does not work with the actions/checkout@v2, had to revert back to the first version and it works.
Will investigate this further
Thank you @gperdomor
Most helpful comment
@jimdubbs this works... Uses the target branch when is a MR and the previous commit in the case of push event 馃槃