Files
http-rs/.gitea/workflows/compile.yaml
T
rattatwinko 7be522de0c
Compile to Binary / build-linux (push) Successful in 1m22s
Compile to Binary / build-linux-musl (push) Successful in 1m39s
Compile to Binary / build-windows (push) Successful in 2m1s
Compile to Binary / release (push) Successful in 17s
testing new workflow in dev branch!
2026-04-29 18:45:00 +02:00

231 lines
7.3 KiB
YAML

name: Compile to Binary
on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]
workflow_dispatch:
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check if Rust/Cargo is already installed
id: rust-check-linux
run: |
if command -v cargo &>/dev/null; then
echo "installed=true" >> $GITHUB_OUTPUT
echo "Cargo found: $(cargo --version)"
else
echo "installed=false" >> $GITHUB_OUTPUT
fi
- name: Install Rust
if: steps.rust-check-linux.outputs.installed == 'false'
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu
- name: Add target (if Rust was pre-installed)
if: steps.rust-check-linux.outputs.installed == 'true'
run: rustup target add x86_64-unknown-linux-gnu
- name: Cache Cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: linux-${{ hashFiles('**/Cargo.lock') }}
- name: Build Linux (glibc)
run: cargo build --release --target x86_64-unknown-linux-gnu
- name: Copy executable
run: |
mkdir -p artifacts
cp target/x86_64-unknown-linux-gnu/release/http-rs artifacts/http-rs-linux-x86_64
- uses: actions/upload-artifact@v3
with:
name: http-rs-linux-x86_64
path: artifacts/http-rs-linux-x86_64
build-linux-musl:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install musl tools
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Check if Rust/Cargo is already installed
id: rust-check-musl
run: |
if command -v cargo &>/dev/null; then
echo "installed=true" >> $GITHUB_OUTPUT
echo "Cargo found: $(cargo --version)"
else
echo "installed=false" >> $GITHUB_OUTPUT
fi
- name: Install Rust
if: steps.rust-check-musl.outputs.installed == 'false'
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-musl
- name: Add target (if Rust was pre-installed)
if: steps.rust-check-musl.outputs.installed == 'true'
run: rustup target add x86_64-unknown-linux-musl
- name: Cache Cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: musl-${{ hashFiles('**/Cargo.lock') }}
- name: Build static binary
run: cargo build --release --target x86_64-unknown-linux-musl
- name: Copy executable
run: |
mkdir -p artifacts
cp target/x86_64-unknown-linux-musl/release/http-rs artifacts/http-rs-linux-musl-x86_64
- uses: actions/upload-artifact@v3
with:
name: http-rs-linux-musl-x86_64
path: artifacts/http-rs-linux-musl-x86_64
build-windows:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install MinGW
run: sudo apt-get update && sudo apt-get install -y gcc-mingw-w64-x86-64
- name: Check if Rust/Cargo is already installed
id: rust-check-windows
run: |
if command -v cargo &>/dev/null; then
echo "installed=true" >> $GITHUB_OUTPUT
echo "Cargo found: $(cargo --version)"
else
echo "installed=false" >> $GITHUB_OUTPUT
fi
- name: Install Rust
if: steps.rust-check-windows.outputs.installed == 'false'
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-pc-windows-gnu
- name: Add target (if Rust was pre-installed)
if: steps.rust-check-windows.outputs.installed == 'true'
run: rustup target add x86_64-pc-windows-gnu
- name: Cache Cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: windows-${{ hashFiles('**/Cargo.lock') }}
- name: Build Windows
run: cargo build --release --target x86_64-pc-windows-gnu
- name: Copy executable
run: |
mkdir -p artifacts
cp target/x86_64-pc-windows-gnu/release/http-rs.exe artifacts/http-rs-windows-x86_64.exe
- uses: actions/upload-artifact@v3
with:
name: http-rs-windows-x86_64
path: artifacts/http-rs-windows-x86_64.exe
release:
runs-on: ubuntu-latest
needs: [build-linux, build-linux-musl, build-windows]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Ensure jq is installed
run: |
if ! command -v jq &>/dev/null; then
sudo apt-get update && sudo apt-get install -y jq
else
echo "jq already present: $(jq --version)"
fi
- name: Gather commit info
id: info
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
BRANCH="${{ gitea.ref_name }}"
COMMIT_MSG=$(git log -1 --format="%s")
FULL_MSG=$(git log -1 --format="%B")
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "commit_msg=$COMMIT_MSG" >> $GITHUB_OUTPUT
echo "full_msg<<EOF" >> $GITHUB_OUTPUT
echo "$FULL_MSG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: release-artifacts
- name: Create Gitea release and upload assets
env:
GITEA_TOKEN: ${{ secrets.HTTP_RS_RELEASE_PUSH }}
SERVER_URL: ${{ gitea.server_url }}
REPO: ${{ gitea.repository }}
TAG: ${{ steps.info.outputs.short_sha }}-${{ steps.info.outputs.branch }}
RELEASE_NAME: "${{ steps.info.outputs.short_sha }}:${{ steps.info.outputs.branch }} - ${{ steps.info.outputs.commit_msg }}"
BODY: ${{ steps.info.outputs.full_msg }}
run: |
RELEASE_RESPONSE=$(curl -s -X POST \
"$SERVER_URL/api/v1/repos/$REPO/releases" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--arg tag "$TAG" \
--arg name "$RELEASE_NAME" \
--arg body "$BODY" \
'{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}'
)")
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id')
echo "Created release ID: $RELEASE_ID"
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then
echo "Failed to create release:"
echo "$RELEASE_RESPONSE"
exit 1
fi
find release-artifacts -type f | while read FILE; do
FILENAME=$(basename "$FILE")
echo "Uploading $FILENAME..."
curl -s -X POST \
"$SERVER_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=$FILENAME" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$FILE"
done