Add GitHub Actions CI workflow #1
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: CI | |
| on: | |
| push: | |
| branches: [main, develop, 'feature/**', 'stdlib-and-secret-binaries'] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build-and-test: | |
| name: Build & Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Rust nightly | |
| uses: dtolnay/rust-action@nightly | |
| with: | |
| components: rustfmt, clippy | |
| - name: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-nightly-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-nightly- | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| - name: Run clippy | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| continue-on-error: true # Don't fail on clippy warnings initially | |
| - name: Build release | |
| run: cargo build --release --package stoffel-vm --bin stoffel-run | |
| - name: Run tests | |
| run: cargo test --all-features | |
| - name: Upload VM binary | |
| if: matrix.os == 'ubuntu-latest' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: stoffel-run-${{ matrix.os }} | |
| path: target/release/stoffel-run | |
| retention-days: 7 | |
| docker-build: | |
| name: Docker Build | |
| runs-on: ubuntu-latest | |
| needs: [build-and-test] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: false | |
| tags: stoffelvm:test | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Login to GitHub Container Registry | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Push to GHCR | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ghcr.io/stoffel-labs/stoffelvm:latest | |
| ghcr.io/stoffel-labs/stoffelvm:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # Trigger integration tests when pushing to main | |
| trigger-integration-tests: | |
| name: Trigger Integration Tests | |
| needs: [build-and-test] | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Trigger integration tests | |
| uses: peter-evans/repository-dispatch@v3 | |
| with: | |
| token: ${{ secrets.INTEGRATION_TESTS_PAT }} | |
| repository: Stoffel-Labs/integration-tests | |
| event-type: stoffel-vm-updated | |
| client-payload: '{"ref": "${{ github.sha }}", "branch": "${{ github.ref_name }}"}' |