Skip to content

Commit

Permalink
Add CI (#12)
Browse files Browse the repository at this point in the history
* Add CI

Includes cross compliation and a release process

* Only cancel other builds on main

Ran into an issue where one OS build was missing a dep and caused all the other ones to be canceled. I want to be able to see which succeed/fail individually in development, but consolidate them all in main.

* Add required check step

Fixes #15

* Add Linux dependencies

* Use cargo-xwin for windows build

* Add aggressive build caching

* Update release to account for cache

* Bump action dependencies

* Tweak caching behavior; rename rust build action

* Exit early if cache hit; now with meaning

I hate that GitHub won't let you just end a test with success without this unfortunate hack.

* Try canceling check if cached

* Redo caching strategy... again

* Add a comment to test build output
  • Loading branch information
zephraph authored Sep 20, 2024
1 parent 6950ac3 commit 9b590d9
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release Rust Binary

on:
workflow_run:
workflows: ["Rust Binary"]
types:
- completed
branches: [main]

jobs:
release:
name: Release
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
run-id: ${{github.event.workflow_run.id}}

- name: Check for artifacts
id: check_artifacts
run: |
if [ -z "$(find . -name 'webview_deno_rust*')" ]; then
echo "No artifacts found. Exiting successfully."
echo "artifacts_found=false" >> $GITHUB_OUTPUT
else
echo "Artifacts found. Proceeding with release."
echo "artifacts_found=true" >> $GITHUB_OUTPUT
fi
- name: Get version from Cargo.toml
if: steps.check_artifacts.outputs.artifacts_found == 'true'
id: get_version
run: |
VERSION=$(grep '^version =' Cargo.toml | sed 's/.*= *"//' | sed 's/".*//')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create Release
if: steps.check_artifacts.outputs.artifacts_found == 'true'
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.get_version.outputs.version }}
name: Release ${{ steps.get_version.outputs.version }}
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "binary-*/webview_deno_rust*"
allowUpdates: true
artifactErrorsFailBuild: true

- name: Release Status
if: steps.check_artifacts.outputs.artifacts_found == 'true'
run: echo "Release v${{ steps.get_version.outputs.version }} created or updated."

- name: No Release Status
if: steps.check_artifacts.outputs.artifacts_found == 'false'
run: echo "No new release created as no new artifacts were found."
117 changes: 117 additions & 0 deletions .github/workflows/rust-binary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Rust Binary

on:
push:

jobs:
check:
name: Check
runs-on: macos-latest
permissions:
actions: write
outputs:
cached: ${{ steps.cache-rust.outputs.cache-hit }}
steps:
- uses: actions/checkout@v4

- name: Cache Rust
uses: actions/cache@v4
id: cache-rust
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-rust-check-${{ hashFiles('Cargo.lock', 'Cargo.toml', 'rust-toolchain.toml', '**/*.rs') }}

- name: Install Rust
if: steps.cache-rust.outputs.cache-hit != 'true'
uses: oxidecomputer/actions-rs_toolchain@oxide/master

- name: Run cargo check
if: steps.cache-rust.outputs.cache-hit != 'true'
run: cargo check

build:
needs: check
if: needs.check.outputs.cached != 'true'
name: Build on ${{ matrix.os }} for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: ${{ github.ref == 'refs/heads/main' }}
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: x86_64-pc-windows-msvc
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: oxidecomputer/actions-rs_toolchain@oxide/master
with:
target: ${{ matrix.target }}

- name: Install libwebkit2gtk (Linux)
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev
- name: Get cargo-xwin version
if: matrix.target == 'x86_64-pc-windows-msvc'
id: cargo-xwin-version
run: |
VERSION=$(cargo search cargo-xwin --limit 1 | awk -F '"' '{print $2}')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Cache cargo-xwin
uses: actions/cache@v4
if: matrix.target == 'x86_64-pc-windows-msvc'
id: cache-cargo-xwin
with:
path: ~/.cargo/bin/cargo-xwin
key: ${{ runner.os }}-cargo-xwin-${{ steps.cargo-xwin-version.outputs.version }}-${{ hashFiles('rust-toolchain.toml') }}

- name: Install cargo-xwin (for Windows build)
if: matrix.target == 'x86_64-pc-windows-msvc' && steps.cache-cargo-xwin.outputs.cache-hit != 'true'
run: cargo install cargo-xwin

- name: Set build flags
id: build_flags
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "flags=--release" >> $GITHUB_OUTPUT
echo "build_type=release" >> $GITHUB_OUTPUT
else
echo "flags=" >> $GITHUB_OUTPUT
echo "build_type=debug" >> $GITHUB_OUTPUT
fi
- name: Build (non-Windows, non-aarch64-apple)
if: matrix.target != 'x86_64-pc-windows-msvc' && matrix.target != 'aarch64-apple-darwin'
run: cargo build ${{ steps.build_flags.outputs.flags }} --target ${{ matrix.target }}

- name: Build (aarch64-apple-darwin)
if: matrix.target == 'aarch64-apple-darwin'
run: SDKROOT=$(xcrun -sdk macosx --show-sdk-path) MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version) cargo build ${{ steps.build_flags.outputs.flags }} --target ${{ matrix.target }}

- name: Build (Windows)
if: matrix.target == 'x86_64-pc-windows-msvc'
run: cargo xwin build ${{ steps.build_flags.outputs.flags }} --target ${{ matrix.target }}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.build_flags.outputs.build_type }}-binary-${{ matrix.target }}
path: |
target/${{ matrix.target }}/${{ steps.build_flags.outputs.build_type }}/webview_deno_rust*
!target/${{ matrix.target }}/${{ steps.build_flags.outputs.build_type }}/deps
!target/${{ matrix.target }}/${{ steps.build_flags.outputs.build_type }}/build
!target/${{ matrix.target }}/${{ steps.build_flags.outputs.build_type }}/.fingerprint
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tao::window::Fullscreen;

#[derive(JsonSchema, Deserialize, Debug)]
struct WebViewOptions {
/// Sets the title of the window.
title: String,
#[serde(flatten)]
target: WebViewTarget,
Expand Down

0 comments on commit 9b590d9

Please sign in to comment.