From fcd6b0f54853aff4b11c053ffe43afc32cd676d1 Mon Sep 17 00:00:00 2001 From: Nghia Date: Wed, 11 Dec 2024 14:53:06 +0100 Subject: [PATCH] ci: run nextest for cross build (#571) * ci: run nextest for cross build * backend/time: sleep a little bit more * typo * typo * upload * upload even if failure --- .github/workflows/coverage.yaml | 13 ++++---- .github/workflows/main.yaml | 55 +++++++++++++++++---------------- ci/cross-pre-build.sh | 2 ++ nghe-backend/src/time/mod.rs | 3 +- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index f65afc7c4..b9b9edc6e 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -92,19 +92,20 @@ jobs: LASTFM_KEY: ${{ secrets.LASTFM_KEY }} SPOTIFY_ID: ${{ secrets.SPOTIFY_ID }} SPOTIFY_SECRET: ${{ secrets.SPOTIFY_SECRET }} - - name: Upload coverage to Codecov + - name: Upload test report to Codecov + if: success() || failure() uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} - files: codecov.json + files: target/nextest/ci/junit.xml disable_search: true - report_type: "coverage" + report_type: "test_results" fail_ci_if_error: true - - name: Upload test report to Codecov + - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} - files: target/nextest/ci/junit.xml + files: codecov.json disable_search: true - report_type: "test_results" + report_type: "coverage" fail_ci_if_error: true diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 6a5fbe440..131ff4be3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -152,7 +152,7 @@ jobs: run: | ${{ matrix.platform.command }} build --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }} if [[ ${{ matrix.platform.command }} == 'cross' ]]; then - cross test --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }} --workspace + cross-util run --target ${{ matrix.platform.target }} -- '/usr/bin/cargo-nextest nextest run --locked --target ${{ matrix.platform.target }} --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace' else cargo nextest run --locked --target ${{ matrix.platform.target }} --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace fi @@ -160,14 +160,8 @@ jobs: LASTFM_KEY: ${{ steps.build.outputs.docker-arch == 'amd64' && secrets.LASTFM_KEY || '' }} SPOTIFY_ID: ${{ steps.build.outputs.docker-arch == 'amd64' && secrets.SPOTIFY_ID || '' }} SPOTIFY_SECRET: ${{ steps.build.outputs.docker-arch == 'amd64' && secrets.SPOTIFY_SECRET || '' }} - - name: Upload build artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ steps.build.outputs.docker-arch }}-${{ steps.build.outputs.env }} - path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend - retention-days: 1 - name: Upload test report to Codecov - if: ${{ matrix.platform.command == 'cargo' }} + if: success() || failure() uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} @@ -175,6 +169,12 @@ jobs: disable_search: true report_type: "test_results" fail_ci_if_error: true + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.build.outputs.docker-arch }}-${{ steps.build.outputs.env }} + path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend + retention-days: 1 build-docker: runs-on: ubuntu-latest @@ -383,13 +383,8 @@ jobs: cargo build --locked --target ${{ steps.build.outputs.target }} --profile ${{ steps.build.outputs.profile }} cargo nextest run --locked --target ${{ steps.build.outputs.target }} --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace - - name: Upload build artifact - uses: actions/upload-artifact@v4 - with: - name: amd64-${{ steps.build.outputs.env }}-${{ matrix.version }} - path: ${{ github.workspace }}/target/${{ steps.build.outputs.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend - retention-days: 1 - name: Upload test report to Codecov + if: success() || failure() uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} @@ -397,6 +392,12 @@ jobs: disable_search: true report_type: "test_results" fail_ci_if_error: true + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: amd64-${{ steps.build.outputs.env }}-${{ matrix.version }} + path: ${{ github.workspace }}/target/${{ steps.build.outputs.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend + retention-days: 1 build-windows: runs-on: windows-latest @@ -466,13 +467,8 @@ jobs: LASTFM_KEY: ${{ secrets.LASTFM_KEY }} SPOTIFY_ID: ${{ secrets.SPOTIFY_ID }} SPOTIFY_SECRET: ${{ secrets.SPOTIFY_SECRET }} - - name: Upload build artifact - uses: actions/upload-artifact@v4 - with: - name: amd64-windows - path: ${{ github.workspace }}\target\x86_64-pc-windows-msvc\${{ steps.build.outputs.output-dir }}\nghe_backend.exe - retention-days: 1 - name: Upload test report to Codecov + if: success() || failure() uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} @@ -480,6 +476,12 @@ jobs: disable_search: true report_type: "test_results" fail_ci_if_error: true + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: amd64-windows + path: ${{ github.workspace }}\target\x86_64-pc-windows-msvc\${{ steps.build.outputs.output-dir }}\nghe_backend.exe + retention-days: 1 build-macos: strategy: @@ -563,13 +565,8 @@ jobs: LASTFM_KEY: ${{ steps.build.outputs.docker-arch == 'arm64' && secrets.LASTFM_KEY || '' }} SPOTIFY_ID: ${{ steps.build.outputs.docker-arch == 'arm64' && secrets.SPOTIFY_ID || '' }} SPOTIFY_SECRET: ${{ steps.build.outputs.docker-arch == 'arm64' && secrets.SPOTIFY_SECRET || '' }} - - name: Upload build artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ steps.build.outputs.docker-arch }}-${{ steps.build.outputs.env }} - path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend - retention-days: 1 - name: Upload test report to Codecov + if: success() || failure() uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} @@ -577,6 +574,12 @@ jobs: disable_search: true report_type: "test_results" fail_ci_if_error: true + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.build.outputs.docker-arch }}-${{ steps.build.outputs.env }} + path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/${{ steps.build.outputs.output-dir }}/nghe_backend + retention-days: 1 upload-release: runs-on: ubuntu-latest diff --git a/ci/cross-pre-build.sh b/ci/cross-pre-build.sh index 18166e42a..bd678215c 100755 --- a/ci/cross-pre-build.sh +++ b/ci/cross-pre-build.sh @@ -4,3 +4,5 @@ set -euxo pipefail if [[ "$CROSS_TARGET" == "aarch64-unknown-linux-gnu" ]]; then apt-get update && apt-get --assume-yes install libclang-10-dev fi + +curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C /usr/bin/ diff --git a/nghe-backend/src/time/mod.rs b/nghe-backend/src/time/mod.rs index 22d490cd9..eac44ff8d 100644 --- a/nghe-backend/src/time/mod.rs +++ b/nghe-backend/src/time/mod.rs @@ -3,6 +3,7 @@ use std::time::Duration; pub async fn now() -> time::OffsetDateTime { let now = time::OffsetDateTime::now_utc(); // Sleep one microsecond because that is the highest time precision postgresql can store. - tokio::time::sleep(Duration::from_micros(1)).await; + // In test, we will sleep a little bit more just to be sure. + tokio::time::sleep(Duration::from_micros(if cfg!(test) { 10 } else { 1 })).await; now }