mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 05:16:44 +08:00
+85
-69
@@ -1,7 +1,6 @@
|
|||||||
# Gitea Actions workflow for the Rust workspace.
|
# Gitea Actions workflow for the Rust workspace.
|
||||||
# This workflow is linux-runner friendly and does not touch real resource
|
# Self-hosted runner friendly.
|
||||||
# directories. It intentionally avoids external GitHub Actions so self-hosted
|
# Does not use external GitHub Actions.
|
||||||
# runners do not need to clone action repositories through a network proxy.
|
|
||||||
|
|
||||||
name: bat-rust
|
name: bat-rust
|
||||||
|
|
||||||
@@ -16,132 +15,149 @@ jobs:
|
|||||||
rust:
|
rust:
|
||||||
name: Build and test Rust
|
name: Build and test Rust
|
||||||
runs-on: linux
|
runs-on: linux
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
RUST_BACKTRACE: 1
|
RUST_BACKTRACE: 1
|
||||||
BAT_SKIP_ENV_FILE: "1"
|
BAT_SKIP_ENV_FILE: "1"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Load Runner Environment
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
source /var/lib/act_runner/env.sh
|
|
||||||
rustc --version
|
|
||||||
cargo --version
|
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
: "${GITHUB_SERVER_URL:?GITHUB_SERVER_URL is required}"
|
: "${GITHUB_SERVER_URL:?GITHUB_SERVER_URL is required}"
|
||||||
: "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}"
|
: "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}"
|
||||||
: "${GITHUB_SHA:?GITHUB_SHA is required}"
|
: "${GITHUB_SHA:?GITHUB_SHA is required}"
|
||||||
|
|
||||||
repo_url="${GITHUB_SERVER_URL%/}/${GITHUB_REPOSITORY}.git"
|
repo_url="${GITHUB_SERVER_URL%/}/${GITHUB_REPOSITORY}.git"
|
||||||
|
|
||||||
if [ -d .git ]; then
|
if [ -d .git ]; then
|
||||||
git remote set-url origin "${repo_url}" 2>/dev/null || git remote add origin "${repo_url}"
|
git remote set-url origin "${repo_url}"
|
||||||
else
|
else
|
||||||
git init .
|
git init .
|
||||||
git remote add origin "${repo_url}"
|
git remote add origin "${repo_url}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ref="${GITHUB_REF:-${GITHUB_SHA}}"
|
ref="${GITHUB_REF:-${GITHUB_SHA}}"
|
||||||
git fetch --no-tags --depth=1 origin "${ref}" || git fetch --no-tags --depth=1 origin "${GITHUB_SHA}"
|
|
||||||
|
git fetch \
|
||||||
|
--no-tags \
|
||||||
|
--depth=1 \
|
||||||
|
origin \
|
||||||
|
"${ref}" \
|
||||||
|
|| git fetch \
|
||||||
|
--no-tags \
|
||||||
|
--depth=1 \
|
||||||
|
origin \
|
||||||
|
"${GITHUB_SHA}"
|
||||||
|
|
||||||
git checkout --force --detach FETCH_HEAD
|
git checkout --force --detach FETCH_HEAD
|
||||||
|
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
|
|
||||||
|
|
||||||
- name: Show tool versions
|
- name: Show tool versions
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
source /var/lib/act_runner/env.sh
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
source /var/lib/act_runner/env.sh
|
||||||
|
|
||||||
command -v git
|
command -v git
|
||||||
|
command -v rustc
|
||||||
|
command -v cargo
|
||||||
|
|
||||||
rustc --version
|
rustc --version
|
||||||
cargo --version
|
cargo --version
|
||||||
rustfmt --version
|
rustfmt --version
|
||||||
cargo clippy --version
|
cargo clippy --version
|
||||||
|
|
||||||
|
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
shell: bash
|
shell: bash
|
||||||
run: source /var/lib/act_runner/env.sh && cargo fmt --all -- --check
|
run: |
|
||||||
|
source /var/lib/act_runner/env.sh
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
|
|
||||||
- name: Check workspace
|
- name: Check workspace
|
||||||
shell: bash
|
shell: bash
|
||||||
run: source /var/lib/act_runner/env.sh && cargo check --workspace --locked
|
run: |
|
||||||
|
source /var/lib/act_runner/env.sh
|
||||||
|
cargo check --workspace --locked
|
||||||
|
|
||||||
|
|
||||||
- name: Build workspace
|
- name: Build workspace
|
||||||
shell: bash
|
shell: bash
|
||||||
run: source /var/lib/act_runner/env.sh && cargo build --workspace --release --locked
|
run: |
|
||||||
|
source /var/lib/act_runner/env.sh
|
||||||
|
|
||||||
|
cargo build \
|
||||||
|
--workspace \
|
||||||
|
--release \
|
||||||
|
--locked
|
||||||
|
|
||||||
|
|
||||||
- name: Run clippy
|
- name: Run clippy
|
||||||
shell: bash
|
shell: bash
|
||||||
run: source /var/lib/act_runner/env.sh && cargo clippy --workspace --all-targets --locked -- -D warnings
|
run: |
|
||||||
|
source /var/lib/act_runner/env.sh
|
||||||
|
|
||||||
|
cargo clippy \
|
||||||
|
--workspace \
|
||||||
|
--all-targets \
|
||||||
|
--locked \
|
||||||
|
-- -D warnings
|
||||||
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
shell: bash
|
shell: bash
|
||||||
run: source /var/lib/act_runner/env.sh && cargo test --workspace --locked
|
run: |
|
||||||
|
source /var/lib/act_runner/env.sh
|
||||||
|
|
||||||
|
cargo test \
|
||||||
|
--workspace \
|
||||||
|
--locked
|
||||||
|
|
||||||
|
|
||||||
- name: Package binary
|
- name: Package binary
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
mkdir -p artifact
|
|
||||||
cp target/release/bat artifact/
|
|
||||||
tar -czf bat-linux-x86_64.tar.gz -C artifact bat
|
|
||||||
sha256sum bat-linux-x86_64.tar.gz > bat-linux-x86_64.sha256
|
|
||||||
|
|
||||||
- name: Upload artifact
|
mkdir -p artifact
|
||||||
|
|
||||||
|
cp target/release/bat artifact/
|
||||||
|
|
||||||
|
tar \
|
||||||
|
-czf \
|
||||||
|
bat-linux-x86_64.tar.gz \
|
||||||
|
-C artifact \
|
||||||
|
bat
|
||||||
|
|
||||||
|
sha256sum \
|
||||||
|
bat-linux-x86_64.tar.gz \
|
||||||
|
> bat-linux-x86_64.sha256
|
||||||
|
|
||||||
|
|
||||||
|
- name: Prepare artifact
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
ARTIFACT_NAME: bat-linux-x86_64
|
|
||||||
ARTIFACT_PATH: |
|
|
||||||
bat-linux-x86_64.tar.gz
|
|
||||||
bat-linux-x86_64.sha256
|
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
: "${ACTIONS_RUNTIME_URL:?missing ACTIONS_RUNTIME_URL}"
|
mkdir upload
|
||||||
: "${ACTIONS_RUNTIME_TOKEN:?missing ACTIONS_RUNTIME_TOKEN}"
|
|
||||||
|
|
||||||
ARTIFACT_ID=$(curl \
|
cp bat-linux-x86_64.tar.gz upload/
|
||||||
-sS \
|
cp bat-linux-x86_64.sha256 upload/
|
||||||
-X POST \
|
|
||||||
"${ACTIONS_RUNTIME_URL}/_apis/artifactcache/artifacts" \
|
|
||||||
-H "Authorization: Bearer ${ACTIONS_RUNTIME_TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{
|
|
||||||
\"type\": \"actions_storage\",
|
|
||||||
\"name\": \"${ARTIFACT_NAME}\"
|
|
||||||
}" \
|
|
||||||
| python3 -c '
|
|
||||||
import sys,json
|
|
||||||
print(json.load(sys.stdin)["artifactId"])
|
|
||||||
')
|
|
||||||
|
|
||||||
echo "Artifact ID: ${ARTIFACT_ID}"
|
cd upload
|
||||||
|
|
||||||
ZIP_FILE="${ARTIFACT_NAME}.zip"
|
zip -q \
|
||||||
|
../bat-linux-x86_64.zip \
|
||||||
|
*
|
||||||
|
|
||||||
zip -q "${ZIP_FILE}" ${ARTIFACT_PATH}
|
cd ..
|
||||||
|
|
||||||
SIZE=$(stat -c%s "${ZIP_FILE}")
|
ls -lh bat-linux-x86_64.zip
|
||||||
|
|
||||||
curl \
|
|
||||||
-sS \
|
|
||||||
-X PATCH \
|
|
||||||
"${ACTIONS_RUNTIME_URL}/_apis/artifactcache/artifacts/${ARTIFACT_ID}" \
|
|
||||||
-H "Authorization: Bearer ${ACTIONS_RUNTIME_TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
--data-binary "@${ZIP_FILE}"
|
|
||||||
|
|
||||||
|
|
||||||
curl \
|
|
||||||
-sS \
|
|
||||||
-X POST \
|
|
||||||
"${ACTIONS_RUNTIME_URL}/_apis/artifactcache/artifacts/${ARTIFACT_ID}" \
|
|
||||||
-H "Authorization: Bearer ${ACTIONS_RUNTIME_TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{
|
|
||||||
\"size\": ${SIZE}
|
|
||||||
}"
|
|
||||||
|
|
||||||
echo "Artifact uploaded: ${ARTIFACT_NAME}"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user