Skip to content

Commit 130c67a

Browse files
committed
Adding release automation and version management
1 parent 2ae393b commit 130c67a

4 files changed

Lines changed: 354 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
create-release:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
upload_url: ${{ steps.create_release.outputs.upload_url }}
17+
version: ${{ steps.get_version.outputs.version }}
18+
steps:
19+
- name: Get version from tag
20+
id: get_version
21+
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
22+
23+
- name: Create Release
24+
id: create_release
25+
uses: actions/create-release@v1
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
with:
29+
tag_name: ${{ github.ref }}
30+
release_name: CANopen Data Viewer v${{ steps.get_version.outputs.version }}
31+
body: |
32+
## CANopen Real-time Monitor & Plotter v${{ steps.get_version.outputs.version }}
33+
34+
### Features
35+
- Real-time CANopen SDO monitoring and plotting
36+
- Comprehensive subscription management
37+
- Plot export (PNG screenshots and CSV data)
38+
- Automatic logging with timestamps
39+
- Connection status monitoring
40+
41+
### Installation
42+
43+
**Linux (Debian/Ubuntu):**
44+
```bash
45+
# Install .deb package
46+
sudo dpkg -i canopen-viewer_${{ steps.get_version.outputs.version }}_amd64.deb
47+
sudo apt-get install -f # Fix any dependency issues
48+
```
49+
50+
**Linux (Generic):**
51+
```bash
52+
# Extract and run executable
53+
chmod +x canopen-viewer
54+
./canopen-viewer
55+
```
56+
57+
### System Requirements
58+
- Linux with CAN interface support
59+
- socketcan kernel modules
60+
- For virtual testing: `sudo modprobe vcan && sudo ip link add dev vcan0 type vcan && sudo ip link set up vcan0`
61+
62+
### Quick Start
63+
1. Set up your CAN interface (physical or virtual)
64+
2. Run the application
65+
3. Select interface, node ID, and EDS file
66+
4. Start monitoring and subscribe to SDO objects
67+
draft: false
68+
prerelease: false
69+
70+
build-linux:
71+
needs: create-release
72+
runs-on: ubuntu-latest
73+
strategy:
74+
matrix:
75+
target: [x86_64-unknown-linux-gnu]
76+
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@v4
80+
81+
- name: Set up Rust
82+
uses: actions-rs/toolchain@v1
83+
with:
84+
toolchain: stable
85+
target: ${{ matrix.target }}
86+
override: true
87+
88+
- name: Install system dependencies
89+
run: |
90+
sudo apt-get update
91+
sudo apt-get install -y \
92+
libx11-dev \
93+
libxrandr-dev \
94+
libxi-dev \
95+
libgl1-mesa-dev \
96+
libasound2-dev \
97+
pkg-config \
98+
build-essential
99+
100+
- name: Update version in Cargo.toml
101+
run: |
102+
sed -i 's/version = "0\.1\.0"/version = "${{ needs.create-release.outputs.version }}"/' canopen-viewer/Cargo.toml
103+
sed -i 's/version = "0\.1\.0"/version = "${{ needs.create-release.outputs.version }}"/' canopen-common/Cargo.toml
104+
sed -i 's/version = "0\.1\.0"/version = "${{ needs.create-release.outputs.version }}"/' mock-canopen-node/Cargo.toml
105+
106+
- name: Build release binary
107+
uses: actions-rs/cargo@v1
108+
with:
109+
command: build
110+
args: --release --target ${{ matrix.target }} -p canopen-viewer
111+
112+
- name: Create binary archive
113+
run: |
114+
mkdir -p dist
115+
cp target/${{ matrix.target }}/release/canopen-viewer dist/
116+
cp README.md dist/
117+
cp LICENSE dist/ || echo "LICENSE file not found, skipping"
118+
cd dist
119+
tar czf ../canopen-viewer-v${{ needs.create-release.outputs.version }}-${{ matrix.target }}.tar.gz .
120+
121+
- name: Upload binary archive
122+
uses: actions/upload-release-asset@v1
123+
env:
124+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
with:
126+
upload_url: ${{ needs.create-release.outputs.upload_url }}
127+
asset_path: ./canopen-viewer-v${{ needs.create-release.outputs.version }}-${{ matrix.target }}.tar.gz
128+
asset_name: canopen-viewer-v${{ needs.create-release.outputs.version }}-${{ matrix.target }}.tar.gz
129+
asset_content_type: application/gzip
130+
131+
build-deb-package:
132+
needs: create-release
133+
runs-on: ubuntu-latest
134+
135+
steps:
136+
- name: Checkout code
137+
uses: actions/checkout@v4
138+
139+
- name: Set up Rust
140+
uses: actions-rs/toolchain@v1
141+
with:
142+
toolchain: stable
143+
override: true
144+
145+
- name: Install system dependencies
146+
run: |
147+
sudo apt-get update
148+
sudo apt-get install -y \
149+
libx11-dev \
150+
libxrandr-dev \
151+
libxi-dev \
152+
libgl1-mesa-dev \
153+
libasound2-dev \
154+
pkg-config \
155+
build-essential \
156+
dpkg-dev \
157+
fakeroot
158+
159+
- name: Update version in Cargo.toml
160+
run: |
161+
sed -i 's/version = "0\.1\.0"/version = "${{ needs.create-release.outputs.version }}"/' canopen-viewer/Cargo.toml
162+
sed -i 's/version = "0\.1\.0"/version = "${{ needs.create-release.outputs.version }}"/' canopen-common/Cargo.toml
163+
sed -i 's/version = "0\.1\.0"/version = "${{ needs.create-release.outputs.version }}"/' mock-canopen-node/Cargo.toml
164+
165+
- name: Build release binary
166+
uses: actions-rs/cargo@v1
167+
with:
168+
command: build
169+
args: --release -p canopen-viewer
170+
171+
- name: Create .deb package structure
172+
run: |
173+
mkdir -p debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/DEBIAN
174+
mkdir -p debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/usr/bin
175+
mkdir -p debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/usr/share/applications
176+
mkdir -p debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/usr/share/doc/canopen-viewer
177+
mkdir -p debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/usr/share/pixmaps
178+
179+
- name: Copy binary and create package files
180+
run: |
181+
# Copy binary
182+
cp target/release/canopen-viewer debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/usr/bin/
183+
184+
# Create control file
185+
cat > debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/DEBIAN/control << EOF
186+
Package: canopen-viewer
187+
Version: ${{ needs.create-release.outputs.version }}
188+
Section: electronics
189+
Priority: optional
190+
Architecture: amd64
191+
Depends: libc6, libx11-6, libxrandr2, libxi6, libgl1-mesa-glx, libasound2
192+
Maintainer: CANopen Data Viewer Team
193+
Description: CANopen Real-time Monitor & Plotter
194+
A high-performance Rust application for CANopen diagnostics providing
195+
real-time visualization of TPDO/SDO data from CAN bus devices with
196+
configurable polling and plotting capabilities.
197+
EOF
198+
199+
# Create desktop entry
200+
cat > debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/usr/share/applications/canopen-viewer.desktop << EOF
201+
[Desktop Entry]
202+
Name=CANopen Data Viewer
203+
Comment=CANopen Real-time Monitor & Plotter
204+
Exec=canopen-viewer
205+
Icon=canopen-viewer
206+
Type=Application
207+
Categories=Development;Electronics;
208+
EOF
209+
210+
# Copy documentation
211+
cp README.md debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64/usr/share/doc/canopen-viewer/
212+
213+
- name: Build .deb package
214+
run: |
215+
cd debian
216+
dpkg-deb --build canopen-viewer_${{ needs.create-release.outputs.version }}_amd64
217+
218+
- name: Upload .deb package
219+
uses: actions/upload-release-asset@v1
220+
env:
221+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
222+
with:
223+
upload_url: ${{ needs.create-release.outputs.upload_url }}
224+
asset_path: ./debian/canopen-viewer_${{ needs.create-release.outputs.version }}_amd64.deb
225+
asset_name: canopen-viewer_${{ needs.create-release.outputs.version }}_amd64.deb
226+
asset_content_type: application/vnd.debian.binary-package

canopen-viewer/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ open = "5.0"
2626

2727
# This will use the shared CANopen protocol code
2828
canopen-common = { path = "../canopen-common" }
29+
30+
[build-dependencies]
31+
chrono = "0.4.41"

canopen-viewer/build.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
// Get version from Cargo.toml
5+
let version = env!("CARGO_PKG_VERSION");
6+
println!("cargo:rustc-env=APP_VERSION={}", version);
7+
8+
// Get git information if available
9+
let git_hash = Command::new("git")
10+
.args(&["rev-parse", "--short", "HEAD"])
11+
.output()
12+
.ok()
13+
.and_then(|output| String::from_utf8(output.stdout).ok())
14+
.map(|s| s.trim().to_string())
15+
.unwrap_or_else(|| "unknown".to_string());
16+
17+
let git_branch = Command::new("git")
18+
.args(&["rev-parse", "--abbrev-ref", "HEAD"])
19+
.output()
20+
.ok()
21+
.and_then(|output| String::from_utf8(output.stdout).ok())
22+
.map(|s| s.trim().to_string())
23+
.unwrap_or_else(|| "unknown".to_string());
24+
25+
// Check if git repo is dirty
26+
let git_dirty = Command::new("git")
27+
.args(&["diff", "--quiet"])
28+
.status()
29+
.map(|status| !status.success())
30+
.unwrap_or(false);
31+
32+
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
33+
println!("cargo:rustc-env=GIT_BRANCH={}", git_branch);
34+
println!("cargo:rustc-env=GIT_DIRTY={}", git_dirty);
35+
36+
// Embed build timestamp
37+
let build_time = chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC").to_string();
38+
println!("cargo:rustc-env=BUILD_TIME={}", build_time);
39+
40+
// Re-run if git HEAD changes
41+
println!("cargo:rerun-if-changed=.git/HEAD");
42+
println!("cargo:rerun-if-changed=.git/index");
43+
}

0 commit comments

Comments
 (0)