From 463500da76e91718a4d513e2ed58c9852f063bcd Mon Sep 17 00:00:00 2001 From: msclock Date: Wed, 11 Oct 2023 11:41:10 +0800 Subject: [PATCH] chore: release and pre-commit Signed-off-by: msclock --- .editorconfig | 2 +- .github/workflows/ci.yml | 80 ++++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 70 +++++++++++++++++++++++++++++++++++ release.config.js | 71 +++++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .pre-commit-config.yaml create mode 100644 release.config.js diff --git a/.editorconfig b/.editorconfig index ca2b4d5..e9ea1b3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[*.{yml,json}] +[*.{yml,json,js}] indent_size = 2 [CMakeLists.txt] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9b0d361 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +name: CI + +on: + workflow_dispatch: + + push: + pull_request: + +jobs: + + pre-commit: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + ref: ${{ github.head_ref }} + + - name: Set up python + uses: actions/setup-python@v3 + + - name: Run pre-commit on codebase + uses: pre-commit/action@v3.0.0 + + - name: Auto commit action + uses: stefanzweifel/git-auto-commit-action@v4 + if: failure() + with: + commit_message: 'ci: auto fixes from pre-commit' + + release: + name: release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v4 + id: semantic + with: + semantic_version: 22.0.5 + branches: | + [ + '+([0-9])?(.{+([0-9]),x}).x', + 'master', + 'main', + 'next', + 'next-major', + { + name: 'beta', + prerelease: true + }, + { + name: 'alpha', + prerelease: true + } + ] + extra_plugins: | + @semantic-release/changelog + @semantic-release/git + @semantic-release/exec + @semantic-release/github + conventional-changelog-conventionalcommits + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # - name: Push updates to branch for major version + # if: steps.semantic.outputs.new_release_published == 'true' + # run: git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:refs/heads/v${{steps.semantic.outputs.new_release_major_version}} + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..72f5a0f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,70 @@ +# To use: +# +# pre-commit run -a +# +# Or: +# +# pre-commit install # (runs every time you commit in git) +# +# To update this file: +# +# pre-commit autoupdate +# +# See https://github.com/pre-commit/pre-commit + +fail_fast: false +exclude: | + (?x)( + ^(.vscode/.*) + ) +files: '' # set '' as default + +repos: + # Standard hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + args: [--maxkb=4096] + - id: check-case-conflict + - id: check-merge-conflict + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + + # Check yaml + - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.10.0 + hooks: + - id: pretty-format-yaml + args: + - --autofix + - --offset=2 + exclude: | + (?x)( + .copier-answers.yml + ) + + # Changes tabs to spaces + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.5.4 + hooks: + - id: remove-tabs + + # CMake formatting + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + additional_dependencies: [pyyaml] + types: [file] + files: (\.cmake|CMakeLists.txt)(.in)?$ + + # Check for spelling + - repo: https://github.com/codespell-project/codespell + rev: v2.2.5 + hooks: + - id: codespell + args: + - -L=lang + - --check-filenames diff --git a/release.config.js b/release.config.js new file mode 100644 index 0000000..317d235 --- /dev/null +++ b/release.config.js @@ -0,0 +1,71 @@ +module.exports = { + "dryRun": false, + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "angular", + "releaseRules": [ + { "breaking": true, "release": "major" }, + { "type": "feat", "release": "minor" }, + { "type": "fix", "release": "patch" }, + { "type": "style", "release": "patch" }, + { "type": "refactor", "release": "patch" }, + { "type": "perf", "release": "patch" }, + { "type": "revert", "release": "patch" }, + { "type": "chore", "scope": "deps", "release": "patch" }, + { "type": "build", "release": false }, + { "type": "ci", "release": false }, + { "type": "docs", "release": false }, + { "type": "test", "release": false }, + ], + "parserOpts": { + "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + }, + }, + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { "type": "feat", "section": "Features" }, + { "type": "fix", "section": "Bug Fixes" }, + { "type": "style", "section": "Style" }, + { "type": "refactor", "section": "Refactor" }, + { "type": "perf", "section": "Performance" }, + { "type": "revert", "section": "Reverts" }, + { "type": "chore", "scope": "deps", "section": "Dependencies" }, + { "type": "chore", "section": "Chores" }, + { "type": "build", "section": "Build" }, + { "type": "ci", "section": "CI" }, + { "type": "docs", "section": "Docs" }, + { "type": "test", "section": "Tests" }, + ], + }, + "parserOpts": { + "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + }, + }, + ] + ["@semantic-release/changelog", { "changelogFile": "CHANGELOG.md", }], + [ + "@semantic-release/exec", + { + "publishCmd": [ + "git tag -a -f v${nextRelease.version} --cleanup=whitespace -m '${nextRelease.notes}'", + "git push --force origin v${nextRelease.version}" + ].join(" && "), + } + ], + "@semantic-release/github", + [ + "@semantic-release/git", + { + "assets": ["CHANGELOG.md"], + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}", + }, + ], + ] +};