-
Notifications
You must be signed in to change notification settings - Fork 32
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
10 changed files
with
157 additions
and
6 deletions.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Rust | ||
name: Run cargo clippy, cargo fmt, build and Unit+Integration tests | ||
|
||
on: | ||
push: | ||
|
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,105 @@ | ||
name: Publish to Crates.io | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*-v*.*.*' # Match tags like 'package1-v1.2.3' | ||
workflow_dispatch: # Allow manual workflow dispatch | ||
|
||
jobs: | ||
test-dry-run: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'workflow_dispatch' # Only run this job for manual triggers | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set Up Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
|
||
- name: Retrieve Package Names from workspace root | ||
id: get-root-packages | ||
run: | | ||
# Retrieve package names from the workspace root | ||
PACKAGE_NAMES=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[].name' | tr '\n' ' ') | ||
# Set the package names as an output | ||
echo "Package names from root Cargo.toml: $PACKAGE_NAMES" | ||
echo "::set-output name=package-names::$PACKAGE_NAMES" | ||
shell: bash | ||
working-directory: ${{ github.workspace }} | ||
|
||
- name: Test Dry-Run Publish for Each Package | ||
run: | | ||
# Iterate through package names retrieved | ||
PACKAGE_NAMES="${{ steps.get-root-packages.outputs.package-names }}" | ||
for PACKAGE_NAME in $PACKAGE_NAMES; do | ||
# Test a dry-run publish for each package within the workspace | ||
cargo publish --dry-run --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --package "$PACKAGE_NAME" | ||
done | ||
env: | ||
CARGO_TERM_COLOR: always | ||
working-directory: ${{ github.workspace }} | ||
|
||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' # Only run this job for tag pushes | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set Up Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
|
||
- name: Determine Package to Publish | ||
id: determine-package | ||
run: | | ||
# Extract package name from the tag name | ||
TAG_NAME="${{ github.ref }}" | ||
PACKAGE_NAME=$(echo "$TAG_NAME" | cut -d'-' -f1) | ||
PACKAGE_NAMES=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[].name' | tr '\n' ' ') | ||
# Check if the extracted package name is a valid package in the workspace root Cargo.toml | ||
if [[ ! " $PACKAGE_NAMES " =~ " $PACKAGE_NAME " ]]; then | ||
echo "Invalid package name: $PACKAGE_NAME" | ||
exit 1 | ||
fi | ||
echo "Package to publish: $PACKAGE_NAME" | ||
echo "::set-output name=package::$PACKAGE_NAME" | ||
shell: bash | ||
working-directory: ${{ github.workspace }} | ||
|
||
- name: Check Package Version | ||
id: check-version | ||
run: | | ||
PACKAGE_NAME="${{ steps.determine-package.outputs.package }}" | ||
TAG_VERSION=$(echo "${{ github.ref }}" | cut -d 'v' -f 2) | ||
MANIFEST_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r --arg PACKAGE_NAME "$PACKAGE_NAME" '.packages[] | select(.name == $PACKAGE_NAME) | .version') | ||
if [ "$TAG_VERSION" != "$MANIFEST_VERSION" ]; then | ||
echo "Package version in manifest does not match tag version." | ||
exit 1 | ||
else | ||
echo "Package version in manifest matches tag version." | ||
fi | ||
shell: bash | ||
working-directory: ${{ github.workspace }} | ||
|
||
- name: Build and Publish | ||
run: | | ||
PACKAGE_NAME="${{ steps.determine-package.outputs.package }}" | ||
# Publish the specified package within the workspace to crates.io | ||
cargo publish --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --package "$PACKAGE_NAME" | ||
env: | ||
CARGO_TERM_COLOR: always | ||
working-directory: ${{ github.workspace }} |
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
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,6 +1,7 @@ | ||
# Ledger Device Rust SDK | ||
This workspace contains the 3 crates members of Ledger Device Rust SDK | ||
This workspace contains the 4 crates members of Ledger Device Rust SDK | ||
|
||
* [ledger_device_sdk](./ledger_device_sdk): main Rust SDK crate used to build an application that runs on BOLOS OS, | ||
* [ledger_secure_sdk_sys](./ledger_secure_sdk_sys): bindings to [ledger_secure_sdk](https://github.com/LedgerHQ/ledger-secure-sdk) | ||
* [include_gif](./include_gif): procedural macro used to manage GIF. | ||
* [include_gif](./include_gif): procedural macro used to manage GIF | ||
* [testmacro](./testmacro): procedural macro used by unit and integrations tests |
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
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
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
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,15 @@ | ||
[package] | ||
name = "testmacro" | ||
version = "0.1.0" | ||
authors = ["yhql <[email protected]>"] | ||
edition = "2018" | ||
license.workspace = true | ||
repository.workspace = true | ||
description = "procedural macro used to run unit and integration tests" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
syn = { version = "1.0", features = ["full"] } | ||
quote = "1.0" |
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,3 @@ | ||
# testmacro | ||
|
||
A macro inspired from [Writing an OS in Rust](https://os.phil-opp.com/testing/) and [Rust Raspberry OS tutorials](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/13_integrated_testing) that helps building `#![no_std]` tests in some other projects. |
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,23 @@ | ||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
|
||
#[proc_macro_attribute] | ||
pub fn test_item(_attr: TokenStream, item: TokenStream) -> TokenStream { | ||
let input = syn::parse_macro_input!(item as syn::ItemFn); | ||
let name = &input.sig.ident.to_string(); | ||
let func = &input.block; | ||
|
||
let r = quote! { | ||
#[test_case] | ||
const t: TestType = TestType { | ||
modname: module_path!(), | ||
name: #name, | ||
f: || -> Result<(),()> { | ||
#func | ||
Ok(()) | ||
} | ||
}; | ||
}; | ||
r.into() | ||
} |