Skip to content

Commit

Permalink
chore(pr): update project (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutsu3 authored Nov 15, 2024
1 parent 3487024 commit 89dd7cf
Show file tree
Hide file tree
Showing 14 changed files with 5,827 additions and 765 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Node.js CI

on:
push:
branches:
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
pull_request:
branches:
- main

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Install dependencies
run: npm ci
- name: Lint with ESLint
run: npm run lint
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
- name: Build and test
run: npm run build
- run: npm run test
- name: Upload coverage reports to Codecov
if: matrix.node-version == '20.x' && github.repository == 'tsutsu3/unbound-control-ts'
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
changelog:
name: Generate Changelog
runs-on: ubuntu-latest
if: startsWith(github.ref_name, 'release-v')
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Extract version from branch
id: extract_version
run: |
branch_name="${{ github.ref_name }}"
version="${branch_name#release-v}"
echo "version=v$version" >> $GITHUB_ENV
- name: Generate Changelog
run: |
git cliff --tag ${{ env.version }} --output CHANGELOG.md
git add CHANGELOG.md
git commit -m "chore: update CHANGELOG for version ${{ env.version }}"
git push origin ${{ github.ref_name }}
# After the PR is merged to the main branch, create a new tag and release
release:
name: Create Tag and Release
needs: test
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release-v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Extract version from branch
id: extract_version
run: |
branch_name=$(echo "${GITHUB_REF}" | awk -F'/' '{print $3}')
version=${branch_name#release-v}
echo "version=${version}" >> $GITHUB_ENV
- name: Generate Latest Changelog
run: |
git cliff --tag ${{ env.version }} --output CHANGELOG_DIFF.md --latest
- name: Create and push tag
run: |
git tag -a "v${{ env.version }}" -m "Release v${{ env.version }}"
git push origin "v${{ env.version }}"
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "v${{ env.version }}"
release_name: "Release v${{ env.version }}"
body_path: CHANGELOG_DIFF.md
draft: false
prerelease: false
publish:
needs: [release]
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release-v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?


coverage/
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
README.md
coverage/
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"trailingComma": "all",
"tabWidth": 2
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"markdown.extension.toc.levels": "1..3",
"markdown.extension.toc.orderedList": true,
"markdown.extension.toc.omittedFromToc": {
"README.md": ["## Table of Contents"]
},
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.formatOnPaste": true,
"files.eol": "\n"
}
2 changes: 2 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ filter_commits = false
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "newest"

tag_pattern = "v[0-9].*"
33 changes: 33 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import globals from "globals";
import tsParser from "@typescript-eslint/parser";
import eslintConfigPrettier from "eslint-config-prettier";

export default [
{
ignores: [
"dist",
"examples",
"vite.config.ts",
"eslint.config.mjs",
"jest.config.ts",
"coverage",
],
},
{
files: ["**/*.{js,mjs,cjs,ts}"],
languageOptions: {
parser: tsParser,
parserOptions: {
sourceType: "module",
project: "./tsconfig.eslint.json",
tsconfigRootDir: import.meta.dirname,
},
globals: globals.node,
},
},
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
eslintConfigPrettier,
];
Loading

0 comments on commit 89dd7cf

Please sign in to comment.