From b39d3d8fab2946ce55010ec6d648e150257d0981 Mon Sep 17 00:00:00 2001 From: zjp Date: Sun, 27 Oct 2024 20:12:54 +0800 Subject: [PATCH] os-checker-plugin-cargo and ci --- .github/workflows/run.yml | 62 +++++++++++++++++++++++++++++++++++++++ Cargo.lock | 38 ++++++++++++------------ Cargo.toml | 2 +- push.sh | 21 +++++++++++++ src/main.rs | 7 ++--- 5 files changed, 105 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/run.yml create mode 100644 push.sh diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml new file mode 100644 index 0000000..754a8d7 --- /dev/null +++ b/.github/workflows/run.yml @@ -0,0 +1,62 @@ +name: Run plugin-cargo + +on: + schedule: + - cron: '0 0 * * *' + push: + branches: [ main, feat/* ] + +env: + CARGO_TERM_COLOR: always + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + RUST_LOG: info + # database branch + DATABASE: main + BOT: 1 + TAG_REPOS_DEFAULT: cache-v8.redb + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Generate list.json + run: | + wget https://github.com/os-checker/database/releases/download/${{ env.TAG_REPOS_DEFAULT }}/repos-default.json + jq 'to_entries | map(.key) + ["os-checker/os-checker", "os-checker/os-checker.github.io"]' repos-default.json > list.json + tree --help + tree --gitignore -h + + - name: Install plugin-cargo + run: cargo install --path . + + - name: Run plugin-cargo + run: | + os-checker-plugin-cargo # demo_jsons/list.json + tree --gitignore -h tmp + + - name: Push to database + env: + PLUGIN_PATH: plugin/cargo + run: | + git config --global user.name "zjp-CN" + git config --global user.email "jiping_zhou@foxmail.com" + git config --global committer.name "zjp-CN[bot]" + git config --global committer.email "zjp-CN[bot]@users.noreply.github.com" + + echo "正在 clone os-checker/database" + git clone https://x-access-token:${{ env.ACCESS_TOKEN }}@github.com/os-checker/database.git + echo "成功 clone os-checker/database" + + cd database + git switch ${{ env.DATABASE }} + + rm -rf ${{ env.PLUGIN_PATH }} + mkdir -p ${{ env.PLUGIN_PATH }} + mv ../tmp ${{ env.PLUGIN_PATH }}/info + cp ../push.sh ${{ env.PLUGIN_PATH }} + + bash ${{ env.PLUGIN_PATH }}/push.sh + diff --git a/Cargo.lock b/Cargo.lock index 2013a0f..f0696e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,6 +296,25 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "os-checker-plugin-cargo" +version = "0.1.0" +dependencies = [ + "camino", + "cargo_metadata", + "color-eyre", + "duct", + "eyre", + "indexmap", + "nextest-metadata", + "serde", + "serde_json", + "tracing", + "tracing-error", + "tracing-subscriber", + "walkdir", +] + [[package]] name = "os_pipe" version = "1.2.1" @@ -324,25 +343,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" -[[package]] -name = "plugin-cargo" -version = "0.1.0" -dependencies = [ - "camino", - "cargo_metadata", - "color-eyre", - "duct", - "eyre", - "indexmap", - "nextest-metadata", - "serde", - "serde_json", - "tracing", - "tracing-error", - "tracing-subscriber", - "walkdir", -] - [[package]] name = "proc-macro2" version = "1.0.89" diff --git a/Cargo.toml b/Cargo.toml index 2fc9d12..5862740 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "plugin-cargo" +name = "os-checker-plugin-cargo" version = "0.1.0" edition = "2021" diff --git a/push.sh b/push.sh new file mode 100644 index 0000000..078afe3 --- /dev/null +++ b/push.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e + +if [ -n "$BOT" ]; then + echo "更新 plugin/cargo 目录" + + export branch=$(git branch --show-current) + + echo "bot!" + + git status + git add . + echo "正在提交:$(git status --porcelain)" + git commit -m "[bot] update plugin dir from os-checker-plugin-cargo repo" + echo "提交成功,正在推送到 database 仓库(分支:$branch)" + git push + echo "成功推送到 database 仓库(分支:$branch)" +fi + +echo 🎇 diff --git a/src/main.rs b/src/main.rs index 8e3a7e3..624323d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ mod prelude { pub use indexmap::IndexMap; } -use eyre::ContextCompat; use prelude::*; #[macro_use] @@ -21,10 +20,8 @@ const BASE: &str = "tmp"; fn main() -> Result<()> { logger::init(); - let arg = std::env::args() - .nth(1) - .with_context(|| "the first argument should be a json path")?; - let list_json = Utf8PathBuf::from(arg); + let arg = std::env::args().nth(1); + let list_json = Utf8PathBuf::from(arg.as_deref().unwrap_or("list.json")); let list: Vec = serde_json::from_slice(&std::fs::read(&list_json)?)?; for user_repo in &list {