Skip to content

Commit

Permalink
os-checker-plugin-cargo and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
zjp-CN committed Oct 27, 2024
1 parent d0db5b1 commit b39d3d8
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 25 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "plugin-cargo"
name = "os-checker-plugin-cargo"
version = "0.1.0"
edition = "2021"

Expand Down
21 changes: 21 additions & 0 deletions push.sh
Original file line number Diff line number Diff line change
@@ -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 🎇
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod prelude {
pub use indexmap::IndexMap;
}

use eyre::ContextCompat;
use prelude::*;

#[macro_use]
Expand All @@ -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<String> = serde_json::from_slice(&std::fs::read(&list_json)?)?;
for user_repo in &list {
Expand Down

0 comments on commit b39d3d8

Please sign in to comment.