Skip to content

Commit 5f7feb8

Browse files
feat: add package check script (#3)
* feat: add package check script * feat: increase timeout * feat: add propagation sleep --------- Co-authored-by: Aleksander Błaszkiewicz <aleksander.blaszkiewicz@flip.shop>
1 parent af5a9e6 commit 5f7feb8

9 files changed

Lines changed: 226 additions & 79 deletions

File tree

.github/workflows/after-pub.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Check deployed package
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_run:
6+
workflows: ['Release-plz']
7+
types:
8+
- completed
9+
branches:
10+
- main
11+
12+
jobs:
13+
check-deployed-package:
14+
name: Check deployed package
15+
runs-on: ubuntu-latest
16+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
21+
22+
- name: Wait for package to propagate
23+
run: sleep 300
24+
25+
- name: Make run script executable
26+
run: chmod +x check-deployed-package/run.sh
27+
28+
- name: Check deployed package
29+
env:
30+
LOGDASH_API_KEY: ${{ secrets.LOGDASH_API_KEY }}
31+
run: ./check-deployed-package/run.sh

.github/workflows/release-plz.yml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
- main
1111

1212
jobs:
13-
# Release unpublished packages.
1413
release-plz-release:
1514
name: Release-plz release
1615
runs-on: ubuntu-latest
@@ -30,29 +29,3 @@ jobs:
3029
env:
3130
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3231
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
33-
34-
# Create a PR with the new versions and changelog, preparing the next release.
35-
# release-plz-pr:
36-
# name: Release-plz PR
37-
# runs-on: ubuntu-latest
38-
# permissions:
39-
# contents: write
40-
# pull-requests: write
41-
# concurrency:
42-
# group: release-plz-${{ github.ref }}
43-
# cancel-in-progress: false
44-
# steps:
45-
# - name: Checkout repository
46-
# uses: actions/checkout@v4
47-
# with:
48-
# fetch-depth: 0
49-
# - name: Install Rust toolchain
50-
# uses: dtolnay/rust-toolchain@stable
51-
# - name: Run release-plz
52-
# uses: release-plz/action@v0.5
53-
# with:
54-
# command: release-pr
55-
# config: release-plz.toml
56-
# env:
57-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58-
# CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "logdash"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
edition = "2024"
55
license = "MIT"
66
authors = ["firesz25 <olek.cz@outlook.com>"]

check-deployed-package/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "logdash-demo"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
logdash = "*"

check-deployed-package/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM rust:1.87-alpine
2+
3+
WORKDIR /app
4+
5+
# Install build dependencies
6+
RUN apk add --no-cache musl-dev
7+
8+
# Copy the Cargo.toml and src files
9+
COPY check-deployed-package/Cargo.toml /app/
10+
COPY check-deployed-package/src /app/src/
11+
12+
# Build the application
13+
RUN cargo build --release
14+
15+
# Run the application
16+
CMD ["./target/release/logdash-demo"]

check-deployed-package/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# LogDash Rust SDK Demo
2+
3+
Use command below to test if the published SDK works:
4+
5+
```
6+
LOGDASH_API_KEY=<your-api-key> ./check-deployed-package/run.sh
7+
```

check-deployed-package/run.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Generate random 5-character seed
5+
LOGS_SEED=$(openssl rand -hex 2 | cut -c1-5)
6+
echo "Generated seed: $LOGS_SEED"
7+
8+
# Generate random metrics seed (1-1,000,000)
9+
METRICS_SEED=$(awk 'BEGIN{srand(); print int(rand()*1000000)+1}')
10+
echo "Generated metrics seed: $METRICS_SEED"
11+
12+
echo "Building LogDash demo Docker image (using published package)..."
13+
docker build --no-cache -t logdash-rust-demo -f check-deployed-package/Dockerfile .
14+
15+
echo
16+
echo "Running LogDash demo..."
17+
echo
18+
19+
# Run in non-interactive mode which works everywhere
20+
docker run --rm \
21+
-e LOGDASH_API_KEY="${LOGDASH_API_KEY}" \
22+
-e LOGS_SEED="${LOGS_SEED}" \
23+
-e METRICS_SEED="${METRICS_SEED}" \
24+
logdash-rust-demo
25+
26+
echo
27+
echo "Demo completed!"
28+
29+
echo
30+
echo "Authenticating with LogDash API..."
31+
32+
# Authenticate with API using the API key
33+
AUTH_RESPONSE=$(curl -s -X 'POST' \
34+
'https://api.logdash.io/auth/api-key' \
35+
-H 'accept: application/json' \
36+
-H 'Content-Type: application/json' \
37+
-d "{
38+
\"apiKey\": \"${LOGDASH_API_KEY}\"
39+
}")
40+
41+
# Extract token and projectId from response
42+
TOKEN=$(echo "$AUTH_RESPONSE" | grep -o '"token":"[^"]*"' | sed 's/"token":"\(.*\)"/\1/')
43+
PROJECT_ID=$(echo "$AUTH_RESPONSE" | grep -o '"projectId":"[^"]*"' | sed 's/"projectId":"\(.*\)"/\1/')
44+
45+
if [ -z "$TOKEN" ] || [ -z "$PROJECT_ID" ]; then
46+
echo "Error: Failed to authenticate with LogDash API"
47+
echo "Response: $AUTH_RESPONSE"
48+
exit 1
49+
fi
50+
51+
echo "Authentication successful. Project ID: $PROJECT_ID"
52+
53+
echo
54+
echo "Fetching logs from LogDash API..."
55+
56+
# Fetch logs from the API
57+
LOGS_RESPONSE=$(curl -s -X 'GET' \
58+
"https://api.logdash.io/projects/${PROJECT_ID}/logs?limit=10" \
59+
-H 'accept: application/json' \
60+
-H "Authorization: Bearer ${TOKEN}")
61+
62+
echo "Logs fetched successfully"
63+
64+
echo
65+
echo "Validating log messages..."
66+
67+
# Expected log messages with seed
68+
EXPECTED_MESSAGES="This is an info log ${LOGS_SEED}
69+
This is an error log ${LOGS_SEED}
70+
This is a warning log ${LOGS_SEED}
71+
This is a debug log ${LOGS_SEED}
72+
This is a http log ${LOGS_SEED}
73+
This is a silly log ${LOGS_SEED}
74+
This is an info log ${LOGS_SEED}
75+
This is a verbose log ${LOGS_SEED}"
76+
77+
# Check if all expected messages are present in the logs
78+
echo "$EXPECTED_MESSAGES" | while IFS= read -r expected_msg; do
79+
if ! echo "$LOGS_RESPONSE" | grep -q "$expected_msg"; then
80+
echo "Error: Expected log message not found: '$expected_msg'"
81+
echo "Logs response: $LOGS_RESPONSE"
82+
exit 1
83+
fi
84+
echo "✓ Found: '$expected_msg'"
85+
done
86+
87+
echo
88+
echo "Fetching metrics from LogDash API..."
89+
90+
# Fetch metrics from the API
91+
METRICS_RESPONSE=$(curl -s -X 'GET' \
92+
"https://api.logdash.io/projects/${PROJECT_ID}/metrics" \
93+
-H 'accept: application/json' \
94+
-H "Authorization: Bearer ${TOKEN}")
95+
96+
echo "Metrics fetched successfully"
97+
98+
echo
99+
echo "Validating metrics..."
100+
101+
# Expected users metric value (metrics_seed + 1)
102+
EXPECTED_USERS_VALUE=$((METRICS_SEED + 1))
103+
104+
# Check if users metric exists with correct value
105+
if ! echo "$METRICS_RESPONSE" | grep -q '"name":"users"'; then
106+
echo "Error: Users metric not found"
107+
echo "Metrics response: $METRICS_RESPONSE"
108+
exit 1
109+
fi
110+
111+
# Extract the value of the users metric and check if it matches expected value
112+
USERS_VALUE=$(echo "$METRICS_RESPONSE" | sed 's/},{/}\n{/g' | grep '"name":"users"' | grep -o '"value":[0-9]*' | sed 's/"value"://')
113+
114+
if [ "$USERS_VALUE" != "$EXPECTED_USERS_VALUE" ]; then
115+
echo "Error: Users metric value mismatch. Expected: $EXPECTED_USERS_VALUE, Found: $USERS_VALUE"
116+
echo "Metrics response: $METRICS_RESPONSE"
117+
exit 1
118+
fi
119+
120+
echo "✓ Found users metric with correct value: $USERS_VALUE"
121+
122+
echo
123+
echo "All expected log messages and metrics found successfully!"
124+
echo "Validation completed!"

check-deployed-package/src/main.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use std::env;
2+
use std::thread;
3+
use std::time::Duration;
4+
5+
fn main() {
6+
println!("=== logdash SDK package check ===");
7+
8+
let api_key = env::var("LOGDASH_API_KEY").ok();
9+
let logs_seed = env::var("LOGS_SEED").unwrap_or_else(|_| "default".to_string());
10+
let metrics_seed = env::var("METRICS_SEED").unwrap_or_else(|_| "1".to_string());
11+
12+
println!("Using API Key: {:?}", api_key);
13+
println!("Using Logs Seed: {}", logs_seed);
14+
println!("Using Metrics Seed: {}", metrics_seed);
15+
16+
// Create logdash instance
17+
let (logger, metrics) = if let Some(key) = api_key {
18+
logdash::create_logdash(logdash::Config::default().api_key(key))
19+
} else {
20+
logdash::create_logdash(logdash::Config::default())
21+
};
22+
23+
// Log messages with seed appended
24+
logger.info(&format!("This is an info log {}", logs_seed));
25+
logger.error(&format!("This is an error log {}", logs_seed));
26+
logger.warn(&format!("This is a warning log {}", logs_seed));
27+
logger.debug(&format!("This is a debug log {}", logs_seed));
28+
logger.http(&format!("This is a http log {}", logs_seed));
29+
logger.silly(&format!("This is a silly log {}", logs_seed));
30+
logger.info(&format!("This is an info log {}", logs_seed));
31+
logger.verbose(&format!("This is a verbose log {}", logs_seed));
32+
33+
// Set and mutate metrics with seed
34+
let metrics_seed_value: f64 = metrics_seed.parse().unwrap_or(1.0);
35+
metrics.set("users".to_string(), metrics_seed_value);
36+
metrics.mutate("users".to_string(), 1.0);
37+
38+
// Wait to ensure data is sent
39+
thread::sleep(Duration::from_secs(5));
40+
}

0 commit comments

Comments
 (0)