Skip to content

Commit dfcb1b3

Browse files
authored
Fix CI failure (#123)
1 parent 21121a1 commit dfcb1b3

18 files changed

+2613
-30
lines changed

.eslintrc.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"es6": true
5+
},
6+
"extends": [
7+
"google"
8+
],
9+
"globals": {
10+
"Atomics": "readonly",
11+
"SharedArrayBuffer": "readonly"
12+
},
13+
"parserOptions": {
14+
"ecmaVersion": 2022,
15+
"sourceType": "module"
16+
},
17+
"rules": {
18+
"block-spacing": ["error", "always"],
19+
"comma-dangle": "off",
20+
"indent": ["error", 2],
21+
"linebreak-style": "off",
22+
"no-unused-vars": [
23+
"error",
24+
{
25+
"args": "after-used",
26+
"varsIgnorePattern": "FaxInstance",
27+
"ignoreRestSiblings": false,
28+
"vars": "all"
29+
}
30+
],
31+
"object-curly-spacing": "off",
32+
"require-jsdoc": "off",
33+
"semi": "off"
34+
}
35+
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
---
2-
name: Functional Tests
2+
name: Functional Tests (Local)
33

44
on:
5-
push:
6-
branches:
7-
- 'main'
85
pull_request:
96

107
jobs:
@@ -18,11 +15,11 @@ jobs:
1815
runs-on: ubuntu-latest
1916
steps:
2017
- uses: actions/checkout@v3
21-
- name: Setup COBOL
22-
uses: ./
18+
- uses: ./
2319
with:
2420
version: ${{ matrix.version }}
2521
- name: Validate script
2622
run: |
2723
cobc -x ./HelloWorld.cob
28-
[[ "$(./HelloWorld)" == "Hello World!" ]] || exit 1;
24+
[ "$(./HelloWorld)" = "Hello World!" ] || exit 1;
25+
shell: sh
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Functional Tests (Remote)
3+
4+
on:
5+
push:
6+
branches:
7+
- 'main'
8+
pull_request:
9+
10+
jobs:
11+
run-script:
12+
name: Run script
13+
timeout-minutes: 5
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
version: ['3.1.2', '3.0-rc1', '3.1-rc1', '3.1.1']
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: fabasoad/[email protected]
21+
with:
22+
version: ${{ matrix.version }}
23+
- name: Prepare script
24+
run: |
25+
echo 'HELLO * HISTORIC EXAMPLE OF HELLO WORLD IN COBOL' > HelloWorld.cob
26+
echo ' IDENTIFICATION DIVISION.' >> HelloWorld.cob
27+
echo ' PROGRAM-ID. HELLO.' >> HelloWorld.cob
28+
echo ' PROCEDURE DIVISION.' >> HelloWorld.cob
29+
echo ' DISPLAY "Hello World!".' >> HelloWorld.cob
30+
echo ' STOP RUN.' >> HelloWorld.cob
31+
shell: sh
32+
- name: Print file
33+
run: cat ./HelloWorld.cob
34+
shell: sh
35+
- name: Validate script
36+
run: |
37+
cobc -x ./HelloWorld.cob
38+
[ "$(./HelloWorld)" = "Hello World!" ] || exit 1;
39+
shell: sh
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Security Tests
3+
4+
on:
5+
push:
6+
branches:
7+
- 'main'
8+
pull_request:
9+
10+
jobs:
11+
codeql_tests:
12+
name: CodeQL
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
language: ['javascript']
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
21+
- name: Initialize CodeQL
22+
uses: github/codeql-action/init@v2
23+
with:
24+
languages: ${{ matrix.language }}
25+
- name: Autobuild
26+
uses: github/codeql-action/autobuild@v2
27+
- name: Perform CodeQL Analysis
28+
uses: github/codeql-action/analyze@v2

.github/workflows/unit-tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: Unit Tests
3+
4+
on:
5+
push:
6+
branches:
7+
- 'main'
8+
pull_request:
9+
10+
jobs:
11+
unit_tests:
12+
name: Lint and Test
13+
timeout-minutes: 5
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Cache node_modules
18+
id: cache
19+
uses: actions/cache@v3
20+
with:
21+
path: '**/node_modules'
22+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
23+
restore-keys: |
24+
${{ runner.os }}-yarn-
25+
- name: Compile
26+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
27+
run: yarn install --ignore-scripts
28+
- name: Lint
29+
run: yarn run lint
30+
- name: Unit tests
31+
run: yarn test
32+
if: github.ref != 'refs/heads/main'
33+
- name: Unit tests with coverage
34+
uses: paambaati/[email protected]
35+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
36+
env:
37+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
38+
with:
39+
coverageCommand: yarn test
40+
debug: true

.markdownlintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.nycrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"check-coverage": true,
3+
"branches": 100,
4+
"lines": 100,
5+
"functions": 100,
6+
"statements": 100,
7+
"extension": ["js"],
8+
"reporter": ["lcov","text","text-summary"]
9+
}

.pre-commit-config.yaml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
---
22
default_stages: ["commit"]
3-
exclude: ^\.gitleaks\.toml$
3+
exclude: ^(\.gitleaks\.toml|dist/.*\.js|coverage/.*)$
44
repos:
5+
- repo: local
6+
hooks:
7+
- id: build
8+
name: Build
9+
entry: yarn run build
10+
language: system
11+
pass_filenames: false
12+
verbose: true
13+
- id: test
14+
name: Unit tests
15+
entry: yarn test
16+
language: system
17+
pass_filenames: false
18+
verbose: true
19+
stages: ["push"]
520
# Security
621
- repo: https://github.com/Yelp/detect-secrets
722
rev: v1.4.0
@@ -13,6 +28,20 @@ repos:
1328
hooks:
1429
- id: gitleaks
1530
stages: ["commit", "push"]
31+
- repo: https://github.com/fabasoad/pre-commit-snyk
32+
rev: v0.2.0
33+
hooks:
34+
- id: snyk-test
35+
stages: ["push"]
36+
# TypeScript
37+
- repo: https://github.com/pre-commit/mirrors-eslint
38+
rev: v8.28.0
39+
hooks:
40+
- id: eslint
41+
args: ['--fix']
42+
files: \.[jt]sx?$
43+
types: [file]
44+
exclude: ^dist/.*\.js$
1645
# Markdown
1746
- repo: https://github.com/igorshubovych/markdownlint-cli
1847
rev: v0.32.2
@@ -31,7 +60,7 @@ repos:
3160
- id: yamllint
3261
# Other
3362
- repo: https://github.com/pre-commit/pre-commit-hooks
34-
rev: v4.3.0
63+
rev: v4.4.0
3564
hooks:
3665
- id: check-merge-conflict
3766
- id: check-json
@@ -44,3 +73,4 @@ repos:
4473
- id: trailing-whitespace
4574
ci:
4675
autofix_prs: false
76+
skip: [build, eslint, test]

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Setup COBOL (GnuCOBOL)
22

33
![GitHub release](https://img.shields.io/github/v/release/fabasoad/setup-cobol-action?include_prereleases)
4-
![Functional Tests](https://github.com/fabasoad/setup-cobol-action/workflows/Functional%20Tests/badge.svg)
4+
![Unit Tests](https://github.com/fabasoad/setup-cobol-action/workflows/Unit%20Tests/badge.svg)
5+
![Functional Tests](https://github.com/fabasoad/setup-cobol-action/workflows/Functional%20Tests%20(Remote)/badge.svg)
6+
![Security Tests](https://github.com/fabasoad/setup-cobol-action/workflows/Security%20Tests/badge.svg)
57
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/fabasoad/setup-cobol-action/main.svg)](https://results.pre-commit.ci/latest/github/fabasoad/setup-cobol-action/main)
8+
[![Maintainability](https://api.codeclimate.com/v1/badges/84d9008a0dc1a2c6f703/maintainability)](https://codeclimate.com/github/fabasoad/setup-cobol-action/maintainability)
9+
[![Test Coverage](https://api.codeclimate.com/v1/badges/84d9008a0dc1a2c6f703/test_coverage)](https://codeclimate.com/github/fabasoad/setup-cobol-action/test_coverage)
10+
[![Known Vulnerabilities](https://snyk.io/test/github/fabasoad/setup-cobol-action/badge.svg?targetFile=package.json)](https://snyk.io/test/github/fabasoad/setup-cobol-action?targetFile=package.json)
611

712
This action sets up a [GnuCOBOL](https://en.wikipedia.org/wiki/COBOL) programming
813
language.

__tests__/test-installer.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
const exec = require('@actions/exec');
2+
const fs = require('fs');
3+
const os = require('os');
4+
const path = require('path');
5+
6+
const { assert } = require('chai');
7+
const itParam = require('mocha-param');
8+
const sinon = require('sinon');
9+
10+
const {
11+
Installer,
12+
UnsupportedOSError,
13+
UnsupportedVersionError
14+
} = require('../src/installer');
15+
16+
const fixture = ['Darwin', 'Windows_NT'];
17+
18+
const validVersions = ['3.1.2', '3.0-rc1', '3.1-rc1', '3.1.1'];
19+
const invalidVersion = 'y50pgz2b';
20+
21+
describe('Test Installer class', () => {
22+
let fsChmodSyncStub;
23+
let execExecStub;
24+
let osTypeStub;
25+
26+
beforeEach(() => {
27+
fsChmodSyncStub = sinon.stub(fs, 'chmodSync');
28+
execExecStub = sinon.stub(exec, 'exec');
29+
osTypeStub = sinon.stub(os, 'type');
30+
});
31+
32+
itParam('should build correct exec file name for Linux OS (${value})',
33+
validVersions, (validVersion) => {
34+
osTypeStub.returns('Linux');
35+
36+
const installer = new Installer(validVersion);
37+
38+
const expected = 'install-cobol-linux.sh';
39+
const actual = installer._execFileName();
40+
assert.equal(expected, actual);
41+
});
42+
43+
itParam('should not build exec file name for ${value} OS', fixture,
44+
(osType) => {
45+
osTypeStub.returns(osType);
46+
47+
const installer = new Installer(validVersions[0]);
48+
49+
try {
50+
installer._execFileName();
51+
} catch (e) {
52+
if (e instanceof UnsupportedOSError) {
53+
return;
54+
}
55+
}
56+
// eslint-disable-next-line new-cap
57+
assert.Throw();
58+
});
59+
60+
itParam('should install correctly for Linux OS (${value})',
61+
validVersions, async (version) => {
62+
const execFileName = 'install-cobol-linux.sh';
63+
64+
osTypeStub.returns('Linux');
65+
66+
const installer = new Installer(version);
67+
await installer.install();
68+
69+
execExecStub.calledOnceWith(
70+
path.join(__dirname, execFileName),
71+
[version]
72+
);
73+
fsChmodSyncStub.calledOnceWith(path.join(__dirname, execFileName), '777');
74+
});
75+
76+
itParam('should not install for ${value} OS', fixture, async (osType) => {
77+
osTypeStub.returns(osType);
78+
79+
const installer = new Installer(validVersions[0]);
80+
try {
81+
await installer.install();
82+
} catch (e) {
83+
if (e instanceof UnsupportedOSError) {
84+
assert.isTrue(execExecStub.notCalled);
85+
assert.isTrue(fsChmodSyncStub.notCalled);
86+
return;
87+
}
88+
}
89+
// eslint-disable-next-line new-cap
90+
assert.Throw();
91+
});
92+
93+
it('should not install invalid version', async () => {
94+
osTypeStub.returns('Linux');
95+
96+
const installer = new Installer(invalidVersion);
97+
try {
98+
await installer.install();
99+
} catch (e) {
100+
if (e instanceof UnsupportedVersionError) {
101+
assert.isTrue(execExecStub.notCalled);
102+
assert.isTrue(fsChmodSyncStub.notCalled);
103+
return;
104+
}
105+
}
106+
// eslint-disable-next-line new-cap
107+
assert.Throw();
108+
});
109+
110+
afterEach(() => {
111+
sinon.restore();
112+
});
113+
});

0 commit comments

Comments
 (0)