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

@ -51,16 +51,19 @@ jobs:
CARGO_BUILD_TARGET: ${{ matrix.target }} CARGO_BUILD_TARGET: ${{ matrix.target }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: ./.github/actions/just-setup - uses: ./.github/actions/just-setup
env: env:
# just-setup use binstall to install sccache, # just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN. # 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 - run: just test
env: env:
GITHUB_TOKEN: ${{ secrets.CI_TEST_GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.CI_TEST_GITHUB_TOKEN }}
CI_UNIT_TEST_GITHUB_TOKEN: ${{ secrets.CI_UNIT_TEST_GITHUB_TOKEN }}
cross-check: cross-check:
strategy: strategy:
@ -85,22 +88,22 @@ jobs:
env: env:
CARGO_BUILD_TARGET: ${{ matrix.target }} CARGO_BUILD_TARGET: ${{ matrix.target }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Enable cargo-zigbuild - name: Enable cargo-zigbuild
if: matrix.os == 'ubuntu-latest' if: matrix.os == 'ubuntu-latest'
run: echo JUST_USE_CARGO_ZIGBUILD=true >> "$GITHUB_ENV" run: echo JUST_USE_CARGO_ZIGBUILD=true >> "$GITHUB_ENV"
- uses: ./.github/actions/just-setup - uses: ./.github/actions/just-setup
with: with:
tools: cargo-hack@0.6.10 tools: cargo-hack@0.6.10
env: env:
# just-setup use binstall to install sccache, # just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN. # 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 avoid-dev-deps
- run: just check - run: just check
lint: lint:
strategy: strategy:
@ -116,12 +119,16 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: ./.github/actions/just-setup - 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 toolchain rustfmt,clippy
- run: just avoid-dev-deps - run: just avoid-dev-deps
- run: just lint - run: just lint
pr-info: pr-info:
outputs: outputs:
@ -130,12 +137,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- id: meta - id: meta
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
uses: cargo-bins/release-meta@v1 uses: cargo-bins/release-meta@v1
with: with:
event-data: ${{ toJSON(github.event) }} event-data: ${{ toJSON(github.event) }}
extract-notes-under: '### Release notes' extract-notes-under: "### Release notes"
release-dry-run: release-dry-run:
needs: pr-info needs: pr-info
@ -158,42 +165,42 @@ jobs:
env: env:
CARGO_BUILD_TARGET: x86_64-unknown-linux-musl CARGO_BUILD_TARGET: x86_64-unknown-linux-musl
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Install ${{ env.CARGO_BUILD_TARGET }} target - name: Install ${{ env.CARGO_BUILD_TARGET }} target
run: | run: |
rustup target add $CARGO_BUILD_TARGET rustup target add $CARGO_BUILD_TARGET
pip3 install -r zigbuild-requirements.txt pip3 install -r zigbuild-requirements.txt
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: with:
cache-all-crates: true cache-all-crates: true
- name: Build detect-targets - name: Build detect-targets
run: | run: |
cargo zigbuild --features cli-logging --target $CARGO_BUILD_TARGET cargo zigbuild --features cli-logging --target $CARGO_BUILD_TARGET
# Set working directory here, otherwise `cargo-zigbuild` would download # Set working directory here, otherwise `cargo-zigbuild` would download
# and build quite a few unused dependencies. # and build quite a few unused dependencies.
working-directory: crates/detect-targets working-directory: crates/detect-targets
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: detect-targets name: detect-targets
path: target/${{ env.CARGO_BUILD_TARGET }}/debug/detect-targets path: target/${{ env.CARGO_BUILD_TARGET }}/debug/detect-targets
detect-targets-alpine-test: detect-targets-alpine-test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: detect-targets-build needs: detect-targets-build
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: detect-targets name: detect-targets
- run: chmod +x detect-targets - run: chmod +x detect-targets
- name: Run test in alpine - name: Run test in alpine
run: | run: |
docker run --rm \ docker run --rm \
--mount src="$PWD/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \ --mount src="$PWD/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \
--mount src="$PWD/.github/scripts/test-detect-targets-musl.sh",dst=/usr/local/bin/test.sh,type=bind \ --mount src="$PWD/.github/scripts/test-detect-targets-musl.sh",dst=/usr/local/bin/test.sh,type=bind \
alpine /bin/ash -c "apk update && apk add bash && test.sh x86_64-unknown-linux-musl" alpine /bin/ash -c "apk update && apk add bash && test.sh x86_64-unknown-linux-musl"
detect-targets-ubuntu-test: detect-targets-ubuntu-test:
needs: detect-targets-build needs: detect-targets-build
@ -205,15 +212,15 @@ jobs:
- ubuntu-latest - ubuntu-latest
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: detect-targets name: detect-targets
- run: chmod +x detect-targets - run: chmod +x detect-targets
- name: Run test in ubuntu - name: Run test in ubuntu
run: | run: |
set -exuo pipefail set -exuo pipefail
[ "$(./detect-targets)" = "$(printf 'x86_64-unknown-linux-gnu\nx86_64-unknown-linux-musl')" ] [ "$(./detect-targets)" = "$(printf 'x86_64-unknown-linux-gnu\nx86_64-unknown-linux-musl')" ]
detect-targets-more-glibc-test: detect-targets-more-glibc-test:
needs: detect-targets-build needs: detect-targets-build
@ -228,33 +235,33 @@ jobs:
- fedora - fedora
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: detect-targets name: detect-targets
- run: chmod +x detect-targets - run: chmod +x detect-targets
- name: Run test - name: Run test
run: | run: |
set -exuo pipefail set -exuo pipefail
[ "$(docker run --rm \ [ "$(docker run --rm \
--mount src="$PWD/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \ --mount src="$PWD/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \
${{ matrix.container }} detect-targets )" = "$(printf 'x86_64-unknown-linux-gnu\nx86_64-unknown-linux-musl')" ] ${{ matrix.container }} detect-targets )" = "$(printf 'x86_64-unknown-linux-gnu\nx86_64-unknown-linux-musl')" ]
detect-targets-nix-test: detect-targets-nix-test:
needs: detect-targets-build needs: detect-targets-build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: detect-targets name: detect-targets
- run: chmod +x detect-targets - run: chmod +x detect-targets
- name: Run test - name: Run test
run: | run: |
set -exuo pipefail set -exuo pipefail
[ "$(docker run --rm \ [ "$(docker run --rm \
--mount src="$PWD/detect-targets",dst=/detect-targets,type=bind \ --mount src="$PWD/detect-targets",dst=/detect-targets,type=bind \
nixos/nix /detect-targets )" = x86_64-unknown-linux-musl ] nixos/nix /detect-targets )" = x86_64-unknown-linux-musl ]
detect-targets-android-check: detect-targets-android-check:
strategy: strategy:
@ -268,40 +275,39 @@ jobs:
CARGO_BUILD_TARGET: ${{ matrix.target }} CARGO_BUILD_TARGET: ${{ matrix.target }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Add ${{ matrix.target }} - name: Add ${{ matrix.target }}
run: rustup target add ${{ matrix.target }} run: rustup target add ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: true
- name: Build detect-targets
run: |
cargo check --target ${{ matrix.target }}
# Set working directory here, otherwise `cargo-check` would download
# and build quite a few unused dependencies.
working-directory: crates/detect-targets
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: true
- name: Build detect-targets
run: |
cargo check --target ${{ matrix.target }}
# Set working directory here, otherwise `cargo-check` would download
# 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 # Dummy job to have a stable name for the "all tests pass" requirement
tests-pass: tests-pass:
name: Tests pass name: Tests pass
needs: needs:
- test - test
- cross-check - cross-check
- lint - lint
- release-dry-run - release-dry-run
- detect-targets-build - detect-targets-build
- detect-targets-alpine-test - detect-targets-alpine-test
- detect-targets-ubuntu-test - detect-targets-ubuntu-test
- detect-targets-more-glibc-test - detect-targets-more-glibc-test
- detect-targets-nix-test - detect-targets-nix-test
- detect-targets-android-check - detect-targets-android-check
if: always() # always run even if dependencies fail if: always() # always run even if dependencies fail
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# fail if ANY dependency has failed or cancelled # fail if ANY dependency has failed or cancelled
- if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')" - if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')"
run: exit 1 run: exit 1
- run: exit 0 - run: exit 0

View file

@ -27,17 +27,28 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
include: include:
- { o: macos-14, t: x86_64-apple-darwin, r: true } - { 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: 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,
- { o: ubuntu-latest, t: aarch64-unknown-linux-gnu, g: 2.17, c: true } t: x86_64-unknown-linux-gnu,
- { o: ubuntu-latest, t: x86_64-unknown-linux-musl, r: true, c: true } g: 2.17,
- { o: ubuntu-latest, t: armv7-unknown-linux-musleabihf, c: true } r: true,
- { o: ubuntu-latest, t: aarch64-unknown-linux-musl, c: true } c: true,
- { o: windows-latest, t: x86_64-pc-windows-msvc, r: true } }
- { o: windows-latest, t: aarch64-pc-windows-msvc } - {
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 }
- { o: ubuntu-latest, t: aarch64-unknown-linux-musl, c: true }
- { o: windows-latest, t: x86_64-pc-windows-msvc, r: true }
- { o: windows-latest, t: aarch64-pc-windows-msvc }
name: ${{ matrix.t }} name: ${{ matrix.t }}
runs-on: ${{ matrix.o }} runs-on: ${{ matrix.o }}
@ -52,73 +63,77 @@ jobs:
JUST_ENABLE_H3: true JUST_ENABLE_H3: true
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Override release profile lto settings - name: Override release profile lto settings
if: inputs.CARGO_PROFILE_RELEASE_LTO if: inputs.CARGO_PROFILE_RELEASE_LTO
run: echo "CARGO_PROFILE_RELEASE_LTO=${{ inputs.CARGO_PROFILE_RELEASE_LTO }}" >> "$GITHUB_ENV" run: echo "CARGO_PROFILE_RELEASE_LTO=${{ inputs.CARGO_PROFILE_RELEASE_LTO }}" >> "$GITHUB_ENV"
shell: bash
- name: Override release profile codegen-units settings - name: Override release profile codegen-units settings
if: inputs.CARGO_PROFILE_RELEASE_CODEGEN_UNITS if: inputs.CARGO_PROFILE_RELEASE_CODEGEN_UNITS
run: echo "CARGO_PROFILE_RELEASE_CODEGEN_UNITS=${{ inputs.CARGO_PROFILE_RELEASE_CODEGEN_UNITS }}" >> "$GITHUB_ENV" run: echo "CARGO_PROFILE_RELEASE_CODEGEN_UNITS=${{ inputs.CARGO_PROFILE_RELEASE_CODEGEN_UNITS }}" >> "$GITHUB_ENV"
shell: bash
- uses: ./.github/actions/just-setup - uses: ./.github/actions/just-setup
with: with:
tools: cargo-auditable,rsign2,rage tools: cargo-auditable,rsign2,rage
env: 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 - run: just toolchain rust-src
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: minisign.pub name: minisign.pub
- run: just package - run: just package
- if: runner.os == 'Windows' - if: runner.os == 'Windows'
run: Get-ChildItem packages/ run: Get-ChildItem packages/
- if: runner.os != 'Windows' - if: runner.os != 'Windows'
run: ls -shal packages/ run: ls -shal packages/
- name: Ensure release binary is runnable - name: Ensure release binary is runnable
if: "matrix.r" if: "matrix.r"
run: just e2e-tests run: just e2e-tests
env: env:
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN }}
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: minisign.key.age name: minisign.key.age
- name: Sign package - name: Sign package
env: env:
AGE_KEY_SECRET: ${{ secrets.AGE_KEY_SECRET }} AGE_KEY_SECRET: ${{ secrets.AGE_KEY_SECRET }}
shell: bash shell: bash
run: .github/scripts/ephemeral-sign.sh packages/cargo-binstall-* run: .github/scripts/ephemeral-sign.sh packages/cargo-binstall-*
- if: fromJSON(inputs.publish).is-release == 'true' - if: fromJSON(inputs.publish).is-release == 'true'
name: Upload to release name: Upload to release
uses: svenstaro/upload-release-action@v2 uses: svenstaro/upload-release-action@v2
with: with:
repo_token: ${{ secrets.GITHUB_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }}
release_name: v${{ fromJSON(inputs.publish).version }} release_name: v${{ fromJSON(inputs.publish).version }}
tag: v${{ fromJSON(inputs.publish).version }} tag: v${{ fromJSON(inputs.publish).version }}
body: ${{ fromJSON(inputs.publish).notes }} body: ${{ fromJSON(inputs.publish).notes }}
file: packages/cargo-binstall-* file: packages/cargo-binstall-*
file_glob: true file_glob: true
prerelease: true prerelease: true
- if: "fromJSON(inputs.publish).is-release != 'true' || runner.os == 'macOS'" - if: "fromJSON(inputs.publish).is-release != 'true' || runner.os == 'macOS'"
name: Upload artifact name: Upload artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: ${{ matrix.t }} name: ${{ matrix.t }}
path: packages/cargo-binstall-* path: packages/cargo-binstall-*
retention-days: 1 retention-days: 1
- name: Upload timings - name: Upload timings
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: ${{ matrix.t }}-cargo-timings name: ${{ matrix.t }}-cargo-timings
path: target/cargo-timings path: target/cargo-timings
retention-days: 1 retention-days: 1
lipo: lipo:
needs: build needs: build
@ -130,58 +145,58 @@ jobs:
JUST_FOR_RELEASE: true JUST_FOR_RELEASE: true
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: taiki-e/install-action@v2 - uses: taiki-e/install-action@v2
with: with:
tool: just,rsign2,rage tool: just,rsign2,rage
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: x86_64h-apple-darwin name: x86_64h-apple-darwin
path: packages/ path: packages/
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: x86_64-apple-darwin name: x86_64-apple-darwin
path: packages/ path: packages/
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: aarch64-apple-darwin name: aarch64-apple-darwin
path: packages/ path: packages/
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: minisign.pub name: minisign.pub
- run: ls -shalr packages/ - run: ls -shalr packages/
- run: just repackage-lipo - run: just repackage-lipo
- run: ls -shal packages/ - run: ls -shal packages/
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
with: with:
name: minisign.key.age name: minisign.key.age
- env: - env:
AGE_KEY_SECRET: ${{ secrets.AGE_KEY_SECRET }} AGE_KEY_SECRET: ${{ secrets.AGE_KEY_SECRET }}
shell: bash shell: bash
run: .github/scripts/ephemeral-sign.sh packages/cargo-binstall-universal-* run: .github/scripts/ephemeral-sign.sh packages/cargo-binstall-universal-*
- if: fromJSON(inputs.publish).is-release == 'true' - if: fromJSON(inputs.publish).is-release == 'true'
name: Upload to release name: Upload to release
uses: svenstaro/upload-release-action@v2 uses: svenstaro/upload-release-action@v2
with: with:
repo_token: ${{ secrets.GITHUB_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: v${{ fromJSON(inputs.publish).version }} tag: v${{ fromJSON(inputs.publish).version }}
release_name: v${{ fromJSON(inputs.publish).version }} release_name: v${{ fromJSON(inputs.publish).version }}
body: ${{ fromJSON(inputs.publish).notes }} body: ${{ fromJSON(inputs.publish).notes }}
file: packages/cargo-binstall-universal-* file: packages/cargo-binstall-universal-*
file_glob: true file_glob: true
overwrite: true overwrite: true
prerelease: true prerelease: true
- if: fromJSON(inputs.publish).is-release != 'true' - if: fromJSON(inputs.publish).is-release != 'true'
name: Upload artifact name: Upload artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: universal-apple-darwin name: universal-apple-darwin
path: packages/cargo-binstall-universal-* path: packages/cargo-binstall-universal-*
retention-days: 1 retention-days: 1

View file

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

View file

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