Skip to content

Commit 8560253

Browse files
committed
Add CI
Includes cross compliation and a release process
1 parent 2c4741c commit 8560253

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

.github/workflows/build.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build Rust Binary
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
build:
8+
name: Build on ${{ matrix.os }} for ${{ matrix.target }}
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
include:
13+
- os: ubuntu-latest
14+
target: x86_64-unknown-linux-gnu
15+
- os: ubuntu-latest
16+
target: x86_64-pc-windows-msvc
17+
- os: macos-latest
18+
target: x86_64-apple-darwin
19+
- os: macos-latest
20+
target: aarch64-apple-darwin
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Install Rust
26+
uses: actions-rs/toolchain@v1
27+
with:
28+
toolchain: stable
29+
target: ${{ matrix.target }}
30+
override: true
31+
32+
- name: Cache Rust dependencies
33+
uses: Swatinem/rust-cache@v2
34+
35+
- name: Install cross (for Windows build)
36+
if: matrix.target == 'x86_64-pc-windows-msvc'
37+
run: cargo install cross
38+
39+
- name: Set build flags
40+
id: build_flags
41+
run: |
42+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
43+
echo "::set-output name=flags::--release"
44+
echo "::set-output name=build_type::release"
45+
else
46+
echo "::set-output name=flags::"
47+
echo "::set-output name=build_type::debug"
48+
fi
49+
50+
- name: Build (non-Windows, non-aarch64-apple)
51+
if: matrix.target != 'x86_64-pc-windows-msvc' && matrix.target != 'aarch64-apple-darwin'
52+
run: cargo build ${{ steps.build_flags.outputs.flags }} --target ${{ matrix.target }}
53+
54+
- name: Build (aarch64-apple-darwin)
55+
if: matrix.target == 'aarch64-apple-darwin'
56+
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 }}
57+
58+
- name: Build (Windows)
59+
if: matrix.target == 'x86_64-pc-windows-msvc'
60+
run: cross build ${{ steps.build_flags.outputs.flags }} --target ${{ matrix.target }}
61+
62+
- name: Upload artifact
63+
uses: actions/upload-artifact@v2
64+
with:
65+
name: ${{ steps.build_flags.outputs.build_type }}-binary-${{ matrix.target }}
66+
path: |
67+
target/${{ matrix.target }}/${{ steps.build_flags.outputs.build_type }}/webview_deno_rust*
68+
!target/${{ matrix.target }}/${{ steps.build_flags.outputs.build_type }}/deps
69+
!target/${{ matrix.target }}/${{ steps.build_flags.outputs.build_type }}/build
70+
!target/${{ matrix.target }}/${{ steps.build_flags.outputs.build_type }}/.fingerprint
71+
retention-days: 7

.github/workflows/release.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Release Rust Binary
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build Rust Binary"]
6+
types:
7+
- completed
8+
branches: [main]
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Download all artifacts
19+
uses: actions/download-artifact@v2
20+
with:
21+
github-token: ${{secrets.GITHUB_TOKEN}}
22+
run-id: ${{github.event.workflow_run.id}}
23+
24+
- name: Get version from Cargo.toml
25+
id: get_version
26+
run: |
27+
VERSION=$(grep '^version =' Cargo.toml | sed 's/.*= *"//' | sed 's/".*//')
28+
echo "::set-output name=version::$VERSION"
29+
30+
- name: Create Release
31+
uses: ncipollo/release-action@v1
32+
with:
33+
tag: v${{ steps.get_version.outputs.version }}
34+
name: Release ${{ steps.get_version.outputs.version }}
35+
draft: false
36+
prerelease: false
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
artifacts: "binary-*/webview_deno_rust*"
39+
allowUpdates: true
40+
artifactErrorsFailBuild: true
41+
42+
- name: Release Status
43+
run: echo "Release v${{ steps.get_version.outputs.version }} created or updated."

0 commit comments

Comments
 (0)