From 0000000f08a0618d5a594f7eca924679ca00f3e9 Mon Sep 17 00:00:00 2001 From: hustcer Date: Wed, 29 Jan 2025 13:09:14 +0800 Subject: [PATCH] Initial commit --- .github/workflows/basic.yml | 73 ++++++++++++++++++++++++++++++++ .github/workflows/milestone.yaml | 34 +++++++++++++++ .gitignore | 1 + CHANGELOG.md | 3 ++ Justfile | 48 +++++++++++++++++++++ LICENSE | 21 +++++++++ README.md | 50 ++++++++++++++++++++++ README.zh-CN.md | 47 ++++++++++++++++++++ action.yaml | 42 ++++++++++++++++++ cliff.toml | 53 +++++++++++++++++++++++ cspell.yml | 10 +++++ lefthook.yml | 33 +++++++++++++++ meta.json | 10 +++++ nu/release.nu | 54 +++++++++++++++++++++++ nu/review.nu | 44 +++++++++++++++++++ 15 files changed, 523 insertions(+) create mode 100644 .github/workflows/basic.yml create mode 100644 .github/workflows/milestone.yaml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 Justfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 README.zh-CN.md create mode 100644 action.yaml create mode 100644 cliff.toml create mode 100644 cspell.yml create mode 100644 lefthook.yml create mode 100644 meta.json create mode 100644 nu/release.nu create mode 100644 nu/review.nu diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml new file mode 100644 index 000000000..d30a3f6 --- /dev/null +++ b/.github/workflows/basic.yml @@ -0,0 +1,73 @@ +# Description: +# - Setup Moonbit with GitHub Actions +# REF: +# - https://github.com/marketplace/actions/checkout + +name: Setup-Moonbit@Dev +on: + push: + branches: + - develop + + paths-ignore: + - '**.md' + +jobs: + setup-moonbit: + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + name: Setup MoonBit@${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Moonbit + uses: hustcer/setup-moonbit@develop + + - name: Check Moonbit Version + run: | + moon version --all + + setup-moonbit-of-version: + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + name: Setup MoonBit with Version@${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Moonbit with Version + uses: hustcer/setup-moonbit@develop + with: + setup-core: false + version: 0.1.20250108+7a6b9ab0e + + - name: Check Moonbit Version + run: | + moon version --all + + setup-moonbit-bleeding: + strategy: + fail-fast: false + matrix: + os: [macos-latest] + runs-on: ${{ matrix.os }} + name: Setup MoonBit Bleeding@${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Moonbit Bleeding + uses: hustcer/setup-moonbit@develop + with: + version: bleeding + + - name: Check Moonbit Version + run: | + moon version --all diff --git a/.github/workflows/milestone.yaml b/.github/workflows/milestone.yaml new file mode 100644 index 000000000..14a101f --- /dev/null +++ b/.github/workflows/milestone.yaml @@ -0,0 +1,34 @@ +# Description: +# - Add milestone to a merged PR or closed issue. + +name: Milestone Action +on: + issues: + types: [closed] + pull_request_target: + types: [closed] + +# Fix GraphQL: Resource not accessible by integration (updatePullRequest) +permissions: + contents: write + pull-requests: write + +jobs: + update-milestone: + runs-on: ubuntu-latest + name: Milestone Update + steps: + - name: Set Milestone for PR + uses: hustcer/milestone-action@main + if: github.event.pull_request.merged == true + with: + action: bind-pr + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Set Milestone for Issue + uses: hustcer/milestone-action@main + if: github.event.issue.state == 'closed' + with: + action: bind-issue + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..ad1d626 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog +All notable changes to this project will be documented in this file. + diff --git a/Justfile b/Justfile new file mode 100644 index 000000000..6cc6858 --- /dev/null +++ b/Justfile @@ -0,0 +1,48 @@ +# Author: hustcer +# Create: 2023/10/29 18:05:20 +# Description: +# Some helper task for setup-moonbit +# Ref: +# 1. https://github.com/casey/just +# 2. https://www.nushell.sh/book/ + +set shell := ['nu', '-c'] + +# The export setting causes all just variables +# to be exported as environment variables. + +set export := true +set dotenv-load := true + +# If positional-arguments is true, recipe arguments will be +# passed as positional arguments to commands. For linewise +# recipes, argument $0 will be the name of the recipe. + +set positional-arguments := true + +# Just commands aliases +alias f := fetch + +# Use `just --evaluate` to show env vars + +# Used to handle the path separator issue +DEEPSEEK_REIVEW_PATH := parent_directory(justfile()) +NU_DIR := parent_directory(`(which nu).path.0`) +_query_plugin := if os_family() == 'windows' { 'nu_plugin_query.exe' } else { 'nu_plugin_query' } + +# To pass arguments to a dependency, put the dependency +# in parentheses along with the arguments, just like: +# default: (sh-cmd "main") + +# List available commands by default +default: + @just --list --list-prefix "··· " + +# Release a new version for `deepseek-review` +release *OPTIONS: + @overlay use {{ join(DEEPSEEK_REIVEW_PATH, 'nu', 'release.nu') }}; \ + make-release {{OPTIONS}} + +# Plugins need to be registered only once after nu v0.61 +_setup: + @register -e json {{ join(NU_DIR, _query_plugin) }} diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..329b877 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 hustcer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 000000000..c3399e8 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Setup MoonBit Action + +[中文说明](README.zh-CN.md) + +[![Setup-Moonbit@Dev](https://github.com/hustcer/setup-moonbit/actions/workflows/basic.yml/badge.svg)](https://github.com/hustcer/setup-moonbit/actions/workflows/basic.yml) +[![Daily Checking](https://github.com/hustcer/setup-moonbit/actions/workflows/daily.yml/badge.svg)](https://github.com/hustcer/setup-moonbit/actions/workflows/daily.yml) + +This GitHub Action will setup a [MoonBit](https://www.moonbitlang.com/) environment for you. It should work on Github `macOS` , `Ubuntu` , and `Windows` runners. + +## Usage + +### Basic + +It's quite simple to use `hustcer/setup-moonbit` , just follow the example below: + +```yaml +steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Moonbit + uses: hustcer/setup-moonbit@v1 + + - name: Check Moonbit Version + run: | + moon version --all +``` + +Or, check the [test.yaml](https://github.com/hustcer/setup-moonbit/blob/main/.github/workflows/test.yml) example. + +In rare circumstances you might get rate limiting errors, if this happens you can set the `GITHUB_TOKEN` environment variable. + +```yaml +- uses: hustcer/setup-moonbit@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + +### Inputs + +| Name | Required | Description | Type | Default | +| ------------ | -------- | ------------ | ------ | --------- | +| `version` | no | A valid moonbit tool chain version, such as `0.1.20250108+7a6b9ab0e`, `nightly`, `latest`, etc. or even `bleeding` | string | `latest`| +| `setup-core` | no | `true` to download and bundle Moonbit Core, `false` to ignore it | bool | `true` | + +## License + +Licensed under: + +* MIT license ([LICENSE](LICENSE) or http://opensource.org/licenses/MIT) diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 000000000..1c66c90 --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,47 @@ +# Setup MoonBit Action + +[![Setup-Moonbit@Dev](https://github.com/hustcer/setup-moonbit/actions/workflows/basic.yml/badge.svg)](https://github.com/hustcer/setup-moonbit/actions/workflows/basic.yml) + +本 GitHub Action 将为你配置一个 [MoonBit](https://www.moonbitlang.com/) 开发环境。适用于 Github `macOS` , `Ubuntu` 和 `Windows` 工作流运行时镜像。 + +## 使用 + +### 基础使用 + +使用 `hustcer/setup-moonbit` 非常简单,只需要按照下面示例即可: + +```yaml +steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Moonbit + uses: hustcer/setup-moonbit@v1 + + - name: Check Moonbit Version + run: | + moon version --all +``` + +或者也可以参考下本仓库的 [test.yaml](https://github.com/hustcer/setup-moonbit/blob/main/.github/workflows/test.yml) 例子。 + +在极少数情况下,你可能会看到速率限制之类的错误。如果发生这种情况,你可以通过设置 `GITHUB_TOKEN` 环境变量来避免该问题: + +```yaml +- uses: hustcer/setup-moonbit@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + +### 输入 + +| 参数名 | 必填 | 描述 | 类型 | 默认值 | +| ---------------- | -------- | --- | ------ | --------- | +| `version` | 否 | 合法的 Moonbit 工具链版本,比如: `0.1.20250108+7a6b9ab0e`, `nightly`, `latest` 或者 `bleeding` | string | `latest` | +| `setup-core` | 否 | 设置为 `true` 则下载并打包 Moonbit Core, `false` 则忽略 | bool | `true` | + +## 许可 + +Licensed under: + +* MIT license ([LICENSE](LICENSE) or http://opensource.org/licenses/MIT) diff --git a/action.yaml b/action.yaml new file mode 100644 index 000000000..d83c4b1 --- /dev/null +++ b/action.yaml @@ -0,0 +1,42 @@ +# Deepseek Code Review Action +# @author: hustcer +# @created: 2025/01/29 13:05:20 +# REF: +# - https://docs.github.com/cn/actions/creating-actions/about-custom-actions +# - https://docs.github.com/cn/actions/creating-actions/metadata-syntax-for-github-actions +# - https://docs.github.com/en/actions/creating-actions/creating-a-composite-action + +name: 'Deepseek Code Review' +author: 'hustcer' +description: 'A github action to do code review by Deepseek for PRs.' + +branding: + icon: 'code' + color: 'purple' + +inputs: + version: + required: false + default: 'latest' + description: 'The moonbit toolchain version to setup.' + setup-core: + required: false + default: true + description: 'Set to `true` if you want to setup moonbit core.' + +runs: + using: 'composite' + steps: + - name: Setup Nu + uses: hustcer/setup-nu@v3 + with: + version: 0.101.0 + + - name: Deepseek Code Review + shell: nu {0} + run: | + use ${{ github.action_path }}/nu/review.nu * + let version = '${{inputs.version}}' + let setupCore = '${{inputs.setup-core}}' | into bool + deepseek-review $version --setup-core=$setupCore + diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 000000000..9652135 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,53 @@ +# configuration file for git-cliff (0.1.0) + +[changelog] +# changelog header +header = """ +# Changelog +All notable changes to this project will be documented in this file.\n +""" +# template for the changelog body +# https://tera.netlify.app/docs/#introduction +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespaces from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# allow only conventional commits +# https://www.conventionalcommits.org +conventional_commits = true +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat", group = "Features"}, + { message = "^fix", group = "Bug Fixes"}, + { message = "^doc", group = "Documentation"}, + { message = "^perf", group = "Performance"}, + { message = "^refactor", group = "Refactor"}, + { message = "^style", group = "Styling"}, + { message = "^test", group = "Testing"}, + { message = "^chore\\(release\\): prepare for", skip = true}, + { message = "^chore", group = "Miscellaneous Tasks"}, + { body = ".*security", group = "Security"}, +] +# filter out the commits that are not matched by commit parsers +filter_commits = false +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" diff --git a/cspell.yml b/cspell.yml new file mode 100644 index 000000000..17929bd --- /dev/null +++ b/cspell.yml @@ -0,0 +1,10 @@ +# REF: +# https://cspell.org/configuration/ +# Usage: +# npx cspell --no-progress . + +words: +- justfile +- lefthook + +ignorePaths: diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 000000000..c2e9d5b --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,33 @@ +# EXAMPLE USAGE +# Refer for explanation to following link: +# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md +# +# pre-push: +# commands: +# packages-audit: +# tags: frontend security +# run: yarn audit +# gems-audit: +# tags: backend security +# run: bundle audit +# +min_version: 1.8.0 +no_tty: false +skip_output: + - meta # Skips lefthook version printing + - skips # Skips "skip" printing (i.e. no files matched) + - summary # Skips summary block (successful and failed steps) printing + - success # Skips successful steps printing + - failure # Skips failed steps printing + - execution_info # Skips printing `EXECUTE > ...` logging + +pre-commit: + parallel: true + commands: + spell-check: + skip: + - merge + - rebase + stage_fixed: true + glob: "*.*" + run: cspell --no-progress {staged_files} diff --git a/meta.json b/meta.json new file mode 100644 index 000000000..caea0a9 --- /dev/null +++ b/meta.json @@ -0,0 +1,10 @@ +{ + "name": "deepseek-review", + "version": "0.1.0", + "actionVer": "v0.1", + "author": "hustcer", + "license": "MIT", + "github": "https://github.com/hustcer/deepseek-review", + "home": "https://github.com/marketplace/actions/deepseek-review", + "description": "A github action to do code review for pull requests." +} diff --git a/nu/release.nu b/nu/release.nu new file mode 100644 index 000000000..199522a --- /dev/null +++ b/nu/release.nu @@ -0,0 +1,54 @@ +#!/usr/bin/env nu +# Author: hustcer +# Created: 2025/01/29 12:56:56 +# Description: Script to release deepseek-review +# +# TODO: +# [√] Make sure the release tag does not exist; +# [√] Make sure there are no uncommitted changes; +# [√] Update change log if required; +# [√] Create a release tag and push it to the remote repo; +# Usage: +# Change `version` in meta.json and then run: `just release` OR `just release -u` + +export def 'make-release' [ + --update-log(-u) # Add flag to enable updating CHANGELOG.md +] { + + cd $env.DEEPSEEK_REIVEW_PATH + let releaseVer = (open meta.json | get actionVer) + + if (has-ref $releaseVer) { + echo $'The version ($releaseVer) already exists, Please choose another version.(char nl)' + exit 5 + } + let majorTag = $releaseVer | split row '.' | first + let statusCheck = (git status --porcelain) + if not ($statusCheck | is-empty) { + echo $'You have uncommitted changes, please commit them and try `release` again!(char nl)' + exit 5 + } + if ($update_log) { + git cliff --unreleased --tag $releaseVer --prepend CHANGELOG.md; + git commit CHANGELOG.md -m $'update CHANGELOG.md for ($releaseVer)' + } + # Delete tags that not exist in remote repo + git fetch origin --prune '+refs/tags/*:refs/tags/*' + let commitMsg = $'A new release for version: ($releaseVer) created by Release command of deepseek-review.' + git tag $releaseVer -am $commitMsg; + # Remove local major version tag if exists and ignore errors + do -i { git tag -d $majorTag | complete | ignore } + git checkout $releaseVer; git tag $majorTag + git push origin $majorTag $releaseVer --force +} + +# Check if a git repo has the specified ref: could be a branch or tag, etc. +export def has-ref [ + ref: string # The git ref to check +] { + let checkRepo = (do -i { git rev-parse --is-inside-work-tree } | complete) + if not ($checkRepo.stdout =~ 'true') { return false } + # Brackets were required here, or error will occur + let parse = (do -i { git rev-parse --verify -q $ref } | complete) + if ($parse.stdout | is-empty) { false } else { true } +} diff --git a/nu/review.nu b/nu/review.nu new file mode 100644 index 000000000..3cb8378 --- /dev/null +++ b/nu/review.nu @@ -0,0 +1,44 @@ +#!/usr/bin/env nu +# Author: hustcer +# Created: 2025/01/29 13:02:15 +# TODO: +# [√] Deepseek code reivew for Github PRs +# [√] Deepseek code reivew for local commit changes +# Description: A script to do code review by deepseek +# Usage: +# + +export def deepseek-review [] { + +} + +# If current host is Windows +export def windows? [] { + # Windows / Darwin / Linux + (sys host | get name) == 'Windows' +} + +# Check if some command available in current shell +export def is-installed [ app: string ] { + (which $app | length) > 0 +} + +export def hr-line [ + width?: int = 90, + --color(-c): string = 'g', + --blank-line(-b), + --with-arrow(-a), +] { + # Create a line by repeating the unit with specified times + def build-line [ + times: int, + unit: string = '-', + ] { + 0..<$times | reduce -f '' { |i, acc| $unit + $acc } + } + + print $'(ansi $color)(build-line $width)(if $with_arrow {'>'})(ansi reset)' + if $blank_line { char nl } +} + +alias main = deepseek-review