-
Notifications
You must be signed in to change notification settings - Fork 0
Release/v2.0.4 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release/v2.0.4 #41
Changes from all commits
30f1e6d
4b79451
5ed636f
932ca55
4b9401b
79dcb2d
9818862
a91d6a7
7abb746
ae7190d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -154,3 +154,23 @@ | |||||||
| asset_name: ${{ matrix.asset_name }}.tar.gz | ||||||||
| asset_content_type: application/x-gzip | ||||||||
| upload_url: ${{ needs.documents.outputs.upload_url }} | ||||||||
|
|
||||||||
| publish_to_crates_io: | ||||||||
| runs-on: ubuntu-latest | ||||||||
| needs: publish | ||||||||
| outputs: | ||||||||
| appname: ${{ needs.publish.outputs.appname }} | ||||||||
| tag: ${{ needs.publish.outputs.tag }} | ||||||||
| steps: | ||||||||
| - name: Checkout | ||||||||
| uses: actions/checkout@v4 | ||||||||
|
|
||||||||
| - name: Authenticate with custom registry | ||||||||
| id: auth | ||||||||
| uses: rust-lang/crates-io-auth-action@v1 | ||||||||
|
|
||||||||
| - name: publish | ||||||||
| env: | ||||||||
| CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} | ||||||||
| run: | ||||||||
| cargo publish --package sibling | ||||||||
|
Comment on lines
+175
to
+176
|
||||||||
| run: | |
| cargo publish --package sibling | |
| run: cargo publish --package sibling |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,66 @@ | ||
| use std::path::Path; | ||
|
|
||
| use crate::cli::PrintingOpts; | ||
| use sibling::{Dir, Dirs, Result}; | ||
| use crate::cli::{Format, PrintingOpts}; | ||
| use sibling::{Dir, Dirs}; | ||
|
|
||
| pub(crate) fn result_string( | ||
| dirs: &Dirs, | ||
| next: Option<Dir<'_>>, | ||
| opts: &PrintingOpts, | ||
| ) -> Result<String> { | ||
| if opts.csv { | ||
| csv_string(dirs, next, opts.absolute) | ||
| } else if opts.list { | ||
| list_string(dirs, next, opts) | ||
| } else if next.is_none() { | ||
| no_more_dir_string(dirs, opts) | ||
| } else { | ||
| result_string_impl(dirs, next, opts) | ||
| ) -> String { | ||
| match opts.format { | ||
| Format::Json => json_string(dirs, next, opts.absolute), | ||
| Format::Csv => csv_string(dirs, next, opts.absolute), | ||
| Format::List => list_string(dirs, next.as_ref(), opts), | ||
| Format::Default => { | ||
| if next.is_none() { | ||
| no_more_dir_string(dirs, opts) | ||
| } else { | ||
| result_string_impl(dirs, next, opts) | ||
| } | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| fn csv_string(dirs: &Dirs, next: Option<Dir<'_>>, absolute: bool) -> Result<String> { | ||
| fn json_string(dirs: &Dirs, next: Option<Dir<'_>>, absolute: bool) -> String { | ||
| let current = dirs.current(); | ||
| let next_path = next.as_ref().map(|n| pathbuf_to_string(Some(n.path()), absolute)); | ||
| format!( | ||
| r#"{{"current":{{"path":"{}","index":{}}},"next":{{"path":"{}","index":{}}},"total":{}}}"#, | ||
| pathbuf_to_string(Some(dirs.current().path()), absolute), | ||
| current.index() + 1, | ||
| next_path.unwrap_or_default(), | ||
| next.map_or(-1, |n| i32::try_from(n.index()).unwrap() + 1), | ||
|
||
| dirs.len() | ||
| ) | ||
| } | ||
|
Comment on lines
+25
to
+36
|
||
|
|
||
| fn csv_string(dirs: &Dirs, next: Option<Dir<'_>>, absolute: bool) -> String { | ||
| let current = dirs.current(); | ||
| Ok(format!( | ||
| r##""{}","{}",{},{},{}"##, | ||
| format!( | ||
| r#""{}","{}",{},{},{}"#, | ||
| pathbuf_to_string(Some(dirs.current().path()), absolute), | ||
| pathbuf_to_string(next.as_ref().map(|p| p.path()), absolute), | ||
| pathbuf_to_string(next.as_ref().map(Dir::path), absolute), | ||
| current.index() + 1, | ||
| next.map(|n| n.index() as i32 + 1).unwrap_or(-1), | ||
| next.map_or(-1, |n| i32::try_from(n.index()).unwrap() + 1), | ||
|
||
| dirs.len() | ||
| )) | ||
| ) | ||
| } | ||
|
|
||
| fn no_more_dir_string(dirs: &Dirs, opts: &PrintingOpts) -> Result<String> { | ||
| fn no_more_dir_string(dirs: &Dirs, opts: &PrintingOpts) -> String { | ||
| if opts.parent { | ||
| Ok(pathbuf_to_string(Some(dirs.parent()), opts.absolute)) | ||
| pathbuf_to_string(Some(dirs.parent()), opts.absolute) | ||
| } else { | ||
| Ok(String::from("no more sibling directory")) | ||
| String::from("no more sibling directory") | ||
| } | ||
| } | ||
|
|
||
| fn list_string(dirs: &Dirs, next: Option<Dir<'_>>, opts: &PrintingOpts) -> Result<String> { | ||
| fn list_string(dirs: &Dirs, next: Option<&Dir<'_>>, opts: &PrintingOpts) -> String { | ||
| let mut result = vec![]; | ||
| let current = dirs.current(); | ||
| let next_index = next.clone().map(|n| n.index() as i32).unwrap_or(-1); | ||
| let next_index = next.map_or(-1, |n| i32::try_from(n.index()).unwrap()); | ||
|
||
| for (i, dir) in dirs.directories().enumerate() { | ||
| let prefix = if i as i32 == next_index { | ||
| let prefix = if i32::try_from(i) == Ok(next_index) { | ||
| "> " | ||
| } else if i == current.index() { | ||
| "* " | ||
|
|
@@ -58,21 +74,21 @@ fn list_string(dirs: &Dirs, next: Option<Dir<'_>>, opts: &PrintingOpts) -> Resul | |
| pathbuf_to_string(Some(dir), opts.absolute) | ||
| )); | ||
| } | ||
| Ok(result.join("\n")) | ||
| result.join("\n") | ||
| } | ||
|
|
||
| fn result_string_impl(dirs: &Dirs, next: Option<Dir<'_>>, opts: &PrintingOpts) -> Result<String> { | ||
| fn result_string_impl(dirs: &Dirs, next: Option<Dir<'_>>, opts: &PrintingOpts) -> String { | ||
| let r = if opts.progress { | ||
| format!( | ||
| "{} ({}/{})", | ||
| pathbuf_to_string(next.as_ref().map(|n| n.path()), opts.absolute), | ||
| next.map(|n| n.index() as i32).unwrap_or(-1) + 1, | ||
| pathbuf_to_string(next.as_ref().map(Dir::path), opts.absolute), | ||
| next.map_or(-1, |n| i32::try_from(n.index()).unwrap()) + 1, | ||
|
||
| dirs.len() | ||
| ) | ||
| } else { | ||
| pathbuf_to_string(next.as_ref().map(|n| n.path()), opts.absolute).to_string() | ||
| pathbuf_to_string(next.as_ref().map(Dir::path), opts.absolute).to_string() | ||
| }; | ||
| Ok(r) | ||
| r | ||
| } | ||
|
|
||
| fn pathbuf_to_string(path: Option<&Path>, absolute: bool) -> String { | ||
|
|
@@ -87,6 +103,6 @@ fn pathbuf_to_string(path: Option<&Path>, absolute: bool) -> String { | |
| p.to_string_lossy().to_string() | ||
| } | ||
| } | ||
| None => "".to_string(), | ||
| None => String::new(), | ||
| } | ||
| } | ||
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 5 months ago
In general, the fix is to add an explicit
permissionsblock so theGITHUB_TOKENis scoped to the least privileges required. You can add it at the top level (applying to all jobs) or per‑job. Since all jobs here are part of the same release/publish pipeline and at least thesetup,documentsandpublishjobs clearly need to write releases (which usescontents: write), the simplest safe change is to define a workflow‑levelpermissionsblock withcontents: write. That both satisfies CodeQL (permissions are now explicit) and matches the actual needs of the workflow.The single best way to fix this without changing behavior is:
permissionsblock right after thename: Publish(or just afteron:) in.github/workflows/publish.yaml.contents: writeso the jobs that create and upload releases continue to function.none), but we won’t guess additional scopes:contents: writeis clearly needed and sufficient for interacting with releases.Concretely, edit
.github/workflows/publish.yamlnear the top, add:leaving all jobs and steps unchanged.