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

chore: upgrade tasks to node 20 #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"guard-for-in": 2,
"import/no-unresolved": ["error"],
"import/no-duplicates": ["error"],
"import/first": "off",
"import/prefer-default-export": 0,
"max-nested-callbacks": [1, 4],
"max-classes-per-file": [0],
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '16', '14', '10' ]
node: [ '20', '16' ]
name: Node ${{ matrix.node }}

steps:
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '10.x'
node-version: '20.x'

Choose a reason for hiding this comment

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

Excuse my ignorance, I'm not really familiar with this repo and Github workflows.
But why the version is hard coded in here instead of "node-version: ${{ matrix.node }}" like on line 28?
If my question doesn't make sense, please feel free to ignore me :)

Copy link
Contributor Author

@lstocchi lstocchi Mar 31, 2025

Choose a reason for hiding this comment

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

There is no strong opinion to why a hard coded version is better than a matrix in this case and it could be changed. Obviously, in general cases, running many matrix tests is more expensive. In this case, the tests are minimal .... it just runs matrix on linux to identify some potential errors with a specific version of node (to see if some func has been deprecated/removed and the code break), and on win/Mac just targets the version which should be used at runtime.
I'm not working with azure devops anymore (I left this field 3+ years ago) so I'm not really updated about it but it seems they recommend node 20. This is why I changed it

Choose a reason for hiding this comment

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

Ah makes sense, much appreciated!

- run: npm run setup
- run: npm install
- run: npm run build
Expand All @@ -53,7 +53,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '10.x'
node-version: '20.x'
- run: npm run setup
- run: npm install
- run: npm run build
Expand Down
7,411 changes: 4,344 additions & 3,067 deletions package-lock.json

Large diffs are not rendered by default.

53 changes: 27 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"docs": "markserv .",
"pretest": "npm run compile",
"watch": "tsc -watch -p ./",
"lint": "node_modules/.bin/eslint . --ext .ts --quiet",
"lint": "npx eslint . --ext .ts --quiet",
"test": "ts-mocha -p tsconfig.json test/*.test.ts --timeout 5000 ${MOCHA_TAG}",
"test:report": "npm run test -- --reporter mocha-simple-html-reporter --reporter-options output=out/test-report.html",
"test:report:ci": "npm run test -- --reporter mocha-junit-reporter --reporter-options mochaFile=out/test-report.xml",
"prettier:base": "prettier --parser typescript --single-quote",
"prettier:check": "npm run prettier:base -- --list-different \"src/*.ts\" \"test/*.ts\"",
"prettier:write": "npm run prettier:base -- --write \"**/**/*.ts\"",
"copy-node-modules": "for i in `ls tasks` ; do copy-node-modules . tasks/$i; done",
"copy-utils-file": "cp src/oc-utils.json out/src/",
"copy-utils-file": "npx shx mkdir -p out/src && cp src/oc-utils.json out/src/",
"copy-task-utils": "for i in `ls tasks` ; do cp -r src/oc-utils.json tasks/$i/lib/; done",
"copy-task-lib": "for i in `ls tasks` ; do cp -r out/src/. tasks/$i/lib/; done",
"bump-task-version": "for i in `ls tasks` ; do TASK=$(cat tasks/$i/task.json | json -e 'this.version.Patch++'); echo \"$TASK\" > tasks/$i/task.json; done",
Expand Down Expand Up @@ -57,32 +57,32 @@
},
"homepage": "https://github.com/redhat-developer/openshift-vsts#readme",
"dependencies": {
"@types/q": "^1.5.1",
"@types/valid-url": "^1.0.2",
"adm-zip": "^0.4.13",
"argv-split": "^2.0.1",
"azure-pipelines-task-lib": "^3.1.7",
"azure-pipelines-tool-lib": "^1.3.2",
"@types/q": "^1.5.8",
"@types/valid-url": "^1.0.7",
"adm-zip": "^0.5.16",
"argv-split": "^3.2.1",
"azure-pipelines-task-lib": "^5.0.0",
"azure-pipelines-tool-lib": "^2.0.8",
"decompress": "^4.2.1",
"decompress-tar": "^4.1.1",
"decompress-targz": "^4.1.1",
"del-cli": "^5.0.0",
"node-fetch": "^2.6.7",
"del-cli": "^6.0.0",
"node-fetch": "^3.3.2",
"q": "^1.5.1",
"semver": "^7.1.3",
"semver": "^7.7.1",
"substituter": "^1.3.0",
"valid-url": "^1.0.9"
},
"devDependencies": {
"@types/chai": "^4.1.6",
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.7",
"@types/sinon": "^7.0.13",
"@types/uuid": "^8.3.0",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.10",
"@types/node": "^20.3.1",
"@types/sinon": "^17.0.3",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"chai": "^4.2.0",
"chai": "4.5.0",
"chai-fs": "^2.0.0",
"commit-message-validator": "^0.1.6",
"copy-node-modules": "^1.0.4",
Expand All @@ -91,19 +91,20 @@
"eslint-config-prettier": "^6.7.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-json": "^2.0.1",
"eslint-plugin-prettier": "^3.1.1",
"istanbul": "^0.4.5",
"mocha": "^6.0",
"mocha": "^7.0",
"mocha-jenkins-reporter": "^0.4.8",
"mocha-junit-reporter": "^1.18.0",
"mocha-simple-html-reporter": "^1.1.0",
"prettier": "^1.14.3",
"mocha-junit-reporter": "^2.2.1",
"mocha-simple-html-reporter": "^2.0.0",
"prettier": "^3.5.1",
"remap-istanbul": "^0.13.0",
"sinon": "^7.4.2",
"ts-mocha": "^6.0",
"ts-node": "^7.0.1",
"typescript": "^4.0.2"
"shx": "^0.3.4",
"sinon": "^19.0.2",
"ts-mocha": "^10.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
}
}
11 changes: 5 additions & 6 deletions src/config-map-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { RunnerHandler } from './oc-exec';
import { InstallHandler } from './oc-install';
import * as auth from './oc-auth';
import { ConfigMap } from './config-map';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getAgentOsName, getReason } from './utils/exec_helper';

import task = require('azure-pipelines-task-lib/task');
import { RunnerHandler } from './oc-exec.ts';
import { InstallHandler } from './oc-install.ts';
import * as auth from './oc-auth.ts';
import { ConfigMap } from './config-map.ts';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getAgentOsName, getReason } from './utils/exec_helper.ts';

async function run(): Promise<void> {
const version = task.getInput('version');
Expand Down
12 changes: 6 additions & 6 deletions src/oc-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import * as fs from 'fs';
import { RunnerHandler } from './oc-exec';
import path = require('path');

import task = require('azure-pipelines-task-lib/task');
import tl = require('azure-pipelines-task-lib/task');
import {
BASIC_AUTHENTICATION,
NO_AUTHENTICATION,
TOKEN_AUTHENTICATION,
RUNTIME_CONFIGURATION_OPTION,
} from './constants';

import task = require('azure-pipelines-task-lib/task');
import tl = require('azure-pipelines-task-lib/task');
import path = require('path');
} from './constants.ts';
import { RunnerHandler } from './oc-exec.ts';

export interface OpenShiftEndpoint {
/** URL to the OpenShiftServer */
Expand Down
8 changes: 2 additions & 6 deletions src/oc-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { IExecSyncResult } from 'azure-pipelines-task-lib/toolrunner';
import { ConditionStatus } from './utils/exec_helper';
import { RunnerHandler } from './oc-exec';
import { ConditionStatus } from './utils/exec_helper.ts';
import { RunnerHandler } from './oc-exec.ts';

export class ConditionHandler {

Expand Down Expand Up @@ -68,10 +68,6 @@ export class ConditionHandler {
return status;
}

static async sleep(ms: number):Promise<NodeJS.Timeout> {
return new Promise(resolve => setTimeout(resolve, ms));
}

static getConditionCommandListener(resource: string): string {
return `get ${resource} -o name --watch=true`;
}
Expand Down
11 changes: 5 additions & 6 deletions src/oc-conditional-exec-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { RunnerHandler } from './oc-exec';
import { InstallHandler } from './oc-install';
import * as auth from './oc-auth';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getReason, ConditionStatus, isFailed, isTimedOut, getAgentOsName } from './utils/exec_helper';
import { ConditionHandler } from './oc-condition';

import task = require('azure-pipelines-task-lib/task');
import { RunnerHandler } from './oc-exec.ts';
import { InstallHandler } from './oc-install.ts';
import * as auth from './oc-auth.ts';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getReason, ConditionStatus, isFailed, isTimedOut, getAgentOsName } from './utils/exec_helper.ts';
import { ConditionHandler } from './oc-condition.ts';

async function run(): Promise<void> {
const version = task.getInput('version');
Expand Down
9 changes: 4 additions & 5 deletions src/oc-exec-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { RunnerHandler } from './oc-exec';
import { InstallHandler } from './oc-install';
import * as auth from './oc-auth';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getAgentOsName, getReason } from './utils/exec_helper';

import task = require('azure-pipelines-task-lib/task');
import { RunnerHandler } from './oc-exec.ts';
import { InstallHandler } from './oc-install.ts';
import * as auth from './oc-auth.ts';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getAgentOsName, getReason } from './utils/exec_helper.ts';

async function run(): Promise<void> {
const version = task.getInput('version');
Expand Down
11 changes: 5 additions & 6 deletions src/oc-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import * as fs from 'fs';
import { ToolRunner, IExecSyncResult } from 'azure-pipelines-task-lib/toolrunner';
import * as toolLib from 'azure-pipelines-tool-lib/tool';
import * as semver from 'semver';
import { RunnerHandler } from './oc-exec';
import { LINUXV3, MACOSXV3, WINV3, LINUXV4, MACOSXV4, WINV4, OC_TAR_GZ, OC_ZIP, LATEST, ZIP, TAR_GZ } from './constants';
import { unzipArchive } from './utils/zip_helper';
import { BinaryVersion, FindBinaryStatus } from './utils/exec_helper';

import tl = require('azure-pipelines-task-lib/task');
import path = require('path');
import fetch = require('node-fetch');
import { RunnerHandler } from './oc-exec.ts';
import { LINUXV3, MACOSXV3, WINV3, LINUXV4, MACOSXV4, WINV4, OC_TAR_GZ, OC_ZIP, LATEST, ZIP, TAR_GZ } from './constants.ts';
import { unzipArchive } from './utils/zip_helper.ts';
import { BinaryVersion, FindBinaryStatus } from './utils/exec_helper.ts';

export class InstallHandler {
/**
Expand Down Expand Up @@ -268,6 +266,7 @@ export class InstallHandler {
let url = InstallHandler.ocBundleURL(version.value, osType, false);
let findURLofLatest = !url;
if (url) {
const { default: fetch } = await import('node-fetch'); // Dynamic import
// check if url is valid otherwise take the latest stable oc cli for this version
const response = await fetch(url, { method: 'HEAD' });
findURLofLatest = !response.ok;
Expand Down
7 changes: 3 additions & 4 deletions src/oc-setup-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { InstallHandler } from './oc-install';
import * as auth from './oc-auth';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getAgentOsName, getReason } from './utils/exec_helper';

import task = require('azure-pipelines-task-lib/task');
import { InstallHandler } from './oc-install.ts';
import * as auth from './oc-auth.ts';
import { BinaryVersion, convertStringToBinaryVersion, FindBinaryStatus, getAgentOsName, getReason } from './utils/exec_helper.ts';

async function run(): Promise<void> {
const version: string = task.getInput('version');
Expand Down
8 changes: 4 additions & 4 deletions tasks/config-map/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
}
],
"version": {
"Major": 3,
"Major": 4,
"Minor": 0,
"Patch": 2
"Patch": 1
},
"minimumAgentVersion": "2.144.0",
"minimumAgentVersion": "3.232.1",
"instanceNameFormat": "config-map $(message)",
"inputs": [
{
Expand Down Expand Up @@ -151,7 +151,7 @@
}
],
"execution": {
"Node10": {
"Node20_1": {
"target": "lib/config-map-task.js",
"workingDirectory": "$(currentDirectory)"
}
Expand Down
8 changes: 4 additions & 4 deletions tasks/oc-cmd/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
}
],
"version": {
"Major": 3,
"Major": 4,
"Minor": 0,
"Patch": 2
"Patch": 1
},
"minimumAgentVersion": "2.144.0",
"minimumAgentVersion": "3.232.1",
"instanceNameFormat": "oc-cmd $(message)",
"inputs": [
{
Expand Down Expand Up @@ -138,7 +138,7 @@
}
],
"execution": {
"Node10": {
"Node20_1": {
"target": "lib/oc-exec-task.js",
"workingDirectory": "$(currentDirectory)"
}
Expand Down
8 changes: 4 additions & 4 deletions tasks/oc-conditional-cmd/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
}
],
"version": {
"Major": 3,
"Major": 4,
"Minor": 0,
"Patch": 2
"Patch": 1
},
"minimumAgentVersion": "2.144.0",
"minimumAgentVersion": "3.232.1",
"instanceNameFormat": "Oc Conditional Cmd",
"inputs": [
{
Expand Down Expand Up @@ -178,7 +178,7 @@
}
],
"execution": {
"Node10": {
"Node20_1": {
"target": "lib/oc-conditional-exec-task.js",
"workingDirectory": "$(currentDirectory)"
}
Expand Down
8 changes: 4 additions & 4 deletions tasks/oc-setup/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
}
],
"version": {
"Major": 3,
"Major": 4,
"Minor": 0,
"Patch": 2
"Patch": 1
},
"minimumAgentVersion": "2.144.0",
"minimumAgentVersion": "3.232.1",
"instanceNameFormat": "oc-setup $(message)",
"inputs": [
{
Expand Down Expand Up @@ -112,7 +112,7 @@
}
],
"execution": {
"Node10": {
"Node20_1": {
"target": "lib/oc-setup-task.js",
"workingDirectory": "$(currentDirectory)"
}
Expand Down
2 changes: 0 additions & 2 deletions test/index.debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
useColors: true,
timeout: 50000,
slow: 50000
});
mocha.useColors(true);

const testsRoot = path.resolve(__dirname);

Expand Down
1 change: 0 additions & 1 deletion test/oc-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import * as Task from 'azure-pipelines-task-lib/task';
import path = require('path');

const chai = require('chai');
chai.use(require('chai-fs'));

const { expect } = chai;

Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noEmit": true,
"allowImportingTsExtensions": true,
"lib": [
"es2015"
],
Expand Down