Skip to content

Commit

Permalink
Merge pull request #4 from Avivbens/improve-implementation
Browse files Browse the repository at this point in the history
improve implementation
  • Loading branch information
Avivbens authored May 29, 2024
2 parents b113559 + 8600577 commit a2e37a4
Show file tree
Hide file tree
Showing 18 changed files with 7,492 additions and 5,857 deletions.
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ coverage
packages
# don't line the docs
docs
.eslintrc.js
reset.d.ts
.eslintrc.cjs
reset.d.ts
commitlint.config.js
27 changes: 25 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
/**
* @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'],
extends: ['plugin:@typescript-eslint/recommended', 'eslint:recommended', 'plugin:prettier/recommended', 'prettier'],
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',
Expand All @@ -24,6 +36,8 @@ module.exports = {
endOfLine: 'auto',
},
],
'deprecation/deprecation': 'warn',
'unused-imports/no-unused-imports': 'error',
},
overrides: [
{
Expand All @@ -34,5 +48,14 @@ module.exports = {
'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',
},
},
],
}
11 changes: 2 additions & 9 deletions .github/workflows/health-check/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ inputs:
runs:
using: composite
steps:
- name: 🖥️ Setup Node
uses: actions/setup-node@v3
with:
node-version: 16

- name: 🔗 Install Dependencies
shell: bash
run: |
npm ci --no-fund --no-audit --ignore-scripts --force
- name: 🖥️ Setup Env
uses: ./.github/workflows/install

- name: 🧪 Test
if: ${{ inputs.run-tests == 'true' }}
Expand Down
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 --force
27 changes: 10 additions & 17 deletions .github/workflows/release-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ on:
branches:
- master

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

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

jobs:
Expand All @@ -23,14 +27,12 @@ jobs:

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

- name: 🧪 Check out repository code
uses: ./.github/workflows/health-check
with:
run-tests: 'false'

release:
name: 📦 Release Version
Expand All @@ -44,7 +46,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
Expand All @@ -54,14 +56,8 @@ jobs:
git config --global user.name "github-bot"
git config --global user.email "github-bot@gmail.com"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install Dependencies
run: |
npm ci --no-fund --no-audit --ignore-scripts --force
- name: 🖥️ Setup Env
uses: ./.github/workflows/install

- name: Build
run: npm run build
Expand All @@ -72,10 +68,7 @@ jobs:
- name: Release
env:
# This is required to make semantic-release work with GitHub Actions
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
# You can use this instead if no branch protection is enabled
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: github-bot
GIT_AUTHOR_EMAIL: github-bot@gmail.com
GIT_COMMITTER_NAME: github-bot
Expand Down
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
});
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
.DS_Store
.eslintcache
3 changes: 0 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run pre-commit
npx lint-staged
5 changes: 5 additions & 0 deletions .lintstagedrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
'*.{ts,cjs,js,json}': 'npx eslint --cache --fix',
'**/*': 'npx prettier --cache --write --ignore-unknown',
'package.json': 'npx sort-package-json',
}
12 changes: 11 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "all",
"semi": false,
"printWidth": 120,
"importOrder": ["^@.*/(.*)$", "^[./]"],
"importOrderSeparation": false,
"importOrderSortSpecifiers": true
"importOrderSortSpecifiers": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"overrides": [
{
"files": ["*.ts"],
"options": {
"importOrderParserPlugins": ["typescript", "decorators-legacy"]
}
}
]
}
Loading

0 comments on commit a2e37a4

Please sign in to comment.