Skip to content

Commit

Permalink
Add Rust workflow (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hatchan authored Jun 5, 2024
1 parent 1833002 commit a5d0ab9
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 18 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Test and build the project.
---
name: Build API

on:
# Allow manual trigger
workflow_dispatch:

# Run on every pull request
pull_request:
branches: ["*"]

# Run on every push to main
push:
branches: ["main"]

jobs:
build-rust:
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest-8-cores

name: Create binary for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
env:
CARGO: cargo
TARGET_FLAGS: ""
TARGET_DIR: ../target
RUST_BACKTRACE: 1

permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: "" # Do not fail on warnings, so reset the default value to empty

- name: cargo test
run: cargo test

- name: cargo build
run: cargo build --release

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: fpx_${{ matrix.target }}
path: target/release/fpx
if-no-files-found: error
retention-days: 7
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
resolver = "2"
members = ["fpx"]

[workspace.package]
authors = ["Fiberplane <[email protected]>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/fiberplane/fpx"

[workspace.dependencies]
23 changes: 23 additions & 0 deletions LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
23 changes: 23 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Description

This has an api and a frontend that can consume telemetry data from a Hono app.
This has an api and a frontend that can consume telemetry data from a Hono app.

To connect your Hono app to the api, you'll need to add the code in the [`client-library`](./client-library) folder to your Hono app. This will send telemetry data to the api.

Expand All @@ -14,9 +14,9 @@ The frontend is a React + Typescript + Tailwind app that uses [shadcn/ui](https:

## Setup

You'll want to
You'll want to

1. Run the code in this repo, and then
1. Run the code in this repo, and then
2. Add some client code to a Hono app

The next two sections take you through how to do this.
Expand All @@ -35,4 +35,11 @@ Follow the instructions in the [`client-library` README](./client-library/README

## Developing

I turned off Biome. But we could always add it? Idk.
I turned off Biome. But we could always add it? Idk.

## License

All code within the `fpx` repository is distributed under the terms of
both the MIT license and the Apache License (Version 2.0).

See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT).
4 changes: 4 additions & 0 deletions fpx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name = "fpx"
version = "0.1.0"
edition = "2021"
authors = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

[dependencies]
anyhow = { version = "1.0" }
Expand All @@ -21,6 +24,7 @@ reqwest = { version = "0.12", default-features = false, features = [
"charset",
"http2",
"rustls-tls",
"json",
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
Expand Down
46 changes: 46 additions & 0 deletions fpx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# fpx

The fpx command is a command line tool that hosts the API and UI.

The fpx tool is intended to be used within a repository as it will use the code
in the repository for retrieving data while also storing cache in the same
repository.

## Usage

To run the fpx tool, download en install it first, then run the following command:

```
fpx dev
```

Depending on your configuration some background tasks will be started and a web
server will be started. By default this will be available at
`http://localhost:6767`.

## Installation

### npm

> TODO: Publish to npm
- npm install -g @fiberplane/fpx

### Homebrew

> TODO: Create homebrew repo
- brew install fiberplane/fpx/fpx

### Cargo

> TODO: Publish to crates.io
- Run `cargo install fpx`

### Manual installation

> TODO: Create releases
- Download the latest release from the [releases page](https://github.com/fiberplane/fpx/releases).
- Make it available in you `$PATH`
2 changes: 1 addition & 1 deletion fpx/src/api/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::response::Html;
use axum::response::IntoResponse;

pub async fn logs_handler(State(events): State<EventsState<ServerMessage>>) -> impl IntoResponse {
events.broadcast(ServerMessage::Otel).await;
events.broadcast(ServerMessage::Otel);

Html("Hello, world!")
}
6 changes: 2 additions & 4 deletions fpx/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ mod ws;

/// Create a API and expose it through a axum router.
pub async fn create_api(events: EventsState<ServerMessage>) -> axum::Router {
let app = axum::Router::new()
axum::Router::new()
.route("/api/v1/logs", get(handlers::logs_handler))
.route("/api/ws", get(ws::ws_handler))
.route("/", get(|| async { Html("Hello, world!") }))
.with_state(events);

app
.with_state(events)
}
5 changes: 3 additions & 2 deletions fpx/src/commands/dev.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{api, events::Events};
use crate::api;
use crate::events::Events;
use anyhow::{Context, Result};
use std::sync::Arc;
use tracing::{debug, info};
use tracing::info;

#[derive(clap::Args, Debug)]
pub struct Args {
Expand Down
4 changes: 2 additions & 2 deletions fpx/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ pub type EventsState<M> = Arc<Events<M>>;

impl<M: Clone> Events<M> {
pub fn new() -> Self {
let (sender, _) = broadcast::channel(10);
let (sender, _) = broadcast::channel(100);
Self { sender }
}

pub async fn broadcast(&self, msg: M) {
pub fn broadcast(&self, msg: M) {
debug!("Broadcasting message:");
let _ = self.sender.send(msg);
}
Expand Down
2 changes: 1 addition & 1 deletion fpx/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

pub const FPX_WEBSOCKET_ID_HEADER: &'static str = "fpx-websocket-id";
pub const FPX_WEBSOCKET_ID_HEADER: &str = "fpx-websocket-id";

/// Messages that are send from the server to the client.
#[derive(Clone, Serialize, Deserialize)]
Expand Down

0 comments on commit a5d0ab9

Please sign in to comment.