Skip to content

Commit da9a842

Browse files
arsenii-fireboltgm42
authored andcommitted
fb-cli initial release
0 parents  commit da9a842

File tree

17 files changed

+3966
-0
lines changed

17 files changed

+3966
-0
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.aarch64-unknown-linux-musl]
2+
linker = "aarch64-unknown-linux-musl-gcc"

.github/workflows/build-static.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build Static Binary
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
pull_request:
7+
branches:
8+
- main
9+
10+
env:
11+
MUSL_CROSS_VERSION: "20250520"
12+
13+
jobs:
14+
build-static:
15+
strategy:
16+
matrix:
17+
arch: [ x86_64, aarch64 ]
18+
name: Build Static Binary for ${{ matrix.arch }}
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
show-progress: 'false'
26+
fetch-depth: 0
27+
28+
- name: Install musl tools
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y musl-tools
32+
33+
- name: Download musl-cross toolchain
34+
if: matrix.arch == 'aarch64'
35+
run: |
36+
TARGET_ARCH="aarch64-unknown-linux-musl"
37+
TOOLCHAIN_URL="https://github.com/cross-tools/musl-cross/releases/download/${MUSL_CROSS_VERSION}/${TARGET_ARCH}.tar.xz"
38+
39+
sudo mkdir -p /opt/x-tools
40+
wget -qO- "${TOOLCHAIN_URL}" | sudo tar -xJf - -C /opt/x-tools
41+
42+
# this symlink is necessary so that rust compiler will find musl GCC
43+
sudo ln -s /opt/x-tools/${TARGET_ARCH}/bin/aarch64-unknown-linux-musl-gcc \
44+
/usr/local/bin/aarch64-linux-musl-gcc
45+
46+
echo "/opt/x-tools/${TARGET_ARCH}/bin" >> $GITHUB_PATH
47+
48+
echo "STRIP_PREFIX=aarch64-unknown-linux-musl-" >> "$GITHUB_ENV"
49+
50+
- name: Install Rust
51+
uses: dtolnay/rust-toolchain@stable
52+
with:
53+
toolchain: stable
54+
targets: ${{ matrix.arch }}-unknown-linux-musl
55+
56+
- name: Cache cargo registry
57+
uses: actions/cache@v3
58+
with:
59+
path: |
60+
~/.cargo/registry
61+
~/.cargo/git
62+
target
63+
key: ${{ runner.os }}-${{ matrix.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}
64+
restore-keys: |
65+
${{ runner.os }}-${{ matrix.arch }}-cargo-
66+
67+
- name: Build static binary
68+
run: |
69+
cargo build --release --target "${{ matrix.arch }}-unknown-linux-musl" --locked
70+
71+
- name: Verify static linking with ldd
72+
run: |
73+
BINARY_PATH="target/${{ matrix.arch }}-unknown-linux-musl/release/fb"
74+
75+
if ldd "$BINARY_PATH" 2>&1 | grep -qF "not a dynamic executable"; then
76+
echo "✅ Binary '$BINARY_PATH' is statically linked." >> "$GITHUB_STEP_SUMMARY"
77+
elif ldd "$BINARY_PATH" 2>&1 | grep -qF "statically linked"; then
78+
echo "✅ Binary '$BINARY_PATH' is statically linked." >> "$GITHUB_STEP_SUMMARY"
79+
else
80+
echo "❌ Binary '$BINARY_PATH' is NOT statically linked:" >> "$GITHUB_STEP_SUMMARY"
81+
ldd "$BINARY_PATH" 1>&2
82+
exit 1
83+
fi
84+
85+
- name: Strip binary
86+
run: |
87+
${STRIP_PREFIX}strip "target/${{ matrix.arch }}-unknown-linux-musl/release/fb"
88+
89+
- name: Move binary into artifacts directory
90+
run: |
91+
mkdir -p artifacts
92+
cp "target/${{ matrix.arch }}-unknown-linux-musl/release/fb" "artifacts/fb-linux-static-${{ matrix.arch }}"
93+
94+
- name: Upload binary
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: fb-linux-static-${{ matrix.arch }}
98+
path: artifacts/fb-linux-static-${{ matrix.arch }}
99+
retention-days: 7

.github/workflows/release.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Release on Version Change
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
uses: ./.github/workflows/build-static.yml
11+
release:
12+
runs-on: ubuntu-latest
13+
needs: ['build']
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Get latest released version
21+
id: releases
22+
run: |
23+
LATEST_RELEASE_JSON=$(curl -sL \
24+
-H "Accept: application/vnd.github+json" \
25+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
26+
-H "X-GitHub-Api-Version: 2022-11-28" \
27+
"${{ github.api_url }}/repos/${{ github.repository }}/releases/latest")
28+
29+
TAG_NAME=$(echo "$LATEST_RELEASE_JSON" | jq -r .tag_name)
30+
# remove the leading 'v' from the tag name
31+
echo "latest_version=${TAG_NAME:1}" >> "$GITHUB_OUTPUT"
32+
echo "🕰️ Latest released version: $TAG_NAME" >> "$GITHUB_STEP_SUMMARY"
33+
34+
- name: Get current version from Cargo.toml
35+
id: main_branch
36+
run: |
37+
CURRENT_VERSION=$(grep '^version' Cargo.toml | head -n 1 | awk -F '"' '{print $2}')
38+
echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
39+
echo "📝 Version detected in Cargo.toml: $CURRENT_VERSION" >> "$GITHUB_STEP_SUMMARY"
40+
41+
- name: Compare versions
42+
id: compare_versions
43+
run: |
44+
MAIN_BRANCH_VERSION="${{ steps.main_branch.outputs.version }}"
45+
LATEST_VERSION="${{ steps.releases.outputs.latest_version }}"
46+
47+
# Use sort -V to compare the versions numerically.
48+
# If MAIN_BRANCH_VERSION is truly greater, it will be the second item
49+
# when sorted, and they must not be identical.
50+
if [ "$(printf '%s\n' "$MAIN_BRANCH_VERSION" "$LATEST_VERSION" | sort -V | head -n 1)" = "$LATEST_VERSION" ] && \
51+
[ "$MAIN_BRANCH_VERSION" != "$LATEST_VERSION" ]; then
52+
echo "needs_release=true" >> "$GITHUB_OUTPUT"
53+
fi
54+
55+
- name: Download x86_64 binary
56+
if: steps.compare_versions.outputs.needs_release
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: fb-linux-static-x86_64
60+
61+
- name: Download aarch64 binary
62+
if: steps.compare_versions.outputs.needs_release
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: fb-linux-static-aarch64
66+
67+
- name: Generate release notes
68+
if: steps.compare_versions.outputs.needs_release
69+
id: release_notes
70+
run: |
71+
git log v${{ steps.releases.outputs.latest_version }}..HEAD --pretty=format:"* %s [%h](https://github.com/${{ github.repository }}/commit/%H)" > release_notes.md
72+
73+
- name: Create GitHub Release if version changed
74+
if: steps.compare_versions.outputs.needs_release
75+
id: create_release
76+
uses: actions/create-release@v1
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
with:
80+
tag_name: v${{ steps.main_branch.outputs.version }}
81+
release_name: Release v${{ steps.main_branch.outputs.version }}
82+
body_path: release_notes.md
83+
84+
- name: Upload x86_64 binary onto release
85+
if: steps.compare_versions.outputs.needs_release
86+
uses: actions/upload-release-asset@v1
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
with:
90+
upload_url: ${{ steps.create_release.outputs.upload_url }}
91+
asset_path: fb-linux-static-x86_64
92+
asset_name: fb-linux-static-x86_64
93+
asset_content_type: application/octet-stream
94+
95+
- name: Upload aarch64 binary onto release
96+
if: steps.compare_versions.outputs.needs_release
97+
uses: actions/upload-release-asset@v1
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
with:
101+
upload_url: ${{ steps.create_release.outputs.upload_url }}
102+
asset_path: fb-linux-static-aarch64
103+
asset_name: fb-linux-static-aarch64
104+
asset_content_type: application/octet-stream

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

0 commit comments

Comments
 (0)