Closed cdb closed 4 years ago
Great, if you look at the logs now, you'll notice that multiple builds will exist: 4 build to be exact! That's because for each of the 2 operating systems we're running tests against 2 versions so: 2 OS :heavy_multiplication_x: 2 Node.js versions = 4 builds.
Our custom workflow now accounts for:
Let's now try to create a dedicated test job. This will allow us to separate the build and test functions of our workflow.
Create a new job called "test" as follows (we'll use ellipses ...
to only show the parts of the workflow we're interested in, but you should not copy the ellipses directly):
name: Node CI
on: [push]
jobs:
build:
...
test:
...
build
job, include the following portions of your existing workflow:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: npm install and build webpack
run: |
npm install
npm run build
test
job, include the following portions of your existing workflow:
test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-lastest, windows-2016]
node-version: [8.x, 10.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, and test
run: |
npm install
npm test
env:
CI: true
When you commit to this branch, the workflow should run again. I'll respond when it is finished running.
Great! We've now got two nicely separated build
and test
jobs. Our custom workflow now accounts for:
If you'd like to learn more about jobs, see:
jobs
No action required in this step - just waiting. I'll respond when the workflow runs your jobs.
The workflow has finished running!
You may notice build
succeeded, but each of the test
jobs failed. That's because the build artifacts created in build
aren't available to the test
job. Each job executes in a fresh instance of the virtual environment. This is due to the design of the virtual environments themselves.
So what do we do when we need the work product of one job in another? We can use the built-in artifact storage.
First, we'll need to save the artifacts created from build
. We can use an action built by GitHub to do this: actions/upload-artifacts
.
You can follow the manual steps below, or accept the suggestion in the following comment.
build
job that uses the upload-artifacts
action.
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: npm install and build webpack
run: |
npm install
npm run build
- uses: actions/upload-artifact@master
with:
name: webpack artifacts
path: public/
I'll respond when you commit to this branch.
Great! The build artifacts will now be uploaded to the artifact storage. If you wait for the workflow to finish, you'll notice the test
job still fails. This is for a number of reasons:
test
job needs to retrieve them.To remedy this, we'll run test
only after build
is finished so the artifacts are available, and we'll use another action built by GitHub, actions/download-artifact
to retrieve artifacts from the build
job.
You can follow the manual steps below, or accept the suggestions in the following comments.
test
job to run only after the build
job is completed (we'll use ellipses ...
to only show the parts of the workflow we're interested in, but you should not copy the ellipses directly):
test:
needs: build
runs-on: ubuntu-latest
...
test
job that uses the download-artifacts
action.
test:
needs: build
runs-on: ubuntu-latest
...
steps:
- uses: actions/checkout@v1
- uses: actions/download-artifact@master
with:
name: webpack artifacts
path: public
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, and test
run: |
npm install
npm test
env:
CI: true
I'll respond when you've edited your workflow file.
Let's go to the next step.
Matrix builds
Great work so far! By targeting specific versions of Node, we've configured a build matrix which allow us to test across multiple operating systems, platforms, and language versions. See Configuring a matrix build in GitHub Help if you'd like to learn more.
I'll respond when you commit the changes in the comment below.