From fcbbee17fe098f5ceb972f9bcb04511d483660f4 Mon Sep 17 00:00:00 2001 From: George Hertz Date: Wed, 31 Jul 2024 19:21:50 +0200 Subject: [PATCH] chore: update github actions (#328) * chore: update GitHub Actions workflows for testing on LTS versions and specific OS * chore: update pr action * chore: update conditions * chore: changes * chore: changes * chore: changes * chore: allow github script to encode * chore: composite * chore: composit * fix: checkout first * chore: better names * chore: move tsd out * chore: trying out stuff * chore: trying out stuff * fix: add shell * chore: playing around with names * chore: job names * fix: codecov * chore: fixes * fix: oops * feat: codecov comments * chore: codecov comments * chore: update other workflows as well * fix: jsdoc updates --------- Co-authored-by: Giorgi Kotchlamazashvili <1886698+hertzg@users.noreply.github.com> --- .github/workflows/actions/setup/action.yaml | 16 +++ .../actions/sudoless-tcpdump/action.yaml | 25 +++++ .github/workflows/jsdoc.yml | 12 +-- .github/workflows/node-version.yml | 46 -------- .github/workflows/pull-request.yaml | 101 +++--------------- .github/workflows/release.yaml | 67 +++--------- .github/workflows/test-lts-matrix.yaml | 68 ++++++++++++ .github/workflows/test-run.yaml | 94 ++++++++++++++++ .github/workflows/test-tsd.yaml | 33 ++++++ codecov.yaml | 1 + package-lock.json | 57 +++++----- package.json | 4 +- 12 files changed, 300 insertions(+), 224 deletions(-) create mode 100644 .github/workflows/actions/setup/action.yaml create mode 100644 .github/workflows/actions/sudoless-tcpdump/action.yaml delete mode 100644 .github/workflows/node-version.yml create mode 100644 .github/workflows/test-lts-matrix.yaml create mode 100644 .github/workflows/test-run.yaml create mode 100644 .github/workflows/test-tsd.yaml diff --git a/.github/workflows/actions/setup/action.yaml b/.github/workflows/actions/setup/action.yaml new file mode 100644 index 00000000..403f5225 --- /dev/null +++ b/.github/workflows/actions/setup/action.yaml @@ -0,0 +1,16 @@ +name: Setup Node + install deps + +inputs: + nodeVersion: + description: 'Node (* for latest or 20, 18, ...)' + type: string + default: '*' + +runs: + using: composite + steps: + - uses: actions/setup-node@v4.0.3 + with: + check-latest: true + node-version: ${{ inputs.nodeVersion }} + - uses: bahmutov/npm-install@v1.10.2 diff --git a/.github/workflows/actions/sudoless-tcpdump/action.yaml b/.github/workflows/actions/sudoless-tcpdump/action.yaml new file mode 100644 index 00000000..b2d1da57 --- /dev/null +++ b/.github/workflows/actions/sudoless-tcpdump/action.yaml @@ -0,0 +1,25 @@ +name: Sudoless tcpdump + +inputs: + runsOn: + description: 'OS (ubuntu-latest, macos-latest, windows-latest, ...)' + required: true + type: string + +runs: + using: composite + steps: + - name: Setup sudoless tcpdump (linux only) + if: ${{ success() && startsWith(inputs.runsOn, 'ubuntu-') }} + shell: bash + run: | + sudo groupadd pcap + sudo usermod -a -G pcap $USER + sudo chgrp pcap /usr/bin/tcpdump + sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/tcpdump + + - name: Setup sudoless tcpdump (macos only) + if: ${{ success() && startsWith(inputs.runsOn, 'macos-') }} + shell: bash + run: | + sudo chown $(whoami):admin /dev/bpf* diff --git a/.github/workflows/jsdoc.yml b/.github/workflows/jsdoc.yml index c073c4b3..4e3e92f3 100644 --- a/.github/workflows/jsdoc.yml +++ b/.github/workflows/jsdoc.yml @@ -10,14 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Setup Node.js - uses: actions/setup-node@v2-beta - - - name: Checkout - uses: actions/checkout@v4 - - - name: Install dependencies - run: npm i + - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/setup + with: + nodeVersion: '*' - name: Build docs run: npm run build:docs diff --git a/.github/workflows/node-version.yml b/.github/workflows/node-version.yml deleted file mode 100644 index 09803321..00000000 --- a/.github/workflows/node-version.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: node-version - -on: - workflow_dispatch: - inputs: - node: - description: 'Node version' - default: '*' - os: - description: 'Runner OS' - default: 'ubuntu-latest' - -jobs: - test-integration: - runs-on: ${{ github.event.inputs.os }} - - steps: - - name: Setup sudoless tcpdump (linux only) - if: ${{ success() && startsWith(github.event.inputs.os, 'ubuntu-') }} - run: | - sudo groupadd pcap - sudo usermod -a -G pcap $USER - sudo chgrp pcap /usr/sbin/tcpdump - sudo setcap cap_net_raw,cap_net_admin=eip /usr/sbin/tcpdump - sudo ln -s /usr/sbin/tcpdump /usr/bin/tcpdump - - - name: Setup sudoless tcpdump (macos only) - if: ${{ success() && startsWith(github.event.inputs.os, 'macos-') }} - run: | - sudo chown $(whoami):admin /dev/bpf* - - - name: Setup Node - uses: actions/setup-node@v2-beta - with: - node-version: ${{ github.event.inputs.node }} - - - name: Checkout - uses: actions/checkout@v4 - - - name: Install dependencies (full) - run: | - npm i --prefer-offline --no-audit - npm list --depth=0 || true - - - name: Test (integration) - run: npm run test:integration diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 6a23d937..2e711dc8 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -7,99 +7,30 @@ on: jobs: lint-commit-message: + name: 'Lint commit message' runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - name: Setup Node - uses: actions/setup-node@v2-beta - - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 + - uses: ./.github/workflows/actions/setup + with: + nodeVersion: '*' - - uses: bahmutov/npm-install@v1 - - - name: Lint Commit Messages - uses: wagoid/commitlint-github-action@v6 + - uses: wagoid/commitlint-github-action@v6 env: NODE_PATH: ${{ github.workspace }}/node_modules test-tsd: - runs-on: ubuntu-latest - steps: - - name: Setup Node - uses: actions/setup-node@v2-beta - - - name: Checkout - uses: actions/checkout@v4 - - - uses: bahmutov/npm-install@v1 - - - name: Test TypeScript definitions - run: npm run test:tsd - - test-coverage: - runs-on: ubuntu-latest - - steps: - - name: Setup Node - uses: actions/setup-node@v2-beta - - - name: Checkout - uses: actions/checkout@v4 - - - uses: bahmutov/npm-install@v1 - - - name: Coverage - run: npm run coverage - - - name: Coverage Upload - continue-on-error: true - if: ${{ success() }} - uses: codecov/codecov-action@v4 - with: - file: ./coverage.lcov - - test-integration: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - node: # https://nodejs.org/en/about/releases/ - - '*' - - '20' - - '18' - - fail-fast: false - - steps: - - name: Setup sudoless tcpdump (linux only) - if: ${{ success() && startsWith(matrix.os, 'ubuntu-') }} - run: | - sudo groupadd pcap - sudo usermod -a -G pcap $USER - sudo chgrp pcap /usr/bin/tcpdump - sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/tcpdump - - name: Setup sudoless tcpdump (macos only) - if: ${{ success() && startsWith(matrix.os, 'macos-') }} - run: | - sudo chown $(whoami):admin /dev/bpf* - - - name: Setup Node - uses: actions/setup-node@v2-beta - with: - check-latest: true - node-version: ${{ matrix.node }} - - - name: Checkout - uses: actions/checkout@v4 - - - uses: bahmutov/npm-install@v1 - - - name: Test (integration) - run: npm run test:integration + name: 'Test: TSD' + uses: ./.github/workflows/test-tsd.yaml + + full-with-coverage: + name: 'Tests: Unit (+coverage) & Integration' + uses: ./.github/workflows/test-lts-matrix.yaml + with: + testUnit: test-with-coverage + testIntegration: test + secrets: inherit diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f3651683..9277fb00 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,61 +6,28 @@ on: - master jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - node: # https://nodejs.org/en/about/releases/ - - '*' - - '20' - - '18' - fail-fast: false - - steps: - - name: Setup Node - uses: actions/setup-node@v2-beta - with: - check-latest: true - node-version: ${{ matrix.node }} - - - name: Checkout - uses: actions/checkout@v4 - - - uses: bahmutov/npm-install@v1 - - - name: Allow sudoless tcpdump (linux only) - if: ${{ success() && startsWith(matrix.os, 'ubuntu-') }} - run: | - sudo groupadd pcap - sudo usermod -a -G pcap $USER - sudo chgrp pcap /usr/bin/tcpdump - sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/tcpdump - - - name: Allow sudoless tcpdump (macos only) - if: ${{ success() && startsWith(matrix.os, 'macos-') }} - run: | - sudo chmod o+r /dev/bpf* - - - name: Test (full) - run: npm run test + test-tsd: + name: 'Test: TSD' + uses: ./.github/workflows/test-tsd.yaml + + test-full: + name: 'Tests: Unit (+coverage) & Integration' + uses: ./.github/workflows/test-lts-matrix.yaml + with: + testUnit: test-with-coverage + testIntegration: test + secrets: inherit release: runs-on: ubuntu-latest - needs: - - test if: ${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'hertzg/node-net-keepalive' }} + needs: + - test-full steps: - - name: Setup Node - uses: actions/setup-node@v2-beta - - - name: Checkout - uses: actions/checkout@v4 - - - uses: bahmutov/npm-install@v1 + - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/setup + with: + nodeVersion: '*' - name: Release env: diff --git a/.github/workflows/test-lts-matrix.yaml b/.github/workflows/test-lts-matrix.yaml new file mode 100644 index 00000000..6a4f0122 --- /dev/null +++ b/.github/workflows/test-lts-matrix.yaml @@ -0,0 +1,68 @@ +name: 'test:lts-matrix' + +on: + workflow_dispatch: + inputs: + testUnit: + description: 'Units' + type: choice + options: + - skip + - test + - test-with-coverage + default: test + testIntegration: + description: 'Integrations' + type: choice + options: + - skip + - test + default: test + + workflow_call: + inputs: + testUnit: + type: string + default: test + testIntegration: + type: string + default: test + +jobs: + ltsVersions: + name: 'LTS Versions' + runs-on: ubuntu-latest + outputs: + nodeVersions: ${{ steps.nodeVersions.outputs.result }} + steps: + - uses: actions/github-script@v7.0.1 + id: nodeVersions + with: + script: | + const isNowWithin = (a, b) => { + const toDateNumber = date => Number(date.split('-').join('')); + const now = toDateNumber(new Date().toISOString().split('T')[0]); + return toDateNumber(a) <= now && now <= toDateNumber(b); + } + + const allVersions = await fetch('https://endoflife.date/api/node.json').then(r => r.json()); + const version = allVersions.filter(v => v.lts).filter(v => isNowWithin(v.lts, v.eol)).map(v => v.cycle) + return ['*', ...version] + + test-full: + needs: + - ltsVersions + strategy: + matrix: + runsOn: + - ubuntu-latest + - macos-latest + - windows-latest + nodeVersion: ${{ fromJson(needs.ltsVersions.outputs.nodeVersions) }} + uses: ./.github/workflows/test-run.yaml + with: + nodeVersion: ${{ matrix.nodeVersion }} + runsOn: ${{ matrix.runsOn }} + testUnit: ${{ inputs.testUnit }} + testIntegration: ${{ inputs.testIntegration }} + secrets: inherit diff --git a/.github/workflows/test-run.yaml b/.github/workflows/test-run.yaml new file mode 100644 index 00000000..0b466886 --- /dev/null +++ b/.github/workflows/test-run.yaml @@ -0,0 +1,94 @@ +name: 'test:run' + +on: + workflow_dispatch: + inputs: + runsOn: + description: 'OS (ubuntu-latest, macos-latest, windows-latest, ...)' + type: string + default: ubuntu-latest + nodeVersion: + description: 'Node (* for latest or 20, 18, ...)' + type: string + default: '*' + testUnit: + description: 'Units' + type: choice + options: + - skip + - test + - test-with-coverage + default: test + testIntegration: + description: 'Integrations' + type: choice + options: + - skip + - test + default: test + testTsd: + description: 'Definitions' + type: choice + options: + - skip + - test + default: test + + workflow_call: + inputs: + runsOn: + type: string + default: ubuntu-latest + nodeVersion: + type: string + default: '*' + testUnit: + type: string + default: skip + testIntegration: + type: string + default: skip + testTsd: + type: string + default: skip + +jobs: + unit: + name: 'Unit (node-${{ inputs.nodeVersion}}, ${{ inputs.runsOn }})' + if: ${{ inputs.testUnit != 'skip' }} + runs-on: ${{ inputs.runsOn }} + steps: + - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/setup + with: + nodeVersion: ${{ inputs.nodeVersion }} + + - if: ${{ inputs.testUnit == 'test' }} + run: npm run test:unit + + - if: ${{ inputs.testUnit == 'test-with-coverage' }} + run: npm run coverage + + - if: ${{ success() && inputs.testUnit == 'test-with-coverage' }} + continue-on-error: true + uses: codecov/codecov-action@v4.5.0 + with: + file: ./coverage.lcov + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + integration: + name: 'Integration (node-${{ inputs.nodeVersion}}, ${{ inputs.runsOn }})' + if: ${{ inputs.testIntegration != 'skip' }} + runs-on: ${{ inputs.runsOn }} + steps: + - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/setup + with: + nodeVersion: ${{ inputs.nodeVersion }} + + - uses: ./.github/workflows/actions/sudoless-tcpdump + with: + runsOn: ${{ inputs.runsOn }} + + - run: npm run test:integration diff --git a/.github/workflows/test-tsd.yaml b/.github/workflows/test-tsd.yaml new file mode 100644 index 00000000..1cbafa59 --- /dev/null +++ b/.github/workflows/test-tsd.yaml @@ -0,0 +1,33 @@ +name: 'test:tsd' + +on: + workflow_dispatch: + inputs: + runsOn: + description: 'OS (ubuntu-latest, macos-latest, windows-latest, ...)' + type: string + default: ubuntu-latest + nodeVersion: + description: 'Node (* for latest or 20, 18, ...)' + type: string + default: '*' + + workflow_call: + inputs: + runsOn: + type: string + default: ubuntu-latest + nodeVersion: + type: string + default: '*' + +jobs: + tsd: + runs-on: ${{ inputs.runsOn }} + steps: + - uses: actions/checkout@v4 + - uses: ./.github/workflows/actions/setup + with: + nodeVersion: ${{ inputs.nodeVersion }} + + - run: npm run test:tsd diff --git a/codecov.yaml b/codecov.yaml index 3e31ee18..29086d7a 100644 --- a/codecov.yaml +++ b/codecov.yaml @@ -2,3 +2,4 @@ coverage: parsers: javascript: enable_partials: yes +comment: true diff --git a/package-lock.json b/package-lock.json index e1bcd7f9..bf090262 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,10 +19,10 @@ "@semantic-release/git": "^10.0.0", "@types/node": "^20.0.0", "all-contributors-cli": "^6.19.0", - "better-docs": "^2.3.0", + "better-docs": "2.3.2", "concurrently": "^8.0.0", "husky": "^9.0.0", - "jsdoc": "^4.0.0", + "jsdoc": "^3.0.0", "mocha": "^10.0.0", "mockery": "^2.1.0", "nyc": "^17.0.0", @@ -1023,18 +1023,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@jsdoc/salty": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/@jsdoc/salty/-/salty-0.2.5.tgz", - "integrity": "sha512-TfRP53RqunNe2HBobVBJ0VLhK1HbfvBYeTC1ahnN64PWvyYyGebmMiPkuwvD9fpw2ZbkoPb8Q7mwy0aR8Z9rvw==", - "dev": true, - "dependencies": { - "lodash": "^4.17.21" - }, - "engines": { - "node": ">=v12.0.0" - } - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", @@ -5603,13 +5591,12 @@ } }, "node_modules/jsdoc": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.2.tgz", - "integrity": "sha512-e8cIg2z62InH7azBBi3EsSEqrKx+nUtAS5bBcYTSpZFA+vhNPyhv8PTFZ0WsjOPDj04/dOLlm08EDcQJDqaGQg==", + "version": "3.6.11", + "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.11.tgz", + "integrity": "sha512-8UCU0TYeIYD9KeLzEcAu2q8N/mx9O3phAGl32nmHlE0LpaJL71mMkP4d+QE5zWfNt50qheHtOZ0qoxVrsX5TUg==", "dev": true, "dependencies": { - "@babel/parser": "^7.20.15", - "@jsdoc/salty": "^0.2.1", + "@babel/parser": "^7.9.4", "@types/markdown-it": "^12.2.3", "bluebird": "^3.7.2", "catharsis": "^0.9.0", @@ -5622,6 +5609,7 @@ "mkdirp": "^1.0.4", "requizzle": "^0.2.3", "strip-json-comments": "^3.1.0", + "taffydb": "2.6.2", "underscore": "~1.13.2" }, "bin": { @@ -11911,6 +11899,12 @@ "node": ">=8" } }, + "node_modules/taffydb": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz", + "integrity": "sha512-y3JaeRSplks6NYQuCOj3ZFMO3j60rTwbuKCvZxsAraGYH2epusatvZ0baZYA01WsGqJBq/Dl6vOrMUJqyMj8kA==", + "dev": true + }, "node_modules/temp-dir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-3.0.0.tgz", @@ -13368,15 +13362,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "@jsdoc/salty": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/@jsdoc/salty/-/salty-0.2.5.tgz", - "integrity": "sha512-TfRP53RqunNe2HBobVBJ0VLhK1HbfvBYeTC1ahnN64PWvyYyGebmMiPkuwvD9fpw2ZbkoPb8Q7mwy0aR8Z9rvw==", - "dev": true, - "requires": { - "lodash": "^4.17.21" - } - }, "@nodelib/fs.scandir": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", @@ -16729,13 +16714,12 @@ } }, "jsdoc": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.2.tgz", - "integrity": "sha512-e8cIg2z62InH7azBBi3EsSEqrKx+nUtAS5bBcYTSpZFA+vhNPyhv8PTFZ0WsjOPDj04/dOLlm08EDcQJDqaGQg==", + "version": "3.6.11", + "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.11.tgz", + "integrity": "sha512-8UCU0TYeIYD9KeLzEcAu2q8N/mx9O3phAGl32nmHlE0LpaJL71mMkP4d+QE5zWfNt50qheHtOZ0qoxVrsX5TUg==", "dev": true, "requires": { - "@babel/parser": "^7.20.15", - "@jsdoc/salty": "^0.2.1", + "@babel/parser": "^7.9.4", "@types/markdown-it": "^12.2.3", "bluebird": "^3.7.2", "catharsis": "^0.9.0", @@ -16748,6 +16732,7 @@ "mkdirp": "^1.0.4", "requizzle": "^0.2.3", "strip-json-comments": "^3.1.0", + "taffydb": "2.6.2", "underscore": "~1.13.2" }, "dependencies": { @@ -21309,6 +21294,12 @@ } } }, + "taffydb": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz", + "integrity": "sha512-y3JaeRSplks6NYQuCOj3ZFMO3j60rTwbuKCvZxsAraGYH2epusatvZ0baZYA01WsGqJBq/Dl6vOrMUJqyMj8kA==", + "dev": true + }, "temp-dir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-3.0.0.tgz", diff --git a/package.json b/package.json index 02d823c7..47707eaf 100644 --- a/package.json +++ b/package.json @@ -60,10 +60,10 @@ "@semantic-release/git": "^10.0.0", "@types/node": "^20.0.0", "all-contributors-cli": "^6.19.0", - "better-docs": "^2.3.0", + "better-docs": "2.3.2", "concurrently": "^8.0.0", "husky": "^9.0.0", - "jsdoc": "^4.0.0", + "jsdoc": "^3.0.0", "mocha": "^10.0.0", "mockery": "^2.1.0", "nyc": "^17.0.0",