From 05e8f6084eb1537a40d9905b18c7553d8ba5f3a5 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 17:21:17 +0900 Subject: [PATCH 01/15] tmp --- .github/workflows/release-tmp.yml | 33 +++++++++++++++++++++++++++++++ .github/workflows/release.yml | 19 +++++++++++++++++- .github/workflows/test.yaml | 33 +++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release-tmp.yml create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml new file mode 100644 index 0000000..b8446ec --- /dev/null +++ b/.github/workflows/release-tmp.yml @@ -0,0 +1,33 @@ +on: + push: + tags: + # - "v*.*.*" + - "tmp" + +jobs: + release: + name: release ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: aarch64-unknown-linux-gnu + - target: aarch64-apple-darwin + steps: + - uses: actions/checkout@master + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.target }} + override: true + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --release --target ${{ matrix.target }} + - name: Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true + files: ${{ matrix.target }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 13e3fac..8c10210 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,4 +26,21 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: RUSTTARGET: ${{ matrix.target }} - ARCHIVE_TYPES: ${{ matrix.archive }} \ No newline at end of file + ARCHIVE_TYPES: ${{ matrix.archive }} + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: aarch64-apple-darwin + override: true + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --release --target aarch64-apple-darwin + - name: Release + uses: softprops/action-gh-release@v1 + with: + name: ${{ github.event.pull_request.body }} + tag_name: ${{ github.event.pull_request.title }} + generate_release_notes: true + files: target/hoge.jar diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..f2d9aec --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,33 @@ +name: test + +on: [push] + +jobs: + test: + name: run test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt, clippy + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + - uses: actions-rs/cargo@v1 + with: + command: test + args: --release --all-features From 3f00a6d2bd7f3a86f8d94b4fd3b0d50e3d5b4057 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 17:23:20 +0900 Subject: [PATCH 02/15] cargo fmt --all --- src/main.rs | 526 +++++++++++++++++++++++++++------------------------- 1 file changed, 271 insertions(+), 255 deletions(-) diff --git a/src/main.rs b/src/main.rs index dc25b17..64730ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,304 +1,320 @@ use clap::Parser; -use octocrab::{Octocrab, params}; -use std::{process::Command}; +use octocrab::{params, Octocrab}; use once_cell::sync::Lazy; -use std::{error::Error}; use regex::Regex; +use std::error::Error; +use std::process::Command; -static RE_GIT_LS_REMOTE: Lazy = Lazy::new(|| { - Regex::new("^(?P\\w*)\\s*refs/pull/(?P\\d+)/head$").unwrap() -}); -static RE_BODY_TASK_LIST_CHECKED: Lazy = Lazy::new(|| { - Regex::new("-\\s\\[x\\]\\s#").unwrap() -}); +static RE_GIT_LS_REMOTE: Lazy = + Lazy::new(|| Regex::new("^(?P\\w*)\\s*refs/pull/(?P\\d+)/head$").unwrap()); +static RE_BODY_TASK_LIST_CHECKED: Lazy = + Lazy::new(|| Regex::new("-\\s\\[x\\]\\s#").unwrap()); /// Simple program to greet a person #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { - /// base branch of pull request - #[arg(short, long)] - base: String, + /// base branch of pull request + #[arg(short, long)] + base: String, - /// head branch of pull request - #[arg(short = 'H', long)] - head: String, + /// head branch of pull request + #[arg(short = 'H', long)] + head: String, - /// merge a pull request - #[arg(long, default_value_t = false)] - merge: bool, + /// merge a pull request + #[arg(long, default_value_t = false)] + merge: bool, - /// merge a pull request with squash - #[arg(long, default_value_t = false)] - merge_squash: bool, + /// merge a pull request with squash + #[arg(long, default_value_t = false)] + merge_squash: bool, - /// merge a pull request with rebase - #[arg(long, default_value_t = false)] - merge_rebase: bool, + /// merge a pull request with rebase + #[arg(long, default_value_t = false)] + merge_rebase: bool, - /// no remote fetch before executing - #[arg(long, default_value_t = false)] - no_fetch: bool, + /// no remote fetch before executing + #[arg(long, default_value_t = false)] + no_fetch: bool, } #[tokio::main] -async fn main()-> Result<(), Box> { - let args = Args::parse(); - - // Variables - let head = args.head; - let base = args.base; - let (owner, repo) = get_repo_name(); - let head_str = head.as_str(); - let base_str = base.as_str(); - let owner_str = owner.as_str(); - let repo_str = repo.as_str(); - - // fetch remote - if !args.no_fetch { - git_fetch_all() - } - - // Gitub PR - let mut ret: Vec = get_diff_pr(base_str, head_str); - - // Github Client - let github_client = get_github_client(); - - for pr in ret.iter_mut() { - let res = github_client.pulls(owner_str, repo_str).get(pr.id).await?; - if let Some(user) = res.user { - pr.username = user.login; +async fn main() -> Result<(), Box> { + let args = Args::parse(); + + // Variables + let head = args.head; + let base = args.base; + let (owner, repo) = get_repo_name(); + let head_str = head.as_str(); + let base_str = base.as_str(); + let owner_str = owner.as_str(); + let repo_str = repo.as_str(); + + // fetch remote + if !args.no_fetch { + git_fetch_all() } - for p in pr.children.iter_mut() { - let res = github_client.pulls(owner_str, repo_str).get(p.id).await?; - if let Some(user) = res.user { - p.username = user.login; - } - } - } - let mut body = "".to_owned(); - for pr in ret { - body += &format!("- [ ] #{} @{} `{}`\n", pr.id, pr.username, pr.date); - for p in pr.children { - body += &format!(" - [ ] #{} @{} `{}`\n", p.id, p.username, p.date); - } - } - - // List Github PR - let list_pr = github_client.pulls(owner_str, repo_str) - .list() - // Optional Parameters - .state(params::State::Open) - .head(head_str) - .base(base_str) - .sort(params::pulls::Sort::Created) - .direction(params::Direction::Descending) - .per_page(1) - // Send the request - .send() - .await? - .take_items(); - - let mut target_id: u64 = 0; - if list_pr.len() > 0 { - target_id = list_pr[0].number; - // keep checked task list - if let Some(now_body) = &list_pr[0].body { - for line in now_body.split("\n") { - if RE_BODY_TASK_LIST_CHECKED.is_match(&line) { - let unchecked_line = line.replace("- [x] #", "- [ ] #"); - body = body.replace(&unchecked_line, &line); + // Gitub PR + let mut ret: Vec = get_diff_pr(base_str, head_str); + + // Github Client + let github_client = get_github_client(); + + for pr in ret.iter_mut() { + let res = github_client.pulls(owner_str, repo_str).get(pr.id).await?; + if let Some(user) = res.user { + pr.username = user.login; + } + for p in pr.children.iter_mut() { + let res = github_client.pulls(owner_str, repo_str).get(p.id).await?; + if let Some(user) = res.user { + p.username = user.login; + } } - } - } - // Update Github PR - github_client - .pulls(owner_str, repo_str) - .update(list_pr[0].number) - .body(body) - .send() - .await?; - - if let Some(html_url) = &list_pr[0].html_url { - println!("existing PullRequest was successfully updated: {}", html_url.as_str()); - } - } else { - // Create Github PR - let title = format!("{} from {}", base_str, head_str); - let ret = github_client - .pulls(owner_str, repo_str) - .create(title, head_str, base_str) - .body(body) - .send() - .await?; - - if let Some(html_url) = &ret.html_url { - println!("new PullRequest was successfully created: {}", html_url.as_str()); } - target_id = ret.number; - } - if args.merge { - let mut method = params::pulls::MergeMethod::Merge; - if args.merge_rebase { - method = params::pulls::MergeMethod::Rebase; - } - else if args.merge_squash { - method = params::pulls::MergeMethod::Squash; + let mut body = "".to_owned(); + for pr in ret { + body += &format!("- [ ] #{} @{} `{}`\n", pr.id, pr.username, pr.date); + for p in pr.children { + body += &format!(" - [ ] #{} @{} `{}`\n", p.id, p.username, p.date); + } } - github_client - .pulls(owner_str, repo_str) - .merge(target_id) - .method(method) - .send().await?; - println!(" and successfully merged ({:?})", method); - } + // List Github PR + let list_pr = github_client + .pulls(owner_str, repo_str) + .list() + // Optional Parameters + .state(params::State::Open) + .head(head_str) + .base(base_str) + .sort(params::pulls::Sort::Created) + .direction(params::Direction::Descending) + .per_page(1) + // Send the request + .send() + .await? + .take_items(); + + let mut target_id: u64 = 0; + if list_pr.len() > 0 { + target_id = list_pr[0].number; + // keep checked task list + if let Some(now_body) = &list_pr[0].body { + for line in now_body.split("\n") { + if RE_BODY_TASK_LIST_CHECKED.is_match(&line) { + let unchecked_line = line.replace("- [x] #", "- [ ] #"); + body = body.replace(&unchecked_line, &line); + } + } + } + // Update Github PR + github_client + .pulls(owner_str, repo_str) + .update(list_pr[0].number) + .body(body) + .send() + .await?; + + if let Some(html_url) = &list_pr[0].html_url { + println!( + "existing PullRequest was successfully updated: {}", + html_url.as_str() + ); + } + } else { + // Create Github PR + let title = format!("{} from {}", base_str, head_str); + let ret = github_client + .pulls(owner_str, repo_str) + .create(title, head_str, base_str) + .body(body) + .send() + .await?; + + if let Some(html_url) = &ret.html_url { + println!( + "new PullRequest was successfully created: {}", + html_url.as_str() + ); + } + target_id = ret.number; + } - Ok(()) + if args.merge { + let mut method = params::pulls::MergeMethod::Merge; + if args.merge_rebase { + method = params::pulls::MergeMethod::Rebase; + } else if args.merge_squash { + method = params::pulls::MergeMethod::Squash; + } + github_client + .pulls(owner_str, repo_str) + .merge(target_id) + .method(method) + .send() + .await?; + + println!(" and successfully merged ({:?})", method); + } + Ok(()) } #[derive(Debug, Clone)] struct PR { - id: u64, - date: String, - username: String, - hash: String, - children: Vec, + id: u64, + date: String, + username: String, + hash: String, + children: Vec, } fn get_diff_pr(base: &str, head: &str) -> Vec { - let mut prs: Vec = Vec::new(); - - // get feature branch commit hash of merge commits - let merges_all = Command::new("git") - .arg("log") - .arg(format!("origin/{}..origin/{}", base, head)) - .arg("--merges") - .arg("--pretty=format:'%P %cI'") - .output().expect("failed to execute process"); - - // get feature branch commit hash of merge commits - let merges_first_parent = Command::new("git") - .arg("log") - .arg(format!("origin/{}..origin/{}", base, head)) - .arg("--merges") - .arg("--pretty=format:'%P %cI'") - .arg("--first-parent") - .output().expect("failed to execute process"); - - let merges_first_parent_list = std::str::from_utf8(&merges_first_parent.stdout).unwrap().split_terminator("\n").collect::>(); - let merges_all_list = std::str::from_utf8(&merges_all.stdout).unwrap().split_terminator("\n").collect::>(); - for a in merges_all_list { - let line_a = a.split_whitespace().collect::>(); - let mut found = false; - for b in &merges_first_parent_list { - if a == b.to_owned() { - found = true; - break; - } - } - if found { - prs.push(PR{ - hash: line_a[1].to_owned(), - id: 0, - date: line_a[2].to_owned().to_owned().replace("'", ""), - username: "".to_owned(), - children: vec![], - }); - } else { - if prs.len() > 0 { - let len = prs.len(); - prs[len-1].children.push(PR{ - hash: line_a[1].to_owned(), - id: 0, - date: line_a[2].to_owned().to_owned().replace("'", ""), - username: "".to_owned(), - children: vec![], - }); - } else { - prs.push(PR{ - hash: line_a[1].to_owned(), - id: 0, - date: line_a[2].to_owned().to_owned().replace("'", ""), - username: "".to_owned(), - children: vec![], - }); - } + let mut prs: Vec = Vec::new(); + + // get feature branch commit hash of merge commits + let merges_all = Command::new("git") + .arg("log") + .arg(format!("origin/{}..origin/{}", base, head)) + .arg("--merges") + .arg("--pretty=format:'%P %cI'") + .output() + .expect("failed to execute process"); + + // get feature branch commit hash of merge commits + let merges_first_parent = Command::new("git") + .arg("log") + .arg(format!("origin/{}..origin/{}", base, head)) + .arg("--merges") + .arg("--pretty=format:'%P %cI'") + .arg("--first-parent") + .output() + .expect("failed to execute process"); + + let merges_first_parent_list = std::str::from_utf8(&merges_first_parent.stdout) + .unwrap() + .split_terminator("\n") + .collect::>(); + let merges_all_list = std::str::from_utf8(&merges_all.stdout) + .unwrap() + .split_terminator("\n") + .collect::>(); + for a in merges_all_list { + let line_a = a.split_whitespace().collect::>(); + let mut found = false; + for b in &merges_first_parent_list { + if a == b.to_owned() { + found = true; + break; + } + } + if found { + prs.push(PR { + hash: line_a[1].to_owned(), + id: 0, + date: line_a[2].to_owned().to_owned().replace("'", ""), + username: "".to_owned(), + children: vec![], + }); + } else { + if prs.len() > 0 { + let len = prs.len(); + prs[len - 1].children.push(PR { + hash: line_a[1].to_owned(), + id: 0, + date: line_a[2].to_owned().to_owned().replace("'", ""), + username: "".to_owned(), + children: vec![], + }); + } else { + prs.push(PR { + hash: line_a[1].to_owned(), + id: 0, + date: line_a[2].to_owned().to_owned().replace("'", ""), + username: "".to_owned(), + children: vec![], + }); + } + } } - } - - // get pull requests - let ls_remotes = Command::new("git") - .arg("ls-remote") - .arg("origin") - .arg("pull/*/head") - .output().expect("failed to execute process"); - for a in std::str::from_utf8(&ls_remotes.stdout).unwrap().split_terminator("\n").collect::>() { - let parts = RE_GIT_LS_REMOTE.captures(&a).unwrap(); - for pr in prs.iter_mut() { - if &parts["hash"] == pr.hash.to_owned() { - pr.id = parts["prid"].parse().unwrap(); - break; - } - - for pr in pr.children.iter_mut() { - if &parts["hash"] == pr.hash.to_owned() { - pr.id = parts["prid"].parse().unwrap(); + // get pull requests + let ls_remotes = Command::new("git") + .arg("ls-remote") + .arg("origin") + .arg("pull/*/head") + .output() + .expect("failed to execute process"); + + for a in std::str::from_utf8(&ls_remotes.stdout) + .unwrap() + .split_terminator("\n") + .collect::>() + { + let parts = RE_GIT_LS_REMOTE.captures(&a).unwrap(); + for pr in prs.iter_mut() { + if &parts["hash"] == pr.hash.to_owned() { + pr.id = parts["prid"].parse().unwrap(); + break; + } + + for pr in pr.children.iter_mut() { + if &parts["hash"] == pr.hash.to_owned() { + pr.id = parts["prid"].parse().unwrap(); + } + } } - } } - } - // filter - prs.retain(|x| x.id != 0); - for pr in prs.iter_mut() { - pr.children.retain(|x| x.id != 0); - } + // filter + prs.retain(|x| x.id != 0); + for pr in prs.iter_mut() { + pr.children.retain(|x| x.id != 0); + } - return prs; + return prs; } fn get_repo_name() -> (String, String) { - - // get feature branch commit hash of merge commits - let url = Command::new("git") - .arg("remote") - .arg("get-url") - .arg("origin") - .output() - .expect("failed to execute process"); - - let out = std::str::from_utf8(&url.stdout).unwrap(); - let s1 = out.split(":").collect::>(); - if s1.len() < 2 { - panic!("git remote url is invalid"); - } - let s2 = s1[1].replace("//github.com/", "").replace(".git", ""); - let names = s2.split("/").collect::>(); - if s2.len() < 2 { - panic!("git remote url is invalid"); - } - return (names[0].to_owned(), names[1].to_owned()); + // get feature branch commit hash of merge commits + let url = Command::new("git") + .arg("remote") + .arg("get-url") + .arg("origin") + .output() + .expect("failed to execute process"); + + let out = std::str::from_utf8(&url.stdout).unwrap(); + let s1 = out.split(":").collect::>(); + if s1.len() < 2 { + panic!("git remote url is invalid"); + } + let s2 = s1[1].replace("//github.com/", "").replace(".git", ""); + let names = s2.split("/").collect::>(); + if s2.len() < 2 { + panic!("git remote url is invalid"); + } + return (names[0].to_owned(), names[1].to_owned()); } fn git_fetch_all() { - // fetch remote - Command::new("git") - .arg("fetch") - .arg("--all") - .output() - .expect("failed to execute process"); + // fetch remote + Command::new("git") + .arg("fetch") + .arg("--all") + .output() + .expect("failed to execute process"); } fn get_github_client() -> Octocrab { - let token = std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable is required"); - return octocrab::OctocrabBuilder::new() - .personal_token(token) - .build() - .unwrap(); + let token = std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable is required"); + return octocrab::OctocrabBuilder::new() + .personal_token(token) + .build() + .unwrap(); } From 9e911b2654eba6df8b64e7811a61f57ffcec4814 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 17:26:26 +0900 Subject: [PATCH 03/15] os --- .github/workflows/release-tmp.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml index b8446ec..945d08b 100644 --- a/.github/workflows/release-tmp.yml +++ b/.github/workflows/release-tmp.yml @@ -7,13 +7,17 @@ on: jobs: release: name: release ${{ matrix.target }} - runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: - - target: aarch64-unknown-linux-gnu - - target: aarch64-apple-darwin + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: macOS-latest + target: x86_64-apple-darwin + - os: macOS-latest + target: aarch64-apple-darwin + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@master - uses: actions-rs/toolchain@v1 From ee122e2bd41be674a4b3d4cef40a09e39ec7d13e Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 17:39:25 +0900 Subject: [PATCH 04/15] fix lint --- src/main.rs | 74 ++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main.rs b/src/main.rs index 64730ed..302ee81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,15 +100,15 @@ async fn main() -> Result<(), Box> { .await? .take_items(); - let mut target_id: u64 = 0; - if list_pr.len() > 0 { + let target_id: u64; + if !list_pr.is_empty() { target_id = list_pr[0].number; // keep checked task list if let Some(now_body) = &list_pr[0].body { - for line in now_body.split("\n") { - if RE_BODY_TASK_LIST_CHECKED.is_match(&line) { + for line in now_body.split('\n') { + if RE_BODY_TASK_LIST_CHECKED.is_match(line) { let unchecked_line = line.replace("- [x] #", "- [ ] #"); - body = body.replace(&unchecked_line, &line); + body = body.replace(&unchecked_line, line); } } } @@ -198,17 +198,17 @@ fn get_diff_pr(base: &str, head: &str) -> Vec { let merges_first_parent_list = std::str::from_utf8(&merges_first_parent.stdout) .unwrap() - .split_terminator("\n") + .split_terminator('\n') .collect::>(); let merges_all_list = std::str::from_utf8(&merges_all.stdout) .unwrap() - .split_terminator("\n") + .split_terminator('\n') .collect::>(); for a in merges_all_list { let line_a = a.split_whitespace().collect::>(); let mut found = false; for b in &merges_first_parent_list { - if a == b.to_owned() { + if a == *b { found = true; break; } @@ -217,29 +217,27 @@ fn get_diff_pr(base: &str, head: &str) -> Vec { prs.push(PR { hash: line_a[1].to_owned(), id: 0, - date: line_a[2].to_owned().to_owned().replace("'", ""), + date: line_a[2].to_owned().to_owned().replace('\'', ""), + username: "".to_owned(), + children: vec![], + }); + } else if !prs.is_empty() { + let len = prs.len(); + prs[len - 1].children.push(PR { + hash: line_a[1].to_owned(), + id: 0, + date: line_a[2].to_owned().to_owned().replace('\'', ""), username: "".to_owned(), children: vec![], }); } else { - if prs.len() > 0 { - let len = prs.len(); - prs[len - 1].children.push(PR { - hash: line_a[1].to_owned(), - id: 0, - date: line_a[2].to_owned().to_owned().replace("'", ""), - username: "".to_owned(), - children: vec![], - }); - } else { - prs.push(PR { - hash: line_a[1].to_owned(), - id: 0, - date: line_a[2].to_owned().to_owned().replace("'", ""), - username: "".to_owned(), - children: vec![], - }); - } + prs.push(PR { + hash: line_a[1].to_owned(), + id: 0, + date: line_a[2].to_owned().to_owned().replace('\'', ""), + username: "".to_owned(), + children: vec![], + }); } } @@ -253,18 +251,18 @@ fn get_diff_pr(base: &str, head: &str) -> Vec { for a in std::str::from_utf8(&ls_remotes.stdout) .unwrap() - .split_terminator("\n") + .split_terminator('\n') .collect::>() { - let parts = RE_GIT_LS_REMOTE.captures(&a).unwrap(); + let parts = RE_GIT_LS_REMOTE.captures(a).unwrap(); for pr in prs.iter_mut() { - if &parts["hash"] == pr.hash.to_owned() { + if parts["hash"] == pr.hash { pr.id = parts["prid"].parse().unwrap(); break; } for pr in pr.children.iter_mut() { - if &parts["hash"] == pr.hash.to_owned() { + if parts["hash"] == pr.hash { pr.id = parts["prid"].parse().unwrap(); } } @@ -277,7 +275,7 @@ fn get_diff_pr(base: &str, head: &str) -> Vec { pr.children.retain(|x| x.id != 0); } - return prs; + prs } fn get_repo_name() -> (String, String) { @@ -290,16 +288,17 @@ fn get_repo_name() -> (String, String) { .expect("failed to execute process"); let out = std::str::from_utf8(&url.stdout).unwrap(); - let s1 = out.split(":").collect::>(); + let s1 = out.split(':').collect::>(); if s1.len() < 2 { panic!("git remote url is invalid"); } let s2 = s1[1].replace("//github.com/", "").replace(".git", ""); - let names = s2.split("/").collect::>(); + let names = s2.split('/').collect::>(); if s2.len() < 2 { panic!("git remote url is invalid"); } - return (names[0].to_owned(), names[1].to_owned()); + + (names[0].to_owned(), names[1].to_owned()) } fn git_fetch_all() { @@ -313,8 +312,9 @@ fn git_fetch_all() { fn get_github_client() -> Octocrab { let token = std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable is required"); - return octocrab::OctocrabBuilder::new() + + octocrab::OctocrabBuilder::new() .personal_token(token) .build() - .unwrap(); + .unwrap() } From 2c5a2bceb1795cb55df66e26af962fb5f9b66f13 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 17:48:37 +0900 Subject: [PATCH 05/15] fix --- .github/workflows/release-tmp.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml index 945d08b..781ff35 100644 --- a/.github/workflows/release-tmp.yml +++ b/.github/workflows/release-tmp.yml @@ -13,10 +13,10 @@ jobs: include: - os: ubuntu-latest target: x86_64-unknown-linux-gnu - - os: macOS-latest - target: x86_64-apple-darwin - - os: macOS-latest - target: aarch64-apple-darwin + # - os: macOS-latest + # target: x86_64-apple-darwin + # - os: macOS-latest + # target: aarch64-apple-darwin runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@master @@ -34,4 +34,4 @@ jobs: uses: softprops/action-gh-release@v1 with: generate_release_notes: true - files: ${{ matrix.target }} + files: target/${{ matrix.target }}/release/create-release-pr From 5dd0f91ec1700e6605dc9bc0378a35e83e3b8dd9 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 17:51:27 +0900 Subject: [PATCH 06/15] fix --- .github/workflows/release-tmp.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml index 781ff35..9c3dbbd 100644 --- a/.github/workflows/release-tmp.yml +++ b/.github/workflows/release-tmp.yml @@ -30,6 +30,15 @@ jobs: use-cross: true command: build args: --release --target ${{ matrix.target }} + - name: Compress action step + uses: a7ul/tar-action@v1.1.0 + id: compress + with: + command: c + cwd: ./test + files: | + target/${{ matrix.target }}/release/create-release-pr + outPath: target/${{ matrix.target }}/release/create-release-pr.tar.gz - name: Release uses: softprops/action-gh-release@v1 with: From 1e80ef6f0a8f171ac740dddaa43998b086cd39e7 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 17:52:25 +0900 Subject: [PATCH 07/15] fix --- .github/workflows/release-tmp.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml index 9c3dbbd..9d9a026 100644 --- a/.github/workflows/release-tmp.yml +++ b/.github/workflows/release-tmp.yml @@ -35,10 +35,10 @@ jobs: id: compress with: command: c - cwd: ./test + cwd: ./target/${{ matrix.target }}/release/ files: | - target/${{ matrix.target }}/release/create-release-pr - outPath: target/${{ matrix.target }}/release/create-release-pr.tar.gz + create-release-pr + outPath: create-release-pr.tar.gz - name: Release uses: softprops/action-gh-release@v1 with: From 45ac39c2dedaae5cfbb1fc0ea5e24480bb63200a Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 17:56:15 +0900 Subject: [PATCH 08/15] fix --- .github/workflows/release-tmp.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml index 9d9a026..7b0788b 100644 --- a/.github/workflows/release-tmp.yml +++ b/.github/workflows/release-tmp.yml @@ -38,9 +38,9 @@ jobs: cwd: ./target/${{ matrix.target }}/release/ files: | create-release-pr - outPath: create-release-pr.tar.gz + outPath: create-release-pr_${{github.ref_name}}_${{ matrix.target }}.tar.gz - name: Release uses: softprops/action-gh-release@v1 with: generate_release_notes: true - files: target/${{ matrix.target }}/release/create-release-pr + files: target/${{ matrix.target }}/release/create-release-pr_${{github.ref_name}}_${{ matrix.target }}.tar.gz From 583603c44f602f3b4483a8cef4975ff2384b4cf6 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 18:09:21 +0900 Subject: [PATCH 09/15] fix --- .github/workflows/release-tmp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml index 7b0788b..ed2407c 100644 --- a/.github/workflows/release-tmp.yml +++ b/.github/workflows/release-tmp.yml @@ -43,4 +43,4 @@ jobs: uses: softprops/action-gh-release@v1 with: generate_release_notes: true - files: target/${{ matrix.target }}/release/create-release-pr_${{github.ref_name}}_${{ matrix.target }}.tar.gz + files: create-release-pr_${{github.ref_name}}_${{ matrix.target }}.tar.gz From 11370f9ff34b78a45af0178cb199840cefde16d8 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 18:39:44 +0900 Subject: [PATCH 10/15] all --- .github/workflows/release-tmp.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml index ed2407c..b4bbad5 100644 --- a/.github/workflows/release-tmp.yml +++ b/.github/workflows/release-tmp.yml @@ -11,12 +11,24 @@ jobs: fail-fast: false matrix: include: + # @see https://doc.rust-lang.org/nightly/rustc/platform-support.html + + # 64-bit Linux (kernel 3.2+, glibc 2.17+) - os: ubuntu-latest target: x86_64-unknown-linux-gnu - # - os: macOS-latest - # target: x86_64-apple-darwin - # - os: macOS-latest - # target: aarch64-apple-darwin + # ARM64 Linux (kernel 4.1, glibc 2.17+) + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + # 64-bit MinGW (Windows 7+) + - os: ubuntu-latest + target: x86_64-pc-windows-gnu + # 64-bit macOS (10.7+, Lion+) + - os: macOS-latest + target: x86_64-apple-darwin + # ARM64 macOS (11.0+, Big Sur+) + - os: macOS-latest + target: aarch64-apple-darwin + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@master From c43eb69f7e304dd417bac1463ef7c4648ce579cb Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 18:57:53 +0900 Subject: [PATCH 11/15] fix install.sh --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 216dda4..8b9a0a7 100644 --- a/install.sh +++ b/install.sh @@ -26,7 +26,7 @@ get_arch() { # echo "386" # ;; "aarch64" | "arm64" | "arm") - echo "arm64" + echo "aarch64" ;; *) echo ${NIL} @@ -45,7 +45,7 @@ get_os(){ echo "pc-windows-gnu" ;; "linux") - echo "unknown-linux-musl" + echo "unknown-linux-gnu" ;; *) echo ${NIL} From a75c535069ce299b8d962517e27b6cde117ad34a Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 19:03:05 +0900 Subject: [PATCH 12/15] fix --- .github/workflows/build.yml | 24 ------------- .github/workflows/release-tmp.yml | 58 ------------------------------ .github/workflows/release.yml | 60 ++++++++++++++++++------------- .github/workflows/test.yaml | 5 ++- 4 files changed, 40 insertions(+), 107 deletions(-) delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/release-tmp.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 94aa228..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Build - -on: - push: - branches: [master] - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Compile - id: compile - uses: rust-build/rust-build.action@v1.3.2 - with: - RUSTTARGET: x86_64-unknown-linux-musl - UPLOAD_MODE: none - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: Binary - path: | - ${{ steps.compile.outputs.BUILT_ARCHIVE }} \ No newline at end of file diff --git a/.github/workflows/release-tmp.yml b/.github/workflows/release-tmp.yml deleted file mode 100644 index b4bbad5..0000000 --- a/.github/workflows/release-tmp.yml +++ /dev/null @@ -1,58 +0,0 @@ -on: - push: - tags: - # - "v*.*.*" - - "tmp" - -jobs: - release: - name: release ${{ matrix.target }} - strategy: - fail-fast: false - matrix: - include: - # @see https://doc.rust-lang.org/nightly/rustc/platform-support.html - - # 64-bit Linux (kernel 3.2+, glibc 2.17+) - - os: ubuntu-latest - target: x86_64-unknown-linux-gnu - # ARM64 Linux (kernel 4.1, glibc 2.17+) - - os: ubuntu-latest - target: aarch64-unknown-linux-gnu - # 64-bit MinGW (Windows 7+) - - os: ubuntu-latest - target: x86_64-pc-windows-gnu - # 64-bit macOS (10.7+, Lion+) - - os: macOS-latest - target: x86_64-apple-darwin - # ARM64 macOS (11.0+, Big Sur+) - - os: macOS-latest - target: aarch64-apple-darwin - - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@master - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: ${{ matrix.target }} - override: true - - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --release --target ${{ matrix.target }} - - name: Compress action step - uses: a7ul/tar-action@v1.1.0 - id: compress - with: - command: c - cwd: ./target/${{ matrix.target }}/release/ - files: | - create-release-pr - outPath: create-release-pr_${{github.ref_name}}_${{ matrix.target }}.tar.gz - - name: Release - uses: softprops/action-gh-release@v1 - with: - generate_release_notes: true - files: create-release-pr_${{github.ref_name}}_${{ matrix.target }}.tar.gz diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c10210..8e2f5dd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,46 +1,58 @@ -on: - release: - types: [created] +on: + push: + tags: + # - "v*.*.*" + - "tmp" jobs: release: name: release ${{ matrix.target }} - runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: - - target: x86_64-pc-windows-gnu - archive: tar.gz - - target: x86_64-unknown-linux-musl - archive: tar.gz - - target: x86_64-apple-darwin - archive: tar.gz + # @see https://doc.rust-lang.org/nightly/rustc/platform-support.html + + # 64-bit Linux (kernel 3.2+, glibc 2.17+) + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + # ARM64 Linux (kernel 4.1, glibc 2.17+) + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + # 64-bit MinGW (Windows 7+) + - os: windows-latest + target: x86_64-pc-windows-gnu + # 64-bit macOS (10.7+, Lion+) + - os: macOS-latest + target: x86_64-apple-darwin + # ARM64 macOS (11.0+, Big Sur+) + - os: macOS-latest + target: aarch64-apple-darwin + + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@master - # - name: install - # run: sudo apt-get install openssl - - name: Compile and release - uses: rust-build/rust-build.action@v1.3.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - RUSTTARGET: ${{ matrix.target }} - ARCHIVE_TYPES: ${{ matrix.archive }} - uses: actions-rs/toolchain@v1 with: toolchain: stable - target: aarch64-apple-darwin + target: ${{ matrix.target }} override: true - uses: actions-rs/cargo@v1 with: use-cross: true command: build - args: --release --target aarch64-apple-darwin + args: --release --target ${{ matrix.target }} + - name: Compress action step + uses: a7ul/tar-action@v1.1.0 + id: compress + with: + command: c + cwd: ./target/${{ matrix.target }}/release/ + files: | + create-release-pr + outPath: create-release-pr_${{github.ref_name}}_${{ matrix.target }}.tar.gz - name: Release uses: softprops/action-gh-release@v1 with: - name: ${{ github.event.pull_request.body }} - tag_name: ${{ github.event.pull_request.title }} generate_release_notes: true - files: target/hoge.jar + files: create-release-pr_${{github.ref_name}}_${{ matrix.target }}.tar.gz diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f2d9aec..28cf721 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,6 +1,9 @@ name: test -on: [push] +on: + push: + branches: + - ".*" jobs: test: From 3a64b7b152c682130ba89c561718dd286abd8f37 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 19:10:21 +0900 Subject: [PATCH 13/15] fix windows --- .github/workflows/release.yml | 4 ++-- install.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e2f5dd..fe6db7b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,9 +19,9 @@ jobs: # ARM64 Linux (kernel 4.1, glibc 2.17+) - os: ubuntu-latest target: aarch64-unknown-linux-gnu - # 64-bit MinGW (Windows 7+) + # 64-bit MSVC (Windows 7+) - os: windows-latest - target: x86_64-pc-windows-gnu + target: x86_64-pc-windows-msvc # 64-bit macOS (10.7+, Lion+) - os: macOS-latest target: x86_64-apple-darwin diff --git a/install.sh b/install.sh index 8b9a0a7..5d52a4b 100644 --- a/install.sh +++ b/install.sh @@ -42,7 +42,7 @@ get_os(){ echo "apple-darwin" ;; "windows") - echo "pc-windows-gnu" + echo "pc-windows-msvc" ;; "linux") echo "unknown-linux-gnu" From 73836682cee807f7d7569533ff33590cded9f9a8 Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 19:34:52 +0900 Subject: [PATCH 14/15] fix --- .github/workflows/release.yml | 6 ++++++ .github/workflows/test.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fe6db7b..6c6c4df 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,6 +42,12 @@ jobs: use-cross: true command: build args: --release --target ${{ matrix.target }} + - name: Run build + shell: bash + run: | + if [[ "${{ runner.os }}" == "Windows" ]]; then + mv target/${{ matrix.target }}/release/create-release-pr.exe target/${{ matrix.target }}/release/create-release-pr + fi - name: Compress action step uses: a7ul/tar-action@v1.1.0 id: compress diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 28cf721..3a96eee 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,7 +3,7 @@ name: test on: push: branches: - - ".*" + - "*" jobs: test: From 81719aed50d66469fbade2e4ca864024ae8da86d Mon Sep 17 00:00:00 2001 From: Tomokatsu Iguchi Date: Fri, 30 Dec 2022 19:48:18 +0900 Subject: [PATCH 15/15] fix --- .github/workflows/release.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6c6c4df..af74507 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,7 @@ on: push: tags: - # - "v*.*.*" - - "tmp" + - "v*.*.*" jobs: release: