Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use binaries for CI testing 😋 #1196

Merged
merged 16 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# GitHub Workflows

General information about GH Workflows

### Using `act`

- Read it: https://github.com/nektos/act (Requires Docker)
- Install it https://github.com/nektos/act#installation
- Run it: `npm run test:act`
- Clean it: `npm run test:act -- --clean`

For more information, run: `npm run test:act -- --help`

**Known Issues for `nektos/[email protected]`**

`0.` The first time it will likely take ~3 minutes to run. Subsequent runs (with `--reuse`) should take less than 2 minutes. <br/>
`1.` Artifact upload and download doesn't work on `nektos/act` (hence why we need to copy the zowe.tgz to a shared Docker volume). <br/>
`2.` `nektos/act` only works with linux distros. <br/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nektos/act doc implies that it runs on windows. Is your statement due to the fact that nektos/act only hosts Linux docker images?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, I will rephrase that statement 👍
It should work fine on Windows, Linux, MacOS, and almost everywhere you can have Docker (e.g. Raspberry PI - armv7l) 😋

`3.` `Install Rust toolchain` step was replaced with simple `yum install cargo -y` because `actions-rs/toolchain@v1` doesn't really work with `nektos/act`. <br/>
`4.` Steps context (`steps.<id>`) doesn't really work on `nektos/act` (hence why we force unit and integration tests to run). <br/>
`5.` Pipeline cannot be stopped (`Ctrl+C`) during most steps unless you kill your docker daemon. <br/>
8 changes: 8 additions & 0 deletions .github/_act_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"head_commit": {
"message": "test"
},
"inputs": {
"binary-type": "debug"
}
}
139 changes: 139 additions & 0 deletions .github/_act_zowe-cli_example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Zowe CLI
'on':
push:
paths-ignore:
- zowex/**
- .github/workflows/rust-cli*.yml
pull_request:
paths-ignore:
- zowex/**
- .github/workflows/rust-cli*.yml
workflow_dispatch:
inputs:
binary-type:
description: Specify whether to use a `debug` or a `release` version of the binary
default: debug
required: false
jobs:
prebuild:
name: Build Linux
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64
if: '(github.event_name == ''push'' || github.event.pull_request.head.repo.full_name != github.repository) && !contains(github.event.head_commit.message, ''[ci skip]'')'
steps:
- uses: actions/checkout@v2
- name: Install Rust toolchain
if: (!github.event.run_with_act)
id: install-rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Rust toolchain
if: github.event.run_with_act
run: |
yum install cargo -y
cargo --version
- name: Build
run: 'cargo build --verbose ${{ github.event.inputs.binary-type == ''release'' && ''--release'' || '''' }} --manifest-path=zowex/Cargo.toml'
- name: Create Archive
run: 'tar -cvzf zowe.tgz -C zowex/target/${{ github.event.inputs.binary-type == ''release'' && ''release'' || ''debug'' }} zowe'
- name: Upload the Prebuilt Linux Binary
if: (!github.event.run_with_act)
uses: actions/upload-artifact@v2
with:
name: zowe-linux-latest.tgz
path: zowe.tgz
- name: Upload the Prebuilt Linux Binary
if: (github.event.run_with_act)
run: mkdir -p /toolcache/artifacts && cp zowe.tgz /toolcache/artifacts/zowe-linux-latest.tgz
test:
name: Cross-Platform Test
runs-on: '${{ matrix.os }}'
needs: prebuild
strategy:
fail-fast: false
matrix:
node-version:
- 16.x
os:
- ubuntu-latest
env:
OS: '${{ matrix.os }}'
NODE: '${{ matrix.node-version }}'
NODE_OPTIONS: '--max_old_space_size=4096'
if: '(github.event_name == ''push'' || github.event.pull_request.head.repo.full_name != github.repository) && !contains(github.event.head_commit.message, ''[ci skip]'')'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: 'Use Node.js ${{ matrix.node-version }}'
uses: actions/setup-node@v2
with:
node-version: '${{ matrix.node-version }}'
- name: Get NPM Version
id: npm-version
run: 'echo "::set-output name=number::$(npm --version)"'
- name: Use NPM v8
id: npm8
run: npm install -g npm@^8
- name: Install Node Package Dependencies
id: install
run: npm ci
- name: Use Original NPM Version
id: original-npm-version
run: 'npm install -g npm@${{ steps.npm-version.outputs.number }}'
- name: Build Source
id: build
run: npm run build --if-present
- name: Build Windows Binary
if: matrix.os == 'windows-latest'
run: |
cargo build --verbose ${{ github.event.inputs.binary-type == 'release' && '--release' || '' }} --manifest-path=zowex/Cargo.toml
tar -cvzf zowe.tgz -C zowex/target/${{ github.event.inputs.binary-type == 'release' && 'release' || 'debug' }} zowe.exe
- name: Build MacOS Binary
if: matrix.os == 'macos-latest'
run: |
cargo build --verbose ${{ github.event.inputs.binary-type == 'release' && '--release' || '' }} --manifest-path=zowex/Cargo.toml
tar -cvzf zowe.tgz -C zowex/target/${{ github.event.inputs.binary-type == 'release' && 'release' || 'debug' }} zowe
- name: Download Prebuilt Linux Binary
if: matrix.os == 'ubuntu-latest' && !github.event.run_with_act
uses: actions/download-artifact@v2
with:
name: zowe-linux-latest.tgz
- name: Download Prebuilt Linux Binary
if: matrix.os == 'ubuntu-latest' && github.event.run_with_act
run: cp /toolcache/artifacts/zowe-linux-latest.tgz zowe.tgz
- name: Archive Binary
if: matrix.os != 'ubuntu-latest'
id: upload-binary
uses: actions/upload-artifact@v2
with:
name: 'zowe-${{ matrix.os }}.tgz'
path: zowe.tgz
- name: Setup Binary in PATH
id: setup-binary
run: tar -xvzf zowe.tgz -C ./node_modules/.bin --overwrite
- name: Unit Tests
id: unit
if: '${{ always() && steps.build.outcome == ''success'' }} || github.event.run_with_act'
run: 'npm run test:unit >> unit-tests.txt'
- name: Integration Tests
id: integration
if: '${{ always() && steps.build.outcome == ''success'' }} || github.event.run_with_act'
run: 'npm run test:integration >> integration-tests.txt'
- name: Archive Results
id: upload
if: '${{ always() && steps.build.outcome == ''success'' }} && !github.event.run_with_act'
uses: actions/upload-artifact@v2
with:
name: '${{ matrix.os }}-${{ matrix.node-version }}-results'
path: |
__tests__/__results__/
unit-tests.txt
integration-tests.txt
- name: Upload Results to Codecov
if: '${{ always() && steps.build.outcome == ''success'' }} && !github.event.run_with_act'
uses: codecov/[email protected]
with:
env_vars: 'OS,NODE'
6 changes: 3 additions & 3 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
with:
node-version: 12.x

- name: Use NPM v7
id: npm7
run: npm install -g npm@^7
- name: Use NPM v8
id: npm8
run: npm install -g npm@^8

- name: Check Vulnerabilities
run: npm audit --production --audit-level=moderate
6 changes: 3 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
with:
node-version: 12.x

- name: Use NPM v7
id: npm7
run: npm install -g npm@^7
- name: Use NPM v8
id: npm8
run: npm install -g npm@^8

- name: Install Node Package Dependencies
run: npm ci
Expand Down
100 changes: 89 additions & 11 deletions .github/workflows/zowe-cli.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean install of node dependencies, 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: Zowe CLI CI
name: Zowe CLI

on:
push:
Expand All @@ -12,12 +12,50 @@ on:
paths-ignore:
- 'zowex/**'
- '.github/workflows/rust-cli*.yml'
workflow_dispatch:
inputs:
binary-type:
description: "Specify whether to use a `debug` or a `release` version of the binary"
default: "debug"
required: false

jobs:
test:
prebuild:
name: Build Linux
runs-on: ubuntu-latest

runs-on: ${{ matrix.os }}
# Need to build in container with old version of GLIBC to support RHEL 7
# https://kobzol.github.io/rust/ci/2021/05/07/building-rust-binaries-in-ci-that-work-with-older-glibc.html
container: quay.io/pypa/manylinux2014_x86_64

if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && !contains(github.event.head_commit.message, '[ci skip]')
steps:
- uses: actions/checkout@v2

- name: Install Rust toolchain
id: install-rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Build
run: cargo build --verbose ${{ github.event.inputs.binary-type == 'release' && '--release' || '' }} --manifest-path=zowex/Cargo.toml

- name: Create Archive
run: tar -cvzf zowe.tgz -C zowex/target/${{ github.event.inputs.binary-type == 'release' && 'release' || 'debug' }} zowe

- name: Upload the Prebuilt Linux Binary
uses: actions/upload-artifact@v2
with:
name: zowe-linux-latest.tgz
path: zowe.tgz

test:
name: Cross-Platform Test
runs-on: ${{ matrix.os }}
needs: prebuild
strategy:
fail-fast: false
matrix:
Expand All @@ -30,45 +68,85 @@ jobs:
NODE_OPTIONS: --max_old_space_size=4096

if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) && !contains(github.event.head_commit.message, '[ci skip]')

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Use NPM v7
id: npm7
run: npm install -g npm@^7
- name: Get NPM Version
id: npm-version
run: echo "::set-output name=number::$(npm --version)"

- name: Use NPM v8
id: npm8
run: npm install -g npm@^8

- name: Install Node Package Dependencies
id: install
run: npm ci

- name: Use Original NPM Version
id: original-npm-version
run: npm install -g npm@${{ steps.npm-version.outputs.number }}

- name: Build Source
id: build
run: npm run build --if-present

- name: Build Windows Binary
if: matrix.os == 'windows-latest'
run: |
cargo build --verbose ${{ github.event.inputs.binary-type == 'release' && '--release' || '' }} --manifest-path=zowex/Cargo.toml
tar -cvzf zowe.tgz -C zowex/target/${{ github.event.inputs.binary-type == 'release' && 'release' || 'debug' }} zowe.exe

- name: Build MacOS Binary
if: matrix.os == 'macos-latest'
run: |
cargo build --verbose ${{ github.event.inputs.binary-type == 'release' && '--release' || '' }} --manifest-path=zowex/Cargo.toml
tar -cvzf zowe.tgz -C zowex/target/${{ github.event.inputs.binary-type == 'release' && 'release' || 'debug' }} zowe

- name: Download Prebuilt Linux Binary
if: matrix.os == 'ubuntu-latest'
uses: actions/download-artifact@v2
with:
name: zowe-linux-latest.tgz

- name: Archive Binary
if: matrix.os != 'ubuntu-latest'
id: upload-binary
uses: actions/upload-artifact@v2
with:
name: zowe-${{ matrix.os }}.tgz
path: zowe.tgz

- name: Setup Binary in PATH
id: setup-binary
run: tar -xvzf zowe.tgz -C ./node_modules/.bin --overwrite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ./node_modules/.bin also be the location that the "zowe config daemon" command puts the zowe executable at a customer site?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ./node_modules/.bin will work for end users since the where/which zowe location depends on their installation/configuration of node and npm, e.g. using nvm.
For example:

  • /root/.nvm/versions/node/v16.12.0/bin/zowe
  • C:\Users\USER\scoop\apps\nvm\current\nodejs\nodejs\zowe
  • C:\Users\USER\AppData\Roaming\npm\zowe

Maybe something along the lines of "${process.env.ZOWE_CLI_HOME}/_bin" or "~/.zowe/_bin")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Makes sense. Many customers may not even have the privilege to write to those NodeJS locations when they run the "zowe config daemon" command.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note:
The location where we place the binary changed from ./node_modules/.bin to ./__tests__/__resources__/application_instances becuase of the TestEnvironment.setUp function. (see below)

result.env.PATH = `${nodePath.resolve(__dirname, "../../__resources__/application_instances")}${separator}${process.env.PATH}`;


- name: Unit Tests
id: unit
if: ${{ always() && steps.build.outcome == 'success' }}
run: npm run test:unit >> file.txt
run: npm run test:unit >> unit-tests.txt

- name: Integration Tests
id: integration
if: ${{ always() && steps.build.outcome == 'success' }}
run: npm run test:integration >> file.txt
run: npm run test:integration >> integration-tests.txt

- name: Archive Results
id: upload
if: ${{ always() && steps.build.outcome == 'success' }}
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }}-${{ matrix.node-version }}-results
path: __tests__/__results__/
path: |
__tests__/__results__/
unit-tests.txt
integration-tests.txt

- name: Upload Results to Codecov
if: ${{ always() && steps.build.outcome == 'success' }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ imperative_debug.log
/packages/cli/prebuilds
zowe.config.json
zowe.config.user.json
zowe.schema.json
zowe.schema.json
.github/_act_*.yml
2 changes: 1 addition & 1 deletion __tests__/__src__/environment/TestEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TestEnvironment extends BaseTestEnvironment {

// Ensure correct path separator for windows or linux like systems.
const separator = process.platform === "win32" ? ";" : ":";
result.env.PATH = `${nodePath.resolve(__dirname, "../../__resources__/application_instances")}${separator}${process.env.PATH}`;
result.env.PATH = `${process.env.PATH}${separator}${nodePath.resolve(__dirname, "../../__resources__/application_instances")}`;
zFernand0 marked this conversation as resolved.
Show resolved Hide resolved

// Return the test environment including working directory that the tests should be using
return result;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lint:tests": "eslint \"**/__tests__/**/*.ts\"",
"update:imperative": "npm i --save --save-exact @zowe/imperative@next && syncpack fix-mismatches --dev --prod --filter @zowe/imperative",
"test": "npm run test:unit && npm run test:integration && npm run test:system",
"test:act": "node scripts/testCliWorkflow.js",
"test:cleanResults": "rimraf __tests__/__results__",
"test:cleanUpProfiles": "sh __tests__/__scripts__/clean_profiles.sh",
"test:integration": "cross-env FORCE_COLOR=1 jest \".*__tests__.*\\**\\.integration\\.(spec|test)\\.ts\\$\" --coverage false",
Expand Down
Loading