Speedup ci (#1724)

* Optimize binstalk-git-repo-api

Use a dedicated github token in CI

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Speedup CI using `cargo-nextest`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix release profile override on Windows

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Optimize unit test in binstalk-registry

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Use `secrets.CI_RELEASE_TEST_GITHUB_TOKEN` for just-setup

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix unit testing in justfile

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Add retry on rate limit in unit testing

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Only use `CI_UNIT_TEST_GITHUB_TOKEN` in unit testing

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix `test_get_repo_info`: Retry on rate limit

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix `test_has_release_artifact_and_download_artifacts`

Retry on rate limit

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

---------

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-06-11 00:12:44 +10:00 committed by GitHub
parent 52f172c713
commit 3aae883467
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 356 additions and 308 deletions

View file

@ -56,11 +56,14 @@ jobs:
env:
# just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN }}
with:
tools: cargo-nextest
- run: just test
env:
GITHUB_TOKEN: ${{ secrets.CI_TEST_GITHUB_TOKEN }}
CI_UNIT_TEST_GITHUB_TOKEN: ${{ secrets.CI_UNIT_TEST_GITHUB_TOKEN }}
cross-check:
strategy:
@ -97,7 +100,7 @@ jobs:
env:
# just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN }}
- run: just avoid-dev-deps
- run: just check
@ -118,6 +121,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/just-setup
env:
# just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN }}
- run: just toolchain rustfmt,clippy
- run: just avoid-dev-deps
@ -135,7 +142,7 @@ jobs:
uses: cargo-bins/release-meta@v1
with:
event-data: ${{ toJSON(github.event) }}
extract-notes-under: '### Release notes'
extract-notes-under: "### Release notes"
release-dry-run:
needs: pr-info
@ -283,7 +290,6 @@ jobs:
# and build quite a few unused dependencies.
working-directory: crates/detect-targets
# Dummy job to have a stable name for the "all tests pass" requirement
tests-pass:
name: Tests pass

View file

@ -28,10 +28,21 @@ jobs:
matrix:
include:
- { o: macos-14, t: x86_64-apple-darwin, r: true }
- { o: macos-14, t: x86_64h-apple-darwin, }
- { o: macos-14, t: x86_64h-apple-darwin }
- { o: macos-14, t: aarch64-apple-darwin }
- { o: ubuntu-latest, t: x86_64-unknown-linux-gnu, g: 2.17, r: true, c: true }
- { o: ubuntu-latest, t: armv7-unknown-linux-gnueabihf, g: 2.17, c: true }
- {
o: ubuntu-latest,
t: x86_64-unknown-linux-gnu,
g: 2.17,
r: true,
c: true,
}
- {
o: ubuntu-latest,
t: armv7-unknown-linux-gnueabihf,
g: 2.17,
c: true,
}
- { o: ubuntu-latest, t: aarch64-unknown-linux-gnu, g: 2.17, c: true }
- { o: ubuntu-latest, t: x86_64-unknown-linux-musl, r: true, c: true }
- { o: ubuntu-latest, t: armv7-unknown-linux-musleabihf, c: true }
@ -57,16 +68,20 @@ jobs:
- name: Override release profile lto settings
if: inputs.CARGO_PROFILE_RELEASE_LTO
run: echo "CARGO_PROFILE_RELEASE_LTO=${{ inputs.CARGO_PROFILE_RELEASE_LTO }}" >> "$GITHUB_ENV"
shell: bash
- name: Override release profile codegen-units settings
if: inputs.CARGO_PROFILE_RELEASE_CODEGEN_UNITS
run: echo "CARGO_PROFILE_RELEASE_CODEGEN_UNITS=${{ inputs.CARGO_PROFILE_RELEASE_CODEGEN_UNITS }}" >> "$GITHUB_ENV"
shell: bash
- uses: ./.github/actions/just-setup
with:
tools: cargo-auditable,rsign2,rage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN }}
- run: just toolchain rust-src

View file

@ -508,7 +508,7 @@ mod test {
let mut gh_clients = vec![GhApiClient::new(client.clone(), None)];
if let Ok(token) = env::var("GITHUB_TOKEN") {
if let Ok(token) = env::var("CI_UNIT_TEST_GITHUB_TOKEN") {
gh_clients.push(GhApiClient::new(client, Some(token.into())));
}
@ -535,30 +535,8 @@ mod test {
let mut tests: Vec<(_, _)> = Vec::new();
for client in create_client() {
for repo in PUBLIC_REPOS {
let spawn_get_repo_info_task = |repo| {
let client = client.clone();
tests.push((
Some(RepoInfo::new(repo.clone(), false)),
tokio::spawn(async move { client.get_repo_info(&repo).await }),
));
}
for repo in NON_EXISTENT_REPOS {
let client = client.clone();
tests.push((
None,
tokio::spawn(async move { client.get_repo_info(&repo).await }),
));
}
if client.has_gh_token() {
for repo in PRIVATE_REPOS {
let client = client.clone();
tests.push((
Some(RepoInfo::new(repo.clone(), true)),
tokio::spawn(async move {
loop {
match client.get_repo_info(&repo).await {
@ -568,7 +546,25 @@ mod test {
res => break res,
}
}
}),
})
};
for repo in PUBLIC_REPOS {
tests.push((
Some(RepoInfo::new(repo.clone(), false)),
spawn_get_repo_info_task(repo),
));
}
for repo in NON_EXISTENT_REPOS {
tests.push((None, spawn_get_repo_info_task(repo)));
}
if client.has_gh_token() {
for repo in PRIVATE_REPOS {
tests.push((
Some(RepoInfo::new(repo.clone(), true)),
spawn_get_repo_info_task(repo),
));
}
}
@ -606,6 +602,20 @@ mod test {
let mut tasks = Vec::new();
for client in create_client() {
async fn has_release_artifact(
client: &GhApiClient,
artifact: &GhReleaseArtifact,
) -> Result<Option<GhReleaseArtifactUrl>, GhApiError> {
loop {
match client.has_release_artifact(artifact.clone()).await {
Err(GhApiError::RateLimit { retry_after }) => {
sleep(retry_after.unwrap_or(DEFAULT_RETRY_AFTER)).await
}
res => break res,
}
}
}
for (release, artifacts) in RELEASES {
for artifact_name in artifacts {
let client = client.clone();
@ -632,15 +642,10 @@ mod test {
.into_bytes(),
)
});
let artifact_url = loop {
match client.has_release_artifact(artifact.clone()).await {
Err(GhApiError::RateLimit { retry_after }) => {
sleep(retry_after.unwrap_or(DEFAULT_RETRY_AFTER)).await
}
res => break res.unwrap().unwrap(),
}
};
let artifact_url = has_release_artifact(&client, &artifact)
.await
.unwrap()
.unwrap();
if let Some(browser_download_task) = browser_download_task {
let artifact_download_data = loop {
@ -666,11 +671,13 @@ mod test {
let client = client.clone();
tasks.push(tokio::spawn(async move {
assert_eq!(
client
.has_release_artifact(GhReleaseArtifact {
has_release_artifact(
&client,
&GhReleaseArtifact {
release,
artifact_name: "123z".to_compact_string(),
})
}
)
.await
.unwrap(),
None
@ -683,11 +690,13 @@ mod test {
tasks.push(tokio::spawn(async move {
assert_eq!(
client
.has_release_artifact(GhReleaseArtifact {
has_release_artifact(
&client,
&GhReleaseArtifact {
release,
artifact_name: "1234".to_compact_string(),
})
}
)
.await
.unwrap(),
None

View file

@ -218,7 +218,7 @@ mod test {
/// Mark this as an async fn so that you won't accidentally use it in
/// sync context.
async fn create_client() -> Client {
fn create_client() -> Client {
Client::new(
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
None,
@ -231,8 +231,16 @@ mod test {
#[tokio::test]
async fn test_crates_io_sparse_registry() {
let client = create_client().await;
let client = create_client();
let crate_name = "cargo-binstall";
let version_req = &VersionReq::parse("=1.0.0").unwrap();
let serialized_manifest_from_sparse_task = tokio::spawn({
let client = client.clone();
let version_req = version_req.clone();
async move {
let sparse_registry: Registry = Registry::crates_io_sparse_registry();
assert!(
matches!(sparse_registry, Registry::Sparse(_)),
@ -240,22 +248,23 @@ mod test {
sparse_registry
);
let crate_name = "cargo-binstall";
let version_req = &VersionReq::parse("=1.0.0").unwrap();
let manifest_from_sparse = sparse_registry
.fetch_crate_matched(client.clone(), crate_name, version_req)
.fetch_crate_matched(client, crate_name, &version_req)
.await
.unwrap();
to_string(&manifest_from_sparse).unwrap()
}
});
let manifest_from_cratesio_api = fetch_crate_cratesio_api(client, crate_name, version_req)
.await
.unwrap();
let serialized_manifest_from_sparse = to_string(&manifest_from_sparse).unwrap();
let serialized_manifest_from_cratesio_api = to_string(&manifest_from_cratesio_api).unwrap();
assert_eq!(
serialized_manifest_from_sparse,
serialized_manifest_from_sparse_task.await.unwrap(),
serialized_manifest_from_cratesio_api
);
}
@ -263,8 +272,16 @@ mod test {
#[cfg(feature = "git")]
#[tokio::test]
async fn test_crates_io_git_registry() {
let client = create_client().await;
let client = create_client();
let crate_name = "cargo-binstall";
let version_req = &VersionReq::parse("=1.0.0").unwrap();
let serialized_manifest_from_git_task = tokio::spawn({
let version_req = version_req.clone();
let client = client.clone();
async move {
let git_registry: Registry = "https://github.com/rust-lang/crates.io-index"
.parse()
.unwrap();
@ -274,23 +291,23 @@ mod test {
git_registry
);
let crate_name = "cargo-binstall";
let version_req = &VersionReq::parse("=1.0.0").unwrap();
let manifest_from_git = git_registry
.fetch_crate_matched(client.clone(), crate_name, version_req)
.fetch_crate_matched(client, crate_name, &version_req)
.await
.unwrap();
to_string(&manifest_from_git).unwrap()
}
});
let manifest_from_cratesio_api = Registry::default()
.fetch_crate_matched(client, crate_name, version_req)
.await
.unwrap();
let serialized_manifest_from_git = to_string(&manifest_from_git).unwrap();
let serialized_manifest_from_cratesio_api = to_string(&manifest_from_cratesio_api).unwrap();
assert_eq!(
serialized_manifest_from_git,
serialized_manifest_from_git_task.await.unwrap(),
serialized_manifest_from_cratesio_api
);
}

View file

@ -260,7 +260,8 @@ e2e-test-tls: (e2e-test "tls" "1.2") (e2e-test "tls" "1.3")
e2e-tests: e2e-test-live e2e-test-manifest-path e2e-test-git e2e-test-other-repos e2e-test-strategies e2e-test-version-syntax e2e-test-upgrade e2e-test-tls e2e-test-self-upgrade-no-symlink e2e-test-uninstall e2e-test-subcrate e2e-test-no-track e2e-test-registries e2e-test-signing e2e-test-continue-on-failure e2e-test-private-github-repo
unit-tests: print-env
{{cargo-bin}} test {{cargo-build-args}}
cargo nextest run {{cargo-build-args}}
cargo test --doc {{cargo-build-args}}
test: unit-tests build e2e-tests