From c2ef662e48223938b1ae35b95d2f28cd5b531fba Mon Sep 17 00:00:00 2001 From: Auca Coyan Date: Tue, 12 Mar 2024 16:48:08 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20a=20`nu-check`=20verification?= =?UTF-8?q?=20CI=20(#771)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I made a `toolkit.nu` with a very bare bones struct, this is called via [`setup-nu`](https://github.com/hustcer/setup-nu) action, and generates the `check-files.nu` file. After that, another nu instance run that script to check files one by one. The folder `before_v0.60/` is excluded. --- .github/workflows/ci.yml | 29 +++++++++++++++++ .github/workflows/daily.yml | 33 +++++++++++++++++++ .gitignore | 2 ++ toolkit.nu | 64 +++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/daily.yml create mode 100644 toolkit.nu diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..d60a230b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +on: + pull_request: + +env: + NUSHELL_CARGO_PROFILE: ci + NU_LOG_LEVEL: DEBUG + +jobs: + nu-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: 'Fetch main branch' + run: | + git fetch origin main --depth 1 + - uses: hustcer/setup-nu@v3.9 + with: + version: '*' + check-latest: true + features: full # dataframe and extra included + - name: toolkit check pr + shell: nu {0} + run: | + nu -c "use toolkit.nu *; check pr" + - name: run nu-check on modified files + shell: nu {0} + run: | + nu ./check-files.nu diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml new file mode 100644 index 00000000..366cc6b6 --- /dev/null +++ b/.github/workflows/daily.yml @@ -0,0 +1,33 @@ +on: + push: + branches: + - main + schedule: + - cron: '30 0 * * *' # every day at 00:30 AM UTC + +env: + NUSHELL_CARGO_PROFILE: ci + NU_LOG_LEVEL: DEBUG + +jobs: + nu-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: 'Fetch main branch' + run: | + git fetch origin main --depth 1 + - uses: hustcer/setup-nu@v3.9 + with: + version: '*' + check-latest: true + features: full # dataframe and extra included + - name: toolkit generate-file-list --full + shell: nu {0} + run: | + nu -c "use toolkit.nu *; generate-file-list --full" + - name: run nu-check on all files + shell: nu {0} + run: | + nu ./check-files.nu diff --git a/.gitignore b/.gitignore index 507f1f66..4f920f11 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ # ignore the git mailmap file .mailmap + +check-files.nu diff --git a/toolkit.nu b/toolkit.nu new file mode 100644 index 00000000..e038b651 --- /dev/null +++ b/toolkit.nu @@ -0,0 +1,64 @@ +# this module regroups a bunch of development tools to make the development +# process easier for anyone. +# +# the main purpose of `toolkit` is to offer an easy to use interface for the +# developer during a PR cycle. + + +# check that all the tests pass +export def test [ +] { + print "toolkit test: not implemented!" +} + +# run all the necessary checks and tests to submit a perfect PR +export def "check pr" [ +] { + generate-file-list + test +} + +export def main [] { help toolkit } + +export def generate-file-list [ --full ] { + let start = "let files = [" + + mut files = [""] + + if $full { + # all the *.nu files in the repo + # exept for `before_v0.60` + print "checking all files..." + mut $files = glob **/*.nu --exclude [before_v0.60/**] + } else { + # only the *.nu files changed in comparison with origin/main + $files = (git diff --name-only origin/main | lines | filter { str ends-with '.nu'} | each { path expand }) + } + + + let new_list = $files | str join ",\n" | append "]" + + let final = " + + mut exit_code = 0 + for file in $files { + let diagnostics_table = nu --ide-check 10 $file | to text | ['[', $in, ']'] | str join | from json + let result = $diagnostics_table | where type == \"diagnostic\" | is-empty + if $result { + print $\"✔ ($file) is ok\" + } else { + print $\"❌ ($file) has errors:\" + print ($diagnostics_table | where type == \"diagnostic\" | reject span) + $exit_code = 1 + } + } + print $\"💚 All files checked!\" + +exit $exit_code +" + + $start + | append $new_list + | append $final + | save "check-files.nu" --force +}