Skip to content

Commit

Permalink
chore: update github actions (#328)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
hertzg and hertzg authored Jul 31, 2024
1 parent 370be6a commit fcbbee1
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 224 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
check-latest: true
node-version: ${{ inputs.nodeVersion }}
- uses: bahmutov/[email protected]
25 changes: 25 additions & 0 deletions .github/workflows/actions/sudoless-tcpdump/action.yaml
Original file line number Diff line number Diff line change
@@ -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*
12 changes: 4 additions & 8 deletions .github/workflows/jsdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 0 additions & 46 deletions .github/workflows/node-version.yml

This file was deleted.

101 changes: 16 additions & 85 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
67 changes: 17 additions & 50 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/test-lts-matrix.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
Loading

0 comments on commit fcbbee1

Please sign in to comment.