Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Jun 21, 2024
1 parent 3b04c3e commit 1cdf8a7
Show file tree
Hide file tree
Showing 19 changed files with 7,832 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This is the composite action:
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
#
# Composite actions have some limitations:
# - many contexts are unavailable, e.g. `runner`
# - `env` can be specified per-step only
# - if `run` is used, `shell` must be explicitly specified
name: 'Setup Node and install dependencies'
description: 'Setup Node and install dependencies using cache'
inputs:
node-version:
description: 'Node version'
required: true
os:
description: 'Composite actions do not support `runner.os`, so it must be passed in as an input'
required: true
runs:
using: 'composite'
steps:
- name: Calculate `CACHE_KEY`
shell: bash
run: |
echo 'CACHE_KEY=node_modules-${{
inputs.os
}}-${{
inputs.node-version
}}-${{
hashFiles('package-lock.json', 'package.json')
}}' >> "$GITHUB_ENV"
- name: Restore `node_modules`
id: node-modules-restore
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: node_modules
key: ${{ env.CACHE_KEY }}
enableCrossOsArchive: true

- name: Calculate `CACHE_HIT`
shell: bash
run: |
echo 'CACHE_HIT=${{
(steps.node-modules-restore.outputs.cache-hit == 'true') && 'true' || ''
}}' >> "$GITHUB_ENV"
- name: Setup Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
registry-url: 'https://registry.npmjs.org'
node-version: ${{ inputs.node-version }}
cache: ${{ env.CACHE_HIT != 'true' && 'npm' || '' }}

- name: Install dependencies
if: env.CACHE_HIT != 'true'
run: npm ci --no-audit --no-fund --progress=false
shell: bash

- name: Write `node_modules` cache
if: env.CACHE_HIT != 'true'
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: node_modules
key: ${{ env.CACHE_KEY }}
enableCrossOsArchive: true
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish

on:
release:
types:
- published

env:
NODE_VERSION: 18

permissions:
id-token: write

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Setup Node and install dependencies
uses: ./.github/actions/setup-node
with:
node-version: ${{ env.NODE_VERSION }}
os: ${{ runner.os }}

- name: Build
run: npm run build

- name: Publish
run: npm publish --verbose --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test

on:
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- main

env:
NODE_VERSION: 18

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}

name: test-${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Setup Node and install dependencies
uses: ./.github/actions/setup-node
with:
node-version: ${{ env.NODE_VERSION }}
os: ${{ runner.os }}

- name: Test
run: npm test
shell: bash
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.coverage
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
!/dist/
!/package.json
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
loglevel=silent
save-exact=true
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
9 changes: 9 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
);
14 changes: 14 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
coverageDirectory: './.coverage/',
coverageThreshold: {
'./src/manager': {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
};
Loading

0 comments on commit 1cdf8a7

Please sign in to comment.