Skip to content

📦 Package › Tests #8

📦 Package › Tests

📦 Package › Tests #8

Workflow file for this run

# #
# @type github workflow
# @author Aetherinox
# @url https://github.com/Aetherinox
# @usage performs tests on the NodeJS package noxenv
#
# @secrets secrets.SELF_TOKEN self github personal access token (fine-grained)
# secrets.SELF_TOKEN_CL self github personal access token (classic)
# secrets.NPM_TOKEN self npmjs access token
# secrets.PYPI_API_TOKEN self Pypi API token (production site) - https://pypi.org/
# secrets.PYPI_API_TEST_TOKEN self Pypi API token (test site) - https://test.pypi.org/
# secrets.SELF_DOCKERHUB_TOKEN self Dockerhub token
# secrets.CODECOV_TOKEN codecov upload token for nodejs projects
# secrets.MAXMIND_GELITE_TOKEN maxmind API token
# secrets.CF_ACCOUNT_ID cloudflare account id
# secrets.CF_ACCOUNT_TOKEN cloudflare account token
# secrets.ORG_TOKEN org github personal access token (fine-grained)
# secrets.ORG_TOKEN_CL org github personal access token (classic)
# secrets.ORG_DOCKERHUB_TOKEN org dockerhub secret
# secrets.ORG_GITEA_TOKEN org gitea personal access token (classic) with package:write permission
# secrets.BOT_GPG_KEY_ASC bot gpg private key (armored) | BEGIN PGP PRIVATE KEY BLOCK
# secrets.BOT_GPG_KEY_B64 bot gpg private key (binary) converted to base64
# secrets.BOT_GPG_PASSPHRASE bot gpg private key passphrase
# secrets.DISCORD_WEBHOOK_CHAN_GITHUB_RELEASES discord webhook to report release notifications from github to discord
# secrets.DISCORD_WEBHOOK_CHAN_GITHUB_WORKFLOWS discord webhook to report workflow notifications from github to discord
# secrets.DISCORD_WEBHOOK_CHAN_GITHUB_UPDATES discord webhook to report activity notifications from github to discord
#
# @local these workflows can be tested locally through the use of `act`
# https://github.com/nektos/act
# Extract act to folder
# Add system env var with path to act.exe
# Run the commands:
# git pull https://github.com/username/repo
# act -W .github/workflows/package-tests.yml -P ubuntu-latest=catthehacker/ubuntu:full-22.04
# act -W .github/workflows/package-tests.yml -s TOKEN_CL=XXXXXXXXXX --pull=false
# #
name: '📦 Package › Tests'
run-name: '📦 Package › Tests'
on:
push:
branches:
- '+([0-9])?(.{+([0-9]),x}).x'
- 'main'
- '!all-contributors/**'
pull_request:
workflow_dispatch:
jobs:
job-tests-run:
name: >-
📦 Test
if: |
${{ !contains(github.head_ref, 'all-contributors') }}
strategy:
matrix:
os: [windows-latest, macOS-latest, ubuntu-latest]
node-version: [16.x, 18.x, 20.x, 21.x, 22.x]
runs-on: ${{ matrix.os }}
env:
CI: true
permissions:
contents: write
packages: write
steps:
# #
# Job > Tests > Fix Line Endings
# #
- name: '🛒 Fix Git Checkout Line Endings'
id: task_tests_git-fixlines
run: |
git config --global core.autocrlf input
# #
# Job > Tests > Checkout
# #
- name: '☑️ Checkout'
id: task_tests_run_checkout
uses: actions/checkout@v4
# #
# Job > Tests > Cancel existing runs
# #
- name: '🛑 Cancel Previous Runs'
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ secrets.ADMINSERV_TOKEN_CL }}
# #
# Job > Tests > Setup Node
# #
- name: '⚙️ Setup Node'
id: task_tests_node_setup
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org/'
always-auth: true
scope: '@aetherinox'
# #
# Job > Tests > Get NPM Cache Directory
#
# must set `shell:bash` otherwise command will fail on Windows runner.
# bash can be used for both Linux and Windows
# #
- name: '📂 Get NPM Cache Directory'
id: task_tests_npm_cache_dir_get
shell: bash
run: |
cacheDir=$(npm config get cache)
echo "dir=$cacheDir" >> $GITHUB_OUTPUT
# #
# Job > Tests > NPM Cache
# #
- name: '📑 NPM cache'
id: task_tests_npm_cache_dir_run # use this to check for `cache-hit` ==> if: steps.task_tests_npm_cache_dir_run.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{ steps.task_tests_npm_cache_dir_get.outputs.dir }}
key: ${{ runner.OS }}-node-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.OS }}-node-
# #
# Job > Tests > NPM Install
# #
- name: '📦 NPM › Install'
id: task_tests_npm_install
run: |
npm install
# #
# Job > Tests > NPM Pretty and Linter
# #
- name: '📦 NPM › Pretty & Linter'
id: task_tests_npm_prettylint
run: |
npm run pretty
npm run lint
# #
# Job > Tests > Run Validation Script
# #
- name: '▶️ Run Build'
run: |
npm run validate
# #
# Job > Tests > Upload Coverage to Codecov
# #
- name: '📝 Upload Coverage Reports › Codecov'
id: task_tests_codecov_upload
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Aetherinox/noxenv
env_vars: CI_OS,NODE_VERSION
env:
CI_OS: ${{ matrix.os }}
NODE_VERSION: ${{ matrix.node-version }}
# #
# JOB > TESTS > COMPLETE
# #
job-tests-complete:
name: >-
📦 Tests › Complete
needs: job-tests-run
runs-on: ubuntu-latest
steps:
- name: '☑️ Tests Complete'
id: task_tests_complete
run: |
echo 'Tests passed'