-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
297 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
name: CI | ||
|
||
on: | ||
- push | ||
- pull_request | ||
- workflow_dispatch | ||
|
||
permissions: | ||
contents: read | ||
|
||
env: | ||
CARGO_INCREMENTAL: 0 | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
# test: | ||
# name: ${{ matrix.cmd.name }} (Rust ${{ matrix.rust }}) | ||
# runs-on: ubuntu-latest | ||
# strategy: | ||
# fail-fast: false | ||
# matrix: | ||
# rust: | ||
# - stable | ||
# cmd: | ||
# - name: Test | ||
# run: cargo test --locked | ||
# - name: Clippy | ||
# run: cargo clippy --locked --tests -- -D warnings | ||
# timeout-minutes: 45 | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# - name: Setup rust | ||
# run: | | ||
# rustup toolchain install ${{ matrix.rust }} --profile minimal --no-self-update | ||
# - name: ${{ matrix.cmd.name }} | ||
# run: ${{ matrix.cmd.run }} | ||
|
||
build: | ||
name: Build for ${{ matrix.target.name }} | ||
runs-on: ${{ matrix.target.runs-on }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
target: | ||
- name: Linux (x86_64) | ||
runs-on: ubuntu-latest | ||
target: x86_64-unknown-linux-gnu | ||
pre-build: | | ||
sudo apt-get install -y libudev-dev | ||
# - name: Windows (x86_64) | ||
# runs-on: windows-latest | ||
# target: x86_64-pc-windows-msvc | ||
# ext: .exe | ||
# - name: MacOS (x86_64) | ||
# runs-on: macos-latest | ||
# target: x86_64-apple-darwin | ||
# - name: MacOS (arm64) | ||
# runs-on: macos-latest | ||
# target: aarch64-apple-darwin | ||
timeout-minutes: 45 | ||
# env: | ||
# RUSTFLAGS: -C target-feature=+crt-static | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup rust | ||
run: | | ||
rustup toolchain install stable --target ${{ matrix.target.target }} --profile minimal --no-self-update | ||
- name: Install build dependencies | ||
run: ${{ matrix.target.pre-build }} | ||
if: ${{ matrix.target.pre-build }} | ||
- name: Build for ${{ matrix.target.name }} | ||
run: cargo build --locked --release --target ${{ matrix.target.target }} | ||
- name: Run for ${{ matrix.target.name }} | ||
run: cargo run --locked --release --target ${{ matrix.target.target }} | ||
- name: Check file | ||
run: | | ||
file target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} | ||
stat target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} | ||
mv target/${{ matrix.target.target }}/release/rust-github-actions-test${{ matrix.target.ext }} rust-github-actions-test.${{ matrix.target.target }}${{ matrix.target.ext }} | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: rust-github-actions-test.${{ matrix.target.target }}${{ matrix.target.ext }} | ||
path: rust-github-actions-test.${{ matrix.target.target }}${{ matrix.target.ext }} | ||
if-no-files-found: error | ||
|
||
release: | ||
name: Update release | ||
permissions: | ||
contents: write | ||
needs: build | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 45 | ||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
pattern: rust-github-actions-test.* | ||
merge-multiple: true | ||
- run: find -exec ls -ld {} + | ||
- uses: actions/github-script@v7 | ||
id: upload-release-asset | ||
with: | ||
script: | | ||
const { env } = process; | ||
const { data: release } = await github.rest.repos.getReleaseByTag({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
tag: 'latest', | ||
}); | ||
console.log('release:', release.id, release); | ||
const { data: assets } = await github.rest.repos.listReleaseAssets({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
release_id: release.id, | ||
}); | ||
console.log('assets:', assets); | ||
for (const asset of assets) { | ||
await github.rest.repos.deleteReleaseAsset({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
asset_id: asset.id, | ||
}); | ||
} | ||
let body = ''; | ||
body += `## Build of ${env.GITHUB_SHA.slice(0, 8)}\n`; | ||
console.log({ body }, env.GITHUB_SHA); | ||
await github.rest.repos.updateRelease({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
release_id: release.id, | ||
body, | ||
}); | ||
const fs = require('fs'); | ||
const artifacts = fs.readdirSync('.'); | ||
console.log('artifacts:', artifacts); | ||
for (const name of artifacts) { | ||
const data = fs.readFileSync(name); | ||
await github.rest.repos.uploadReleaseAsset({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
release_id: release.id, | ||
name, | ||
data, | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ version = "0.1.0" | |
edition = "2021" | ||
|
||
[dependencies] | ||
hidapi = "2.6.1" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,40 @@ | ||
#![warn(clippy::all, clippy::pedantic)] | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
println!( | ||
"Hello, world!: {:?} {:?}", | ||
std::path::MAIN_SEPARATOR, | ||
std::env::current_dir().unwrap(), | ||
); | ||
|
||
foo(); | ||
|
||
match hidapi::HidApi::new() { | ||
Ok(hidapi) => { | ||
println!("devices:"); | ||
for device in hidapi.device_list() { | ||
println!( | ||
"- vendor={:?} {:?} product={:?} {:?} serial={:?} path={:?}", | ||
device.vendor_id(), | ||
device.manufacturer_string(), | ||
device.product_id(), | ||
device.product_string(), | ||
device.serial_number(), | ||
device.path(), | ||
); | ||
} | ||
println!("--- done"); | ||
} | ||
Err(err) => eprintln!("Error: {err:?}"), | ||
} | ||
} | ||
|
||
#[cfg(target_feature = "crt-static")] | ||
fn foo() { | ||
println!("the C runtime should be statically linked"); | ||
} | ||
|
||
#[cfg(not(target_feature = "crt-static"))] | ||
fn foo() { | ||
println!("the C runtime should be dynamically linked"); | ||
} |