Skip to content

Commit 1b17bd6

Browse files
committed
Add build
1 parent 9882ff4 commit 1b17bd6

2 files changed

Lines changed: 142 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
tags:
8+
- "*"
9+
10+
jobs:
11+
rops-build-amd64:
12+
name: Build rops binary for amd64
13+
runs-on: ubuntu-22.04
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
- name: Set up Rust
18+
uses: dtolnay/rust-toolchain@stable
19+
- name: Build rops binary
20+
run: cargo build --release
21+
- name: Upload artifact (binary)
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: rops-amd64-
25+
if-no-files-found: error
26+
path: target/release/rops
27+
28+
rops-build-arm64:
29+
name: Build rops binary for arm64
30+
runs-on: ubuntu-22.04
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
- name: Set up Rust
35+
uses: dtolnay/rust-toolchain@stable
36+
- name: Install GCC for arm64
37+
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
38+
- name: Build rops binary for arm64
39+
run: rustup target add aarch64-unknown-linux-gnu && cargo build --release --target aarch64-unknown-linux-gnu
40+
- name: Upload artifact (binary for arm64)
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: rops-arm64-
44+
if-no-files-found: error
45+
path: rops/target/aarch64-unknown-linux-gnu/release/rops
46+
47+
rops-release:
48+
name: Release rops binary
49+
needs: [rops-build-amd64, rops-build-arm64]
50+
runs-on: ubuntu-latest
51+
permissions:
52+
contents: write
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@v4
56+
- name: Download artifacts
57+
uses: actions/download-artifact@v4
58+
- name: Rename artifacts
59+
run: |
60+
mv rops-amd64-/rops rops-amd64
61+
mv rops-arm64-/rops rops-arm64
62+
- name: Create GitHub Release
63+
if: startsWith(github.ref, 'refs/tags/')
64+
uses: ncipollo/release-action@v1
65+
with:
66+
artifacts: "rops-amd64,rops-arm64"

dev/install-rops

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
5+
# Load environment variables from .env file
6+
ENV_FILE="${PWD}/.env"
7+
touch "${ENV_FILE}"
8+
export $(grep -v '^#' "${ENV_FILE}" | xargs)
9+
10+
11+
raw_arch=$(uname -m)
12+
13+
# Determine the architecture string ("amd64" or "arm64")
14+
case "$raw_arch" in
15+
x86_64)
16+
ARCH="amd64"
17+
URL=${AMD64_BINARY_URL}
18+
;;
19+
aarch64|arm64) # Match both 'aarch64' and 'arm64' outputs
20+
ARCH="arm64"
21+
URL=${ARM64_BINARY_URL}
22+
;;
23+
*)
24+
echo "Error: Detected architecture '$raw_arch' is not explicitly supported as amd64 or arm64." >&2
25+
exit 1
26+
;;
27+
esac
28+
29+
EXECUTABLE="rops-${ARCH}"
30+
31+
# Fetch the release JSON from GitHub API
32+
RELEASE_JSON=$(curl -s \
33+
-H "Accept: application/vnd.github+json" \
34+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
35+
https://api.github.com/repos/quantmind/rops/releases/latest)
36+
37+
echo "Release JSON: ${RELEASE_JSON}"
38+
# Extract the top-level release name from the JSON file
39+
TAG=$(echo "${RELEASE_JSON}" | grep -oP '"name":\s*"\K[^"]+' | head -n 1)
40+
41+
if [ -z "${TAG}" ]; then
42+
echo "Error: Top-level release name not found in the JSON file." >&2
43+
exit 1
44+
fi
45+
46+
47+
# Extract the asset ID for the given asset name from RELEASE_JSON
48+
ASSET_ID=$(echo "${RELEASE_JSON}" | grep -oP '"id":\s*\d+|"name":\s*"'${EXECUTABLE}'"' | paste - - | grep "\"name\": \"${EXECUTABLE}\"" | sed -n 's/.*"id":\s*\([0-9]*\).*/\1/p')
49+
50+
if [ -z "${ASSET_ID}" ]; then
51+
echo "Error: Asset with name '${EXECUTABLE}' not found in the release assets." >&2
52+
exit 1
53+
fi
54+
55+
INSTALL_DIR="$HOME/bin"
56+
57+
# Create the ~/bin directory if it doesn't exist
58+
mkdir -p "$INSTALL_DIR"
59+
EXECUTABLE_PATH="${INSTALL_DIR}/rops"
60+
61+
ASSET_URL="https://api.github.com/repos/quantmind/rops/releases/assets/${ASSET_ID}"
62+
echo "Download rops executable from ${ASSET_URL}"
63+
curl -L \
64+
-H "Accept: application/octet-stream" \
65+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
66+
${ASSET_URL} -o ${EXECUTABLE_PATH}
67+
68+
if [ $? -ne 0 ]; then
69+
echo "Error: Failed to download the asset '${BINARY_NAME}'." >&2
70+
exit 1
71+
fi
72+
73+
chmod +x ${EXECUTABLE_PATH}
74+
echo "Installed ${EXECUTABLE_PATH}"
75+
76+
${EXECUTABLE_PATH} settings

0 commit comments

Comments
 (0)