Skip to content

Commit

Permalink
ci: fix warning and use nextest (#569)
Browse files Browse the repository at this point in the history
* disable docker build summary

* upgrade freebsd version

* use nextest for freebsd, coverage, macos and windows

* update test report to codecov

* update postgres to 17

* fix upload test report to codecov

* add wait for read lock in stream

* image version does not receive env
  • Loading branch information
vnghia authored Dec 11, 2024
1 parent 1d4f5bf commit 593d70b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[profile.ci]
fail-fast = false
retries = { backoff = "fixed", count = 3, delay = "1s", jitter = true }
junit = { path = "junit.xml" }
14 changes: 13 additions & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --exclude nghe-frontend --codecov --output-path codecov.json
run: cargo llvm-cov nextest --profile ci --workspace --codecov --output-path codecov.json
env:
LASTFM_KEY: ${{ secrets.LASTFM_KEY }}
SPOTIFY_ID: ${{ secrets.SPOTIFY_ID }}
Expand All @@ -95,4 +97,14 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: codecov.json
disable_search: true
report_type: "coverage"
fail_ci_if_error: true
- name: Upload test report to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: target/nextest/ci/junit.xml
disable_search: true
report_type: "test_results"
fail_ci_if_error: true
33 changes: 21 additions & 12 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ env:
AWS_USE_PATH_STYLE_ENDPOINT: true
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
POSTGRES_VERSION: 17

jobs:
build-linux:
Expand Down Expand Up @@ -163,6 +164,9 @@ jobs:
needs: [build-linux]
if: ${{ vars.BUILD_DOCKER != '' }}

env:
DOCKER_BUILD_RECORD_UPLOAD: false

steps:
- uses: actions/checkout@v4
- name: Download build artifact for docker
Expand Down Expand Up @@ -231,8 +235,8 @@ jobs:
fail-fast: false
matrix:
version:
- "14.0"
- "13.2"
- "14.2"
- "13.4"

runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -347,7 +351,7 @@ jobs:
environment_variables: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG COLORBT_SHOW_HIDDEN DATABASE_URL AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION AWS_ENDPOINT_URL AWS_USE_PATH_STYLE_ENDPOINT"
shell: "bash"
cpu_count: 4
image_url: https://github.com/vnghia/nghe-freebsd-builder/releases/download/v0.0.12/freebsd-${{ matrix.version }}-x86-64.qcow2
image_url: https://github.com/vnghia/nghe-freebsd-builder/releases/download/v0.0.13/freebsd-${{ matrix.version }}-x86-64.qcow2
run: |
sudo chown -R $(id -u):$(id -g) /root/
export PATH="/root/.cargo/bin/:$PATH"
Expand All @@ -358,8 +362,10 @@ jobs:
cargo install cargo-vcpkg
cargo vcpkg --verbose build --manifest-path nghe-backend/Cargo.toml --target ${{ steps.build.outputs.target }}
curl -LsSf https://get.nexte.st/latest/freebsd | tar zxf - -C /root/.cargo/bin/
cargo build --locked --target ${{ steps.build.outputs.target }} --profile ${{ steps.build.outputs.profile }}
cargo test --locked --target ${{ steps.build.outputs.target }} --profile ${{ steps.build.outputs.profile }} --workspace --exclude nghe-frontend
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:
Expand Down Expand Up @@ -398,7 +404,7 @@ jobs:

- name: Install and setup postgres
run: |
curl https://get.enterprisedb.com/postgresql/postgresql-16.2-1-windows-x64-binaries.zip --output postgresql.zip
curl https://get.enterprisedb.com/postgresql/postgresql-${{ env.POSTGRES_VERSION }}.2-2-windows-x64-binaries.zip --output postgresql.zip
7z x postgresql.zip
$env:PGDATA = "$PWD\pgsql\data"
$env:PGPASSWORD = "postgres"
Expand All @@ -423,11 +429,14 @@ jobs:
run: |
cargo vcpkg --verbose build --manifest-path nghe-backend\Cargo.toml --target x86_64-pc-windows-msvc
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest

- name: Build and test
run: |
.\minio.exe server data &
cargo build --locked --target x86_64-pc-windows-msvc --profile ${{ steps.build.outputs.profile }}
cargo test --locked --target x86_64-pc-windows-msvc --profile ${{ steps.build.outputs.profile }} --workspace --exclude nghe-frontend
cargo nextest run --locked --target x86_64-pc-windows-msvc --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace
env:
LASTFM_KEY: ${{ secrets.LASTFM_KEY }}
SPOTIFY_ID: ${{ secrets.SPOTIFY_ID }}
Expand Down Expand Up @@ -455,7 +464,6 @@ jobs:

env:
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -488,10 +496,8 @@ jobs:

- name: Install and setup postgres
run: |
brew uninstall --force postgresql
brew uninstall --force postgresql@14
brew install postgresql@16
brew link postgresql@16
brew install postgresql@${{ env.POSTGRES_VERSION }}
brew link postgresql@${{ env.POSTGRES_VERSION }}
export PGDATA="$RUNNER_TEMP/pgdata"
initdb --username=postgres --encoding="UTF-8" --locale="en_US.UTF-8" --pwfile=<(echo postgres)
pg_ctl start
Expand All @@ -513,10 +519,13 @@ jobs:
run: |
cargo vcpkg --verbose build --manifest-path nghe-backend/Cargo.toml --target ${{ matrix.platform.target }}
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest

- name: Build and test
run: |
cargo build --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }}
cargo test --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }} --workspace --exclude nghe-frontend
cargo nextest run --locked --target ${{ matrix.platform.target }} --profile ci --cargo-profile ${{ steps.build.outputs.profile }} --workspace
env:
LASTFM_KEY: ${{ steps.build.outputs.docker-arch == 'arm64' && secrets.LASTFM_KEY || '' }}
SPOTIFY_ID: ${{ steps.build.outputs.docker-arch == 'arm64' && secrets.SPOTIFY_ID || '' }}
Expand Down
14 changes: 13 additions & 1 deletion nghe-backend/src/route/media_retrieval/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ mod tests {
let mut music_folder = mock.music_folder(0).await;
music_folder.add_audio_filesystem::<&str>().format(audio::Format::Flac).call().await;

let config = &mock.config.transcode;
let user_id = mock.user_id(0).await;
let song_id = music_folder.song_id_filesystem(0).await;
let format = format::Transcode::Opus;
Expand All @@ -174,7 +175,6 @@ mod tests {
let transcoded = {
let path = music_folder.absolute_path(0);
let input = music_folder.to_impl().transcode_input(path.to_path()).await.unwrap();
let config = &mock.config.transcode;
transcode::Transcoder::spawn_collect(&input, config, format, bitrate, 0).await
};

Expand All @@ -192,6 +192,18 @@ mod tests {
}
assert_eq!(transcode_status, &[TranscodeStatus::NoCache, TranscodeStatus::WithCache]);

// We will have to wait a bit to make sure that the write lock is released.
let cache_path = music_folder.filesystem[0]
.information
.file
.replace(format)
.path(config.cache_dir.as_ref().unwrap(), bitrate.to_string().as_str());
tokio::task::spawn_blocking(move || {
transcode::Lock::lock_read_blocking(&cache_path).unwrap();
})
.await
.unwrap();

let (responses, transcode_status) = spawn_stream(&mock, 2, user_id, request).await;
for (status, body) in responses {
assert_eq!(status, StatusCode::OK);
Expand Down

0 comments on commit 593d70b

Please sign in to comment.