name: CI on: push: branches: [main] pull_request: branches: [main] release: branches: [main] workflow_dispatch: jobs: build: strategy: fail-fast: true matrix: include: - os: ubuntu-latest target: x86_64-unknown-linux-gnu - os: windows-latest target: x86_64-pc-windows-msvc - os: macOS-latest target: x86_64-apple-darwin runs-on: ${{ matrix.os }} steps: # - name: Install stable toolchain # uses: dtolnay/rust-toolchain@master # with: # toolchain: ${{ matrix.rust }} # override: true # target: ${{ matrix.target }} - name: Checkout uses: actions/checkout@v3 - name: Lint if: runner.os == 'Linux' shell: bash run: | cargo fmt --all -- --check cargo clippy --all-targets --all-features -- -D warnings - name: Install OpenSSL (Windows) if: runner.os == 'Windows' run: | echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append vcpkg install openssl:x64-windows-static-md - name: Run build shell: bash run: | cargo build --release --target ${{ matrix.target }} mkdir target_releases if [[ "${{ runner.os }}" == "Windows" ]]; then mv target/${{ matrix.target }}/release/martin.exe target_releases else mv target/${{ matrix.target }}/release/martin target_releases fi - name: Save build artifacts uses: actions/upload-artifact@v3 with: name: build-${{ runner.os }} path: target_releases/* test: name: Test builds on ${{ matrix.os }} needs: [build] runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: include: - os: ubuntu-latest bin: martin name: martin-Linux-x86_64.tar.gz - os: windows-latest bin: martin.exe name: martin-Windows-x86_64.zip - os: macOS-latest bin: martin name: martin-Darwin-x86_64.tar.gz steps: - name: Checkout sources uses: actions/checkout@v3 - name: Start postgres uses: nyurik/action-setup-postgis@v1 id: pg with: username: test password: test database: test rights: --superuser - name: Init database shell: bash run: tests/fixtures/initdb.sh env: DATABASE_URL: ${{ steps.pg.outputs.connection-uri }} - name: Unit Tests (Linux) if: runner.os == 'Linux' shell: bash run: | cargo test --all rm -rf target env: DATABASE_URL: ${{ steps.pg.outputs.connection-uri }} - uses: actions/download-artifact@v3 with: name: build-${{ runner.os }} path: target/ - name: Compare test output results (TODO) if: false && runner.os == 'Linux' run: | # TODO: this test is currently broken # the output of the tests is not deterministic diff --brief --recursive --new-file tests/output tests/expected - name: Save test output on failure (Linux) if: failure() && runner.os == 'Linux' uses: actions/upload-artifact@v3 with: name: test-output path: tests/output/* retention-days: 5 - name: Test shell: bash run: | if [[ "${{ runner.os }}" != "Windows" ]]; then chmod +x target/${{ matrix.bin }} fi tests/test.sh env: DATABASE_URL: ${{ steps.pg.outputs.connection-uri }} MARTIN_BUILD: "-" MARTIN_BIN: target/${{ matrix.bin }} - name: Package shell: bash run: | cd target/ strip ${{ matrix.bin }} if [[ "${{ runner.os }}" == "Windows" ]]; then 7z a ../${{ matrix.name }} ${{ matrix.bin }} else tar czvf ../${{ matrix.name }} ${{ matrix.bin }} fi cd - - name: Generate SHA-256 (MacOS) if: runner.os == 'macOS' run: shasum -a 256 ${{ matrix.name }} - name: Publish if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v1 with: draft: true files: 'martin*' body_path: CHANGELOG.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}