This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Test | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| # Cancel already running jobs | |
| concurrency: | |
| group: build_and_test_${{ github.head_ref }} | |
| cancel-in-progress: true | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| build_check_and_upload: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: Build Release | |
| runner: ubuntu-24.04 | |
| cargo_flags: --release | |
| profile: release | |
| - name: Build Debug | |
| runner: ubuntu-24.04 | |
| cargo_flags: | |
| profile: debug | |
| name: ${{ matrix.name }} | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: Swatinem/rust-cache@v2 | |
| with: | |
| # rust-cache already handles all the sane defaults for caching rust builds. | |
| # However because we are running seperate debug/release builds in parallel, | |
| # we also need to add the runner and cargo_flags to the key so that a seperate cache is used. | |
| # Otherwise only the last build to finish would get saved to the cache. | |
| # We allow different test_flags to share a cache as they should have identical build outputs | |
| key: ${{ matrix.runner }} - ${{ matrix.cargo_flags }} | |
| # this line means that only the main branch writes to the cache | |
| # benefits: | |
| # * prevents main branch caches from being evicted in favor of a PR cache | |
| # * saves about 1min per workflow by skipping the actual cache write | |
| # downsides: | |
| # * PRs that update rust version or changes deps will be slow to iterate on due to changes not being cached. | |
| save-if: ${{ github.ref == 'refs/heads/main' }} | |
| # Additionally, the main builds should always run without cache to avoid accumulating unused build files across builds. | |
| # Usually, this isnt a problem because rust-cache only caches dependencies, not our project. | |
| # However, in this case we have enabled cache-all-crates, which forces rust-cache to cache our projects build files as well as the dependencies. | |
| lookup-only: ${{ github.ref == 'refs/heads/main' }} | |
| # Our workspace contains crates like test-helpers that are only changed sometimes, | |
| # so enabling this gives a nice speedup at the cost of extra cache storage. | |
| cache-all-crates: "true" | |
| cache-workspace-crates: "true" | |
| # If we cache the j4rs build as done above in the rust-cache action, we also need to cache the jassets directory created by j4rs. | |
| # Even though the rust-cache action caches the target directory, it ignores non-standard folders inside it, so we need to manually cache jassets seperately. | |
| # | |
| # Note that: evicting this cache without evicting the rust-cache will lead to CI failures, however as long as our caches are well within the 10GB limit we should be fine. | |
| - name: Cache jassets | |
| uses: actions/cache/restore@v5 | |
| with: | |
| path: target/${{ matrix.profile }}/jassets | |
| # cache can be global as java assets work regardless of OS+arch | |
| key: jassets-${{ hashFiles('Cargo.lock') }} | |
| restore-keys: jassets- | |
| - name: cache custom ubuntu packages | |
| uses: actions/cache@v5 | |
| with: | |
| path: shotover-proxy/build/packages | |
| key: ubuntu-24.04-packages | |
| - run: tree target | |
| - name: Install ubuntu packages | |
| run: shotover-proxy/build/install_ubuntu_packages.sh | |
| - name: Install nextest | |
| uses: taiki-e/install-action@v2 | |
| with: | |
| tool: nextest@0.9.129 | |
| - name: Build tests | |
| run: cargo nextest archive --archive-file nextest-${{ matrix.profile }}.tar.zst ${{ matrix.cargo_flags }} --all-features --all-targets | |
| - name: Upload built tests to workflow | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nextest-${{ matrix.profile }} | |
| path: nextest-${{ matrix.profile }}.tar.zst | |
| - name: Report disk usage | |
| run: | | |
| df -h | |
| echo -e "\ntarget dir usage:" | |
| du -h $PWD/target | |
| echo -e "\n.cargo dir usage:" | |
| du -h ~/.cargo | |
| - name: Cleanup archive | |
| run: rm nextest-${{ matrix.profile }}.tar.zst | |
| - name: Ensure that tests did not create or modify any files that arent .gitignore'd | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git status | |
| exit 1 | |
| fi | |
| - name: Save jassets cache | |
| if: ${{ github.ref == 'refs/heads/main' }} | |
| uses: actions/cache/save@v5 | |
| with: | |
| path: target/${{ matrix.profile }}/jassets | |
| key: jassets-${{ hashFiles('foo/Cargo.lock') }} | |
| run_tests_partitioned: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| partition: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ] | |
| profile: [ "release", "debug" ] | |
| name: Test ${{ matrix.profile}} ${{ matrix.partition }}/15 | |
| runs-on: ubuntu-24.04 | |
| needs: build_check_and_upload | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: cache custom ubuntu packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: shotover-proxy/build/packages | |
| key: ubuntu-24.04-packages | |
| - name: Install ubuntu packages | |
| run: shotover-proxy/build/install_ubuntu_packages.sh | |
| - name: Install nextest | |
| uses: taiki-e/install-action@v2 | |
| with: | |
| tool: nextest@0.9.70 | |
| - run: mkdir -p ~/.cargo/bin | |
| - name: Download archive | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nextest-${{ matrix.profile }} | |
| - name: Run tests | |
| run: | | |
| ~/.cargo/bin/cargo-nextest nextest run --archive-file nextest-${{ matrix.profile }}.tar.zst \ | |
| --partition count:${{ matrix.partition }}/15 --extract-to . --run-ignored all --success-output=immediate | |
| - name: Cleanup archive | |
| run: rm nextest-${{ matrix.profile }}.tar.zst | |
| - name: Ensure that tests did not create or modify any files that arent .gitignore'd | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git status | |
| exit 1 | |
| fi | |