Skip to content

Commit

Permalink
Build project to test against nodejs versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bguerout committed Dec 10, 2023
1 parent a8b317d commit 2a0159d
Show file tree
Hide file tree
Showing 8 changed files with 903 additions and 834 deletions.
42 changes: 31 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,51 @@ on: [ push ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x, 16.x, 17.x, 18.x ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: 18.x
cache: npm
- run: npm ci
- run: npm test
- run: npm run lint
- run: npm run build
- run: cd build && tar -czf ../build.tar.gz *
- uses: actions/upload-artifact@v3
with:
name: built-project
path: build.tar.gz

test-legacy-versions:
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
node-version: [ 10.x, 12.x, 14.x, 15.x, 16.x, 17.x ]
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: actions/download-artifact@v3
with:
name: built-project
- run: mkdir -p build && tar -xzf build.tar.gz -C build
- run: npm --prefix build install
- run: npm --prefix build test

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: 18.x
- run: npm ci
- run: npm run coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: .coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
.nyc_output/
.coverage/
.idea/
build/
dist/
3 changes: 1 addition & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"extension": ["ts"],
"node-option": ["loader=ts-node/esm"]
"extension": ["ts"]
}
20 changes: 15 additions & 5 deletions .tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@
set -euo pipefail

readonly PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
readonly BUILD_DIR="${PROJECT_DIR}/build"
readonly DIST_DIR="${PROJECT_DIR}/dist"

rm -rf "${PROJECT_DIR}/dist"
rm -rf "${DIST_DIR}" "${BUILD_DIR}"
mkdir -p "${DIST_DIR}" "${BUILD_DIR}"

cd "${PROJECT_DIR}"

echo "Building oleoduc (esm version)..."
echo "Compiling oleoduc (esm version)..."
tsc -p tsconfig.json
cat >"./dist/mjs/package.json" <<!EOF
cat >"${DIST_DIR}/mjs/package.json" <<!EOF
{
"type": "module"
}
!EOF

echo "Building oleoduc (cjs version)..."
echo "Compiling oleoduc (cjs version)..."
tsc -p tsconfig.cjs.json
cat >"./dist/cjs/package.json" <<!EOF
cat >"${DIST_DIR}/cjs/package.json" <<!EOF
{
"type": "commonjs"
}
!EOF

echo "Building oleoduc for test..."
tsc -p tsconfig.test.json
echo "Patching package.json to be able to run tests against previous versions of nodejs..."
cp "${PROJECT_DIR}/package.json" "${BUILD_DIR}"
npx json -I -f "${BUILD_DIR}/package.json" -e 'this.scripts.test="mocha --recursive --exit test/**/*-test.js"'
npx json -I -f "${BUILD_DIR}/package.json" -e 'this.devDependencies.mocha="9.x"'

cd -

Loading

0 comments on commit 2a0159d

Please sign in to comment.