refactor: improve caching and installation steps in build workflow
This commit is contained in:
@@ -19,11 +19,34 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
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)
|
- name: Install Rust (stable)
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -e
|
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"
|
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
- name: Debug workspace
|
- name: Debug workspace
|
||||||
@@ -33,17 +56,6 @@ jobs:
|
|||||||
pwd
|
pwd
|
||||||
ls -la
|
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
|
- name: Read package name
|
||||||
id: pkg_meta
|
id: pkg_meta
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -76,12 +88,13 @@ jobs:
|
|||||||
REPO="${FULL##*/}"
|
REPO="${FULL##*/}"
|
||||||
VERSION="${GITHUB_REF_NAME#v}"
|
VERSION="${GITHUB_REF_NAME#v}"
|
||||||
PKG_VERSION="${VERSION}"
|
PKG_VERSION="${VERSION}"
|
||||||
|
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
||||||
|
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
# Clean source snapshot of the repository at current commit
|
# Clean source snapshot of the repository at current commit
|
||||||
git archive --format=tar.gz \
|
git archive --format=tar.gz \
|
||||||
--prefix="${REPO}-${PKG_VERSION}/" \
|
--prefix="${BIN_NAME}-${PKG_VERSION}/" \
|
||||||
-o "dist/${REPO}-${PKG_VERSION}-source.tar.gz" \
|
-o "dist/${BIN_NAME}-${PKG_VERSION}-source.tar.gz" \
|
||||||
HEAD
|
HEAD
|
||||||
|
|
||||||
ls -lh dist
|
ls -lh dist
|
||||||
@@ -108,9 +121,9 @@ jobs:
|
|||||||
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
||||||
|
|
||||||
mkdir -p dist
|
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
|
ls -lh dist
|
||||||
|
|
||||||
- name: Upload to Gitea Generic Packages
|
- name: Upload to Gitea Generic Packages
|
||||||
@@ -129,6 +142,7 @@ jobs:
|
|||||||
REPO="${FULL##*/}"
|
REPO="${FULL##*/}"
|
||||||
VERSION="${GITHUB_REF_NAME#v}"
|
VERSION="${GITHUB_REF_NAME#v}"
|
||||||
PKG_VERSION="${VERSION}"
|
PKG_VERSION="${VERSION}"
|
||||||
|
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
||||||
|
|
||||||
if [ -z "${GITEA_BASE_URL:-}" ]; then
|
if [ -z "${GITEA_BASE_URL:-}" ]; then
|
||||||
echo "Missing vars.GITEA_BASE_URL (example: https://gitea.example.com)"
|
echo "Missing vars.GITEA_BASE_URL (example: https://gitea.example.com)"
|
||||||
@@ -139,8 +153,8 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Choose a package name (keep stable). Here: repo name.
|
# Choose a package name (keep stable). Here: cargo package name.
|
||||||
PACKAGE_NAME="$REPO"
|
PACKAGE_NAME="$BIN_NAME"
|
||||||
|
|
||||||
for FILE in dist/*; do
|
for FILE in dist/*; do
|
||||||
FILENAME="$(basename "$FILE")"
|
FILENAME="$(basename "$FILE")"
|
||||||
|
|||||||
Reference in New Issue
Block a user