Skip to content

Commit

Permalink
chore: add publish pipeline (#69)
Browse files Browse the repository at this point in the history
* chore: add publish pipeline

* use npm install instead

* add core and lib installation

* change tauri version to v1

* remove not webkit 4.1

* install msgpack

* use compile profile

* fix compile command

* parametrize compile board

* fix path issue

* build only when push on release branch
  • Loading branch information
lucarin91 committed May 31, 2024
1 parent a0e46e0 commit 848f39b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 6 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "publish"
on:
push:
branches:
- release

# This is the example from the readme.
# On each push to the `release` branch it will create or update a GitHub release, build your app, and upload the artifacts to the release.

jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- platform: "macos-latest" # for Arm based macs (M1 and above).
args: "--target aarch64-apple-darwin"
- platform: "macos-latest" # for Intel based macs.
args: "--target x86_64-apple-darwin"
- platform: "ubuntu-20.04" # for Tauri v2 you could replace this with ubuntu-22.04.
args: ""
- platform: "windows-latest"
args: ""

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4

- name: setup node
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
# Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds.
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}

- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04' # This must match the platform value defined above.
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
# webkitgtk 4.0 is for Tauri v1 - webkitgtk 4.1 is for Tauri v2.
# You can remove the one that doesn't apply to your app to speed up the workflow a bit.

- name: install frontend dependencies
run: npm install
working-directory: ./installer

- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: app-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
releaseName: "App v__VERSION__"
releaseBody: "See the assets to download this version and install."
releaseDraft: true
prerelease: false
args: ${{ matrix.args }}
projectPath: ./installer
24 changes: 18 additions & 6 deletions installer/src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ fn main() {

let sketches = base_dir.join("../../sketches/BLE_Scratch/BLE_Scratch.ino");

compile_sketch(&arduino_cli, &sketches, &resource_dir.join("sketch.bin"))
.expect("Failed to compile sketch");
compile_sketch(
&arduino_cli,
&sketches,
&resource_dir.join("sketch.bin"),
"arduino:mbed_nano:nano33ble",
)
.expect("Failed to compile sketch");

println!("cargo:rerun-if-changed={}", sketches.to_str().unwrap());

Expand Down Expand Up @@ -100,6 +105,7 @@ fn compile_sketch(
arduino_cli: &path::Path,
sketch: &path::Path,
to: &path::Path,
fqbn: &str,
) -> anyhow::Result<()> {
if to.exists() && fs::metadata(to)?.modified()? >= fs::metadata(sketch)?.modified()? {
println!("Binary up to date");
Expand All @@ -109,16 +115,17 @@ fn compile_sketch(

println!("Compiling sketch '{}'", sketch.to_str().unwrap_or_default());

let profile = fqbn.rsplit(':').next().unwrap();

let output = Command::new(arduino_cli)
.args(&[
"compile",
"-b",
"arduino:mbed_nano:nano33ble",
"-e",
"--profile",
profile,
sketch.to_str().unwrap(),
])
.output()?;

println!(
"compilation output:\n{}\n{}",
String::from_utf8_lossy(&output.stderr),
Expand All @@ -129,11 +136,16 @@ fn compile_sketch(
return Err(anyhow::anyhow!("Compilation failed"));
}

let path_fqbn: String = fqbn
.chars()
.map(|c| if c == ':' { '.' } else { c })
.collect();

let dir = sketch.parent().unwrap();
let file = sketch.file_name().unwrap();
let bin = dir
.join("build")
.join("arduino.mbed_nano.nano33ble")
.join(path_fqbn)
.join(file)
.with_extension("ino.bin");

Expand Down
16 changes: 16 additions & 0 deletions sketches/BLE_Scratch/sketch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
profiles:
nano33ble:
fqbn: arduino:mbed_nano:nano33ble
platforms:
- platform: arduino:mbed_nano (4.1.3)
libraries:
- Arduino_APDS9960 (1.0.4)
- Arduino_BMI270_BMM150 (1.2.0)
- Arduino_HS300x (1.0.0)
- Arduino_LPS22HB (1.0.2)
- ArduinoBLE (1.3.6)
- MsgPack (0.4.2)
- DebugLog (0.8.3)
- ArxTypeTraits (0.3.1)
- ArxContainer (0.6.0)
- Servo (1.2.1)

0 comments on commit 848f39b

Please sign in to comment.