refactor: improve caching and installation steps in build workflow

This commit is contained in:
2026-01-11 08:08:12 +01:00
parent 8145f1c7e4
commit b8e209bd03

View File

@@ -19,11 +19,34 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Cache Rust toolchain
uses: actions/cache@v4
with:
path: |
~/.cargo/bin
~/.rustup
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-rustup-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-rustup-
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: |
target
key: ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-target-
- name: Install Rust (stable)
shell: bash
run: |
set -e
curl -fsSL https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
if ! command -v cargo >/dev/null 2>&1; then
curl -fsSL https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
fi
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- name: Debug workspace
@@ -33,17 +56,6 @@ jobs:
pwd
ls -la
- name: Cache Cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Read package name
id: pkg_meta
shell: bash
@@ -76,12 +88,13 @@ jobs:
REPO="${FULL##*/}"
VERSION="${GITHUB_REF_NAME#v}"
PKG_VERSION="${VERSION}"
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
mkdir -p dist
# Clean source snapshot of the repository at current commit
git archive --format=tar.gz \
--prefix="${REPO}-${PKG_VERSION}/" \
-o "dist/${REPO}-${PKG_VERSION}-source.tar.gz" \
--prefix="${BIN_NAME}-${PKG_VERSION}/" \
-o "dist/${BIN_NAME}-${PKG_VERSION}-source.tar.gz" \
HEAD
ls -lh dist
@@ -108,9 +121,9 @@ jobs:
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
mkdir -p dist
cp "target/release/${BIN_NAME}" "dist/${REPO}-${PKG_VERSION}-linux-x86_64"
cp "target/release/${BIN_NAME}" "dist/${BIN_NAME}-${PKG_VERSION}-linux-x86_64"
chmod +x "dist/${REPO}-${PKG_VERSION}-linux-x86_64"
chmod +x "dist/${BIN_NAME}-${PKG_VERSION}-linux-x86_64"
ls -lh dist
- name: Upload to Gitea Generic Packages
@@ -129,6 +142,7 @@ jobs:
REPO="${FULL##*/}"
VERSION="${GITHUB_REF_NAME#v}"
PKG_VERSION="${VERSION}"
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
if [ -z "${GITEA_BASE_URL:-}" ]; then
echo "Missing vars.GITEA_BASE_URL (example: https://gitea.example.com)"
@@ -139,8 +153,8 @@ jobs:
exit 1
fi
# Choose a package name (keep stable). Here: repo name.
PACKAGE_NAME="$REPO"
# Choose a package name (keep stable). Here: cargo package name.
PACKAGE_NAME="$BIN_NAME"
for FILE in dist/*; do
FILENAME="$(basename "$FILE")"