Skip to content

Commit

Permalink
Use binaries for CI testing 😋
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <[email protected]>
  • Loading branch information
zFernand0 committed Nov 4, 2021
1 parent dbef8dc commit 088cc71
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 24 deletions.
27 changes: 27 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# GitHub Workflows

General information about GH Workflows

### Using `act`

1. Read about it: https://github.com/nektos/act (Requires Docker)
2. Install it https://github.com/nektos/act#installation
3. Run: `act --eventpath .github/_act_event.json --workflows .github/workflows/zowe-cli.yml --verbose --reuse`
- Equivalent: `act -vre .github/_act_event.json -W .github/workflows/zowe-cli.yml`
4. After it fails the first time, Copy the `zowe.tgz` file from the Build-Linux container to the Cross-Platform-Test container
- `docker cp act-Zowe-CLI-Build-Linux:/root/gh/zowe/zowe-cli/zowe.tgz .`
- `docker cp zowe.tgz act-Zowe-CLI-Cross-Platform-Test:/root/gh/zowe/zowe-cli/`
5. Run: `act -re .github/_act_event.json -W .github/workflows/zowe-cli.yml`

`100.` To start from scratch, just remove the containers
- `docker rm act-Zowe-CLI-Build-Linux --force`
- `docker rm act-Zowe-CLI-Cross-Platform-Test --force`

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

`0.` The first time (i.e. when it is supposed to fail) 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 manually copy the zowe.tgz). <br/>
`2.` `nektos/act` only works with linux distros. <br/>
`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/>
9 changes: 9 additions & 0 deletions .github/_act_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"head_commit": {
"message": "test"
},
"inputs": {
"binary-type": "debug"
},
"run_with_act": true
}
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
125 changes: 108 additions & 17 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,66 +12,157 @@ 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:
build-linux:
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
if: (!github.event.run_with_act)
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

test:
name: Cross-Platform Test
runs-on: ${{ matrix.os }}
needs: build-linux
strategy:
fail-fast: false
matrix:
node-version: [12.x, 14.x, 16.x]
os: [windows-latest, ubuntu-latest, macos-latest]
# node-version: [12.x, 14.x, 16.x]
# os: [windows-latest, ubuntu-latest, macos-latest]
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@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' && !github.event.run_with_act
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
# run: |
# mkdir -p $HOME/.zowe/_bin
# tar -xvzf zowe.tgz -C $HOME/.zowe/_bin
# ${{ github.event.run_with_act && 'export PATH=$HOME/.zowe/_bin:$PATH' || 'echo "$HOME/.zowe/_bin" >> $GITHUB_PATH' }}

- name: Unit Tests
id: unit
if: ${{ always() && steps.build.outcome == 'success' }}
run: npm run test:unit >> file.txt
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' }}
run: npm run test:integration >> file.txt
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' }}
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__/
path: |
__tests__/__results__/
unit-tests.txt
integration-tests.txt
- name: Upload Results to Codecov
if: ${{ always() && steps.build.outcome == 'success' }}
if: ${{ always() && steps.build.outcome == 'success' }} && !github.event.run_with_act
uses: codecov/[email protected]
with:
env_vars: OS,NODE
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")}`;

// Return the test environment including working directory that the tests should be using
return result;
Expand Down
1 change: 1 addition & 0 deletions zowex/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ fn is_daemon_running() -> DaemonProcInfo {
sys.refresh_all();
for (pid, process) in sys.processes() {
if process.name().to_lowercase().contains("node") &&
process.cmd().len() > 0 &&
process.cmd()[1].to_lowercase().contains("@zowe") &&
process.cmd()[1].to_lowercase().contains("cli") &&
process.cmd()[2].to_lowercase() == "--daemon"
Expand Down

0 comments on commit 088cc71

Please sign in to comment.