Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Avivbens committed Jun 1, 2024
0 parents commit da10769
Show file tree
Hide file tree
Showing 29 changed files with 14,307 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage
# don't lint the packages
packages
# don't line the docs
docs
.eslintrc.js
reset.d.ts
commitlint.config.js
61 changes: 61 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @type {import('eslint').Linter.Config}
*/
module.exports = {
$schema: 'http://json.schemastore.org/eslintrc',
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
ecmaVersion: 2020,
},
plugins: ['@typescript-eslint/eslint-plugin', 'jest', 'prettier', 'deprecation', 'unused-imports'],
extends: [
'plugin:@typescript-eslint/recommended',
'eslint:recommended',
'plugin:prettier/recommended',
'prettier',
'plugin:jsonc/recommended-with-jsonc',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
'no-unused-vars': 'off',
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
'deprecation/deprecation': 'warn',
'unused-imports/no-unused-imports': 'error',
},
overrides: [
{
files: ['*.spec.js'],
plugins: ['jest'],
extends: ['plugin:jest/recommended'],
rules: {
'jest/prefer-expect-assertions': 0,
},
},
{
files: ['*.json'],
parser: 'jsonc-eslint-parser',
extends: ['plugin:jsonc/recommended-with-jsonc'],
rules: {
'deprecation/deprecation': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
},
},
],
}
58 changes: 58 additions & 0 deletions .github/workflows/health-check/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
name: '☑️ Checks Pipeline'
description: 'Checks the codebase health'

inputs:
run-tests-command:
description: 'Run tests command, default is `npm test`'
default: 'npm test'
required: false

run-tests:
description: 'Run tests'
default: 'true'
required: false

run-lint-command:
description: 'Run linter command, default is `npm run lint`'
default: 'npm run lint'
required: false

run-lint:
description: 'Run lint'
default: 'true'
required: false

run-build-command:
description: 'Run build command, default is `npm run build`'
default: 'npm run build'
required: false

run-build:
description: 'Run build'
default: 'true'
required: false

runs:
using: composite
steps:
- name: 🖥️ Setup Env
uses: ./.github/workflows/install

- name: 🧪 Test
if: ${{ inputs.run-tests == 'true' }}
shell: bash
run: |
${{ inputs.run-tests-command }}
- name: 🔨 Build
if: ${{ inputs.run-build == 'true' }}
shell: bash
run: |
${{ inputs.run-build-command }}
- name: ✅ Lint
if: ${{ inputs.run-lint == 'true' }}
shell: bash
run: |
${{ inputs.run-lint-command }}
16 changes: 16 additions & 0 deletions .github/workflows/install/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: '☑️ Install deps'
description: 'Install dependencies and setup node'

runs:
using: composite
steps:
- name: 🖥️ Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: 🔗 Install Dependencies
shell: bash
run: |
npm ci --no-fund --no-audit --no-progress --ignore-scripts
22 changes: 22 additions & 0 deletions .github/workflows/pr-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: PR Health Checks 🐛
on:
pull_request:
branches:
- master

permissions: write-all

jobs:
PR-checks:
# https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/using-self-hosted-runners-in-a-workflow
runs-on: ubuntu-latest
name: PR Health Checks 🐛
steps:
- name: 📀 Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: 🧪 Check out repository code
uses: ./.github/workflows/health-check
77 changes: 77 additions & 0 deletions .github/workflows/release-master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
name: '📦 Create New Release'

on:
push:
branches:
- master

permissions:
contents: write
pull-requests: write
issues: write
deployments: write

concurrency:
group: release-master-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
checks:
name: ✅ Check for Release
runs-on: ubuntu-latest
timeout-minutes: 15

env:
HUSKY: 0

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: 🧪 Check out repository code
uses: ./.github/workflows/health-check

release:
name: 📦 Release Version
runs-on: ubuntu-latest
timeout-minutes: 60
needs:
- checks

env:
HUSKY: 0

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Git Config
run: |
git config --global user.name "github-bot"
git config --global user.email "[email protected]"
- name: 🖥️ Setup Env
uses: ./.github/workflows/install

- name: Build
run: npm run build

- name: Setup NPM
run: |
npm config -L user set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GIT_AUTHOR_NAME: github-bot
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: github-bot
GIT_COMMITTER_EMAIL: [email protected]
run: |
npx semantic-release
98 changes: 98 additions & 0 deletions .github/workflows/semantic-release-report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
name: Semantic Release Report 📝
on:
pull_request:
branches:
- master

permissions:
contents: write
issues: write
pull-requests: write

jobs:
PR-checks:
# https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/using-self-hosted-runners-in-a-workflow
runs-on: ubuntu-latest
name: Semantic Release Report 📝
steps:
- name: 📀 Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: 🖥️ Setup Env
uses: ./.github/workflows/install

- name: 🔬 Check Semantic Versioning
id: semantic-release
run: |
GITHUB_REF=${{ github.head_ref }}
npx semantic-release --no-ci --dry-run --plugins @semantic-release/commit-analyzer,@semantic-release/release-notes-generator --branches ${{ github.head_ref }} > output.txt
REPORT=$(cat output.txt | base64 -w 0)
VERSION=$(cat output.txt | \
grep "The next release version is" | \
node -e "console.log(require('fs').readFileSync(0, 'utf-8').match(/The next release version is (\d+\.\d+\.\d+(-beta\.\d+)?)/)?.[1] ?? '')")
echo "releaseNote=$REPORT" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: 📝 Report semantic versioning
uses: actions/github-script@v7
if: ${{ steps.semantic-release.outputs.releaseNote != '' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// build release note
const semanticReleaseOutput = Buffer.from('${{ steps.semantic-release.outputs.releaseNote }}', 'base64').toString('utf8');
const semanticReleaseLogMatch = /^[[0-9:\sAMPM]+\]\s\[semantic-release\].*$/;
const lines = semanticReleaseOutput.split('\n');
const lastSemanticReleaseLogIndex = [...lines]
.reverse()
.findIndex((line) => line.match(semanticReleaseLogMatch));
const nextVersion = '${{ steps.semantic-release.outputs.version }}';
const releaseNoteIndex = lines.length - lastSemanticReleaseLogIndex;
const releaseNote = lines.slice(releaseNoteIndex);
let res = releaseNote.join('\n');
if (!releaseNote.length || !res) {
res = '### No release note would be generated.';
}
const SEMANTIC_RELEASE_BODY_HEADER = '## 📝 Semantic Release Report';
const NEXT_VERSION_HEADER = `### 🚀 Next Version: ${nextVersion}`;
const body = [SEMANTIC_RELEASE_BODY_HEADER, NEXT_VERSION_HEADER, res].join('\n');
// get last comment
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// find comments to delete
const commentsToDelete = comments.data.filter((comment) =>
comment.body.startsWith(SEMANTIC_RELEASE_BODY_HEADER)
);
// delete comments
const prms = commentsToDelete.map((comment) =>
github.rest.issues.deleteComment({
comment_id: comment.id,
owner: context.repo.owner,
repo: context.repo.repo
})
);
await Promise.all(prms);
// create new comment for release note
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
/lib
.DS_Store
coverage
.eslintcache
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no -- commitlint --edit ${1}
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
4 changes: 4 additions & 0 deletions .lintstagedrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'*.{ts,cjs,js,json}': 'npx eslint --cache --fix',
'**/*': 'npx prettier --cache --write --ignore-unknown',
}
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test/**/*
**/test/**/*
**/mocks/**/*
**/*.mock.*
**/*.spec.*
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry=https://registry.npmjs.org/

2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
SECURITY.md
Loading

0 comments on commit da10769

Please sign in to comment.