Skip to content

Commit

Permalink
feat:m update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
luhc228 committed Jun 1, 2024
1 parent 0ed03ab commit 66daf8e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ jobs:
os: windows-latest
target: x86_64-pc-windows-msvc
bin: toolkit.exe
name: toolkit-Windows-x86_64.zip
- os_name: macOS-x86_64
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
os: macos-13
target: x86_64-apple-darwin
bin: toolkit
name: toolkit-macOS-x86_64.zip
- os_name: macOS-aarch64
os: macos-latest
target: aarch64-apple-darwin
skip_tests: true
bin: toolkit
name: toolkit-macOS-aarch64.zip
skip_tests: true
toolchain: [stable]
steps:
- uses: actions/checkout@v4
Expand All @@ -55,21 +58,23 @@ jobs:
args: "--locked --release"
strip: true
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
# Windows
- name: Move binary to bin directory
run: |
mkdir -p bin
move target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} bin/${{ matrix.platform.os_name }}-${{ matrix.platform.bin }}
cd target/${{ matrix.platform.target }}/release
7z a ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }}
if: matrix.platform.os == 'windows-latest' && (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
# Macos & Linux
- name: Move binary to bin directory
run: |
mkdir -p bin
mv target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} bin/${{ matrix.platform.os_name }}-${{ matrix.platform.bin }}
cd target/${{ matrix.platform.target }}/release
zip ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }}
if: matrix.platform.os != 'windows-latest' && (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
- name: Publish release binary
uses: actions/upload-artifact@v4
with:
name: toolkit-${{ matrix.platform.os_name }}
path: bin/${{ matrix.platform.os_name }}-${{ matrix.platform.bin }}
path: toolkit-*
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
- name: Generate SHA-256
run: shasum -a 256 bin/${{ matrix.platform.os_name }}-${{ matrix.platform.bin }} > bin/${{ matrix.platform.os_name }}-${{ matrix.platform.bin }}.sha256
Expand All @@ -78,6 +83,6 @@ jobs:
uses: softprops/action-gh-release@v2
with:
draft: true
files: "bin/*"
files: "toolkit-*"
body_path: CHANGELOG.md
if: (startsWith(github.ref, 'refs/tags/cli-v') || github.ref == 'refs/heads/test-release')
38 changes: 23 additions & 15 deletions src/utils/download_file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use futures_util::StreamExt;
use regex::Regex;
use reqwest::{Client, Response};
use reqwest::{Client, Response, Url};
use std::{cmp::min, env, fs::File, io::Write, path::PathBuf};

pub async fn download_file(url: &str, set_process_message: impl Fn(&str)) -> Result<PathBuf> {
Expand Down Expand Up @@ -50,19 +50,27 @@ fn get_file_name_from_response(response: &Response) -> Result<String> {
.ok_or(anyhow::anyhow!("Failed to get content-disposition header"))?
.to_str()
.map_err(|err| anyhow::anyhow!("Failed to convert content-disposition header to string. Error: {}", err))?;
let re =
Regex::new(r"filename=([^;]+)").map_err(|err| anyhow::anyhow!("Failed to create regex. Error: {}", err))?;
let file_name = re
.captures(content_disposition)
.ok_or(anyhow::anyhow!(
"Failed to get file name from content-disposition header"
))?
.get(1)
.ok_or(anyhow::anyhow!(
"Failed to get file name from content-disposition header"
))?
.as_str()
.replace('"', "");
if content_disposition == "attachment" {
let url = response.url();
let filename = Url::parse(response.url().as_str())
.map_err(|err| anyhow::anyhow!("Failed to parse url '{}'. Error: {}", url, err))
.map(|url| url.path_segments().unwrap().last().unwrap().to_string())?;
Ok(filename)
} else {
let re =
Regex::new(r"filename=([^;]+)").map_err(|err| anyhow::anyhow!("Failed to create regex. Error: {}", err))?;
let file_name = re
.captures(content_disposition)
.ok_or(anyhow::anyhow!(
"Failed to get file name from content-disposition header"
))?
.get(1)
.ok_or(anyhow::anyhow!(
"Failed to get file name from content-disposition header"
))?
.as_str()
.replace('"', "");

Ok(file_name)
Ok(file_name)
}
}

0 comments on commit 66daf8e

Please sign in to comment.