Skip to content

Build dd Static Binaries #1

Build dd Static Binaries

Build dd Static Binaries #1

Workflow file for this run

name: Build and Package Coreutils
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 检出代码库
uses: actions/checkout@v4
- name: 获取最新版本号
id: get_version
run: |
LATEST_RELEASE=$(curl -s https://api.github.com/repos/uutils/coreutils/releases/latest)
VERSION=$(echo "$LATEST_RELEASE" | grep -Po '"tag_name": "\K.*?(?=")' | sed 's/^v//')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "版本号: $VERSION"
- name: 下载并处理所有Coreutils二进制文件
run: |
# 定义所有目标平台
declare -A TARGETS=(
["x86_64-unknown-linux-gnu"]="linux-amd64"
["aarch64-unknown-linux-gnu"]="linux-arm64"
["i686-unknown-linux-gnu"]="linux-386"
["x86_64-unknown-linux-musl"]="linux-musl-amd64"
["aarch64-unknown-linux-musl"]="linux-musl-arm64"
["i686-unknown-linux-musl"]="linux-musl-386"
["x86_64-apple-darwin"]="darwin-amd64"
["aarch64-apple-darwin"]="darwin-arm64"
["x86_64-pc-windows-msvc"]="windows-amd64"
["i686-pc-windows-msvc"]="windows-386"
["arm-unknown-linux-gnueabihf"]="linux-armhf"
)
# 处理每个目标
for TRIPLE in "${!TARGETS[@]}"; do
NAME="${TARGETS[$TRIPLE]}"
echo "处理平台: $TRIPLE -> $NAME"
# 确定文件扩展名
if [[ "$TRIPLE" == *"windows"* ]]; then
EXT="zip"
else
EXT="tar.gz"
fi
# 构建下载URL
URL="https://github.com/uutils/coreutils/releases/latest/download/coreutils-$VERSION-$TRIPLE.$EXT"
DOWNLOAD_FILE="coreutils-$VERSION-$TRIPLE.$EXT"
echo "下载: $URL"
# 下载文件
curl -L -o "$DOWNLOAD_FILE" "$URL"
# 根据文件类型解压
mkdir -p "temp_extract_$NAME"
if [[ "$EXT" == "zip" ]]; then
unzip -q "$DOWNLOAD_FILE" -d "temp_extract_$NAME"
# 查找并复制二进制文件
BINARY_PATH=$(find "temp_extract_$NAME" -type f -name "coreutils.exe" | head -n 1)
if [ -n "$BINARY_PATH" ]; then
cp "$BINARY_PATH" "bin/coreutils-$NAME.exe"
echo "✅ 成功提取: bin/coreutils-$NAME.exe"
else
echo "❌ 未找到 coreutils.exe,显示目录结构:"
find "temp_extract_$NAME" -type f
fi
else
tar -xf "$DOWNLOAD_FILE" -C "temp_extract_$NAME"
# 查找并复制二进制文件
BINARY_PATH=$(find "temp_extract_$NAME" -type f -name "coreutils" | head -n 1)
if [ -n "$BINARY_PATH" ]; then
cp "$BINARY_PATH" "bin/coreutils-$NAME"
chmod +x "bin/coreutils-$NAME"
echo "✅ 成功提取: bin/coreutils-$NAME"
else
echo "❌ 未找到 coreutils 二进制文件,显示目录结构:"
find "temp_extract_$NAME" -type f
fi
fi
# 清理临时文件
rm -f "$DOWNLOAD_FILE"
rm -rf "temp_extract_$NAME"
done
- name: 配置Git
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: 提交并推送二进制文件
run: |
# 列出提取的文件
echo "提取的二进制文件:"
ls -la bin/
# 提交更改
git add bin/
# 只有当有更改时才提交
if git diff --staged --quiet; then
echo "没有更改需要提交"
else
git commit -m "fix: 更新 Coreutils 二进制文件到版本 $VERSION [自动]"
git push
fi