mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:19:59 +00:00
Merge pull request #37 from Magnus167/wkflow-update
Run workflows on self-hosted x86 and ARM runners
This commit is contained in:
commit
fc508bb1a9
61
.github/actions/runner-fallback/action.yml
vendored
Normal file
61
.github/actions/runner-fallback/action.yml
vendored
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# actions/runner-fallback/action.yml
|
||||||
|
name: "Runner Fallback"
|
||||||
|
description: |
|
||||||
|
Chooses a self-hosted runner when one with the required labels is online,
|
||||||
|
otherwise returns a fallback GitHub-hosted label.
|
||||||
|
inputs:
|
||||||
|
primary-runner:
|
||||||
|
description: 'Comma-separated label list for the preferred self-hosted runner (e.g. "self-hosted,linux")'
|
||||||
|
required: true
|
||||||
|
fallback-runner:
|
||||||
|
description: 'Comma-separated label list or single label for the fallback (e.g. "ubuntu-latest")'
|
||||||
|
required: true
|
||||||
|
github-token:
|
||||||
|
description: "PAT or GITHUB_TOKEN with `repo` scope"
|
||||||
|
required: true
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
use-runner:
|
||||||
|
description: "JSON array of labels you can feed straight into runs-on"
|
||||||
|
value: ${{ steps.pick.outputs.use-runner }}
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Check self-hosted fleet
|
||||||
|
id: pick
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ inputs.github-token }}
|
||||||
|
PRIMARY: ${{ inputs.primary-runner }}
|
||||||
|
FALLBACK: ${{ inputs.fallback-runner }}
|
||||||
|
run: |
|
||||||
|
# -------- helper -----------
|
||||||
|
to_json_array () {
|
||||||
|
local list="$1"; IFS=',' read -ra L <<<"$list"
|
||||||
|
printf '['; printf '"%s",' "${L[@]}"; printf ']'
|
||||||
|
}
|
||||||
|
# -------- query API ---------
|
||||||
|
repo="${{ github.repository }}"
|
||||||
|
runners=$(curl -s -H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
"https://api.github.com/repos/$repo/actions/runners?per_page=100")
|
||||||
|
# Split wanted labels
|
||||||
|
IFS=',' read -ra WANT <<<"$PRIMARY"
|
||||||
|
online_found=0
|
||||||
|
while read -r row; do
|
||||||
|
labels=$(jq -r '.labels[].name' <<<"$row")
|
||||||
|
ok=1
|
||||||
|
for w in "${WANT[@]}"; do
|
||||||
|
grep -Fxq "$w" <<<"$labels" || { ok=0; break; }
|
||||||
|
done
|
||||||
|
[ "$ok" -eq 1 ] && { online_found=1; break; }
|
||||||
|
done < <(jq -c '.runners[] | select(.status=="online")' <<<"$runners")
|
||||||
|
|
||||||
|
if [ "$online_found" -eq 1 ]; then
|
||||||
|
echo "✅ Self-hosted runner online."
|
||||||
|
echo "use-runner=$(to_json_array "$PRIMARY")" >>"$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "❌ No matching self-hosted runner online - using fallback."
|
||||||
|
echo "use-runner=$(to_json_array "$FALLBACK")" >>"$GITHUB_OUTPUT"
|
||||||
|
fi
|
30
.github/runners/runner-arm/Dockerfile
vendored
Normal file
30
.github/runners/runner-arm/Dockerfile
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
FROM ubuntu:latest
|
||||||
|
|
||||||
|
ARG RUNNER_VERSION="2.323.0"
|
||||||
|
|
||||||
|
# Prevents installdependencies.sh from prompting the user and blocking the image creation
|
||||||
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
RUN apt update -y && apt upgrade -y && useradd -m docker
|
||||||
|
RUN apt install -y --no-install-recommends \
|
||||||
|
curl jq build-essential libssl-dev libffi-dev python3 python3-venv python3-dev python3-pip \
|
||||||
|
# dot net core dependencies
|
||||||
|
libicu74 libssl3 libkrb5-3 zlib1g libcurl4
|
||||||
|
|
||||||
|
|
||||||
|
RUN cd /home/docker && mkdir actions-runner && cd actions-runner \
|
||||||
|
&& curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-arm64-${RUNNER_VERSION}.tar.gz \
|
||||||
|
&& tar xzf ./actions-runner-linux-arm64-${RUNNER_VERSION}.tar.gz
|
||||||
|
|
||||||
|
RUN chown -R docker ~docker && /home/docker/actions-runner/bin/installdependencies.sh
|
||||||
|
|
||||||
|
COPY entrypoint.sh entrypoint.sh
|
||||||
|
|
||||||
|
# make the script executable
|
||||||
|
RUN chmod +x entrypoint.sh
|
||||||
|
|
||||||
|
# since the config and run script for actions are not allowed to be run by root,
|
||||||
|
# set the user to "docker" so all subsequent commands are run as the docker user
|
||||||
|
USER docker
|
||||||
|
|
||||||
|
ENTRYPOINT ["./entrypoint.sh"]
|
18
.github/runners/runner-x64/docker-compose.yml
vendored
Normal file
18
.github/runners/runner-x64/docker-compose.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# docker-compose.yml
|
||||||
|
|
||||||
|
services:
|
||||||
|
github-runner:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
RUNNER_VERSION: 2.323.0
|
||||||
|
# container_name commented to allow for multiple runners
|
||||||
|
# container_name: github-runner
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- runner-work:/home/runner/actions-runner/_work
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
runner-work:
|
24
.github/runners/runner-x64/entrypoint.sh
vendored
Normal file
24
.github/runners/runner-x64/entrypoint.sh
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
REPOSITORY=$REPO
|
||||||
|
ACCESS_TOKEN=$GH_TOKEN
|
||||||
|
LABELS=$RUNNER_LABELS
|
||||||
|
|
||||||
|
# echo "REPO ${REPOSITORY}"
|
||||||
|
# echo "ACCESS_TOKEN ${ACCESS_TOKEN}"
|
||||||
|
|
||||||
|
REG_TOKEN=$(curl -X POST -H "Authorization: token ${ACCESS_TOKEN}" -H "Accept: application/vnd.github+json" https://api.github.com/repos/${REPOSITORY}/actions/runners/registration-token | jq .token --raw-output)
|
||||||
|
|
||||||
|
cd /home/docker/actions-runner
|
||||||
|
|
||||||
|
./config.sh --url https://github.com/${REPOSITORY} --token ${REG_TOKEN} --labels ${LABELS}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
echo "Removing runner..."
|
||||||
|
./config.sh remove --unattended --token ${REG_TOKEN}
|
||||||
|
}
|
||||||
|
|
||||||
|
trap 'cleanup; exit 130' INT
|
||||||
|
trap 'cleanup; exit 143' TERM
|
||||||
|
|
||||||
|
./run.sh & wait $!
|
9
.github/runners/runner-x64/example.env
vendored
Normal file
9
.github/runners/runner-x64/example.env
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
# Repository name
|
||||||
|
REPO="Magnus167/rustframe"
|
||||||
|
|
||||||
|
# GitHub runner token
|
||||||
|
GH_TOKEN="some_token_here"
|
||||||
|
|
||||||
|
# Labels for the runner
|
||||||
|
RUNNER_LABELS=self-hosted-linux,linux
|
4
.github/runners/runner-x64/start.sh
vendored
Normal file
4
.github/runners/runner-x64/start.sh
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
docker compose up -d --build
|
||||||
|
# docker compose up -d --build --scale github-runner=2
|
49
.github/workflows/docs-and-testcov.yml
vendored
49
.github/workflows/docs-and-testcov.yml
vendored
@ -17,8 +17,23 @@ permissions:
|
|||||||
pages: write
|
pages: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docs-and-testcov:
|
pick-runner:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
runner: ${{ steps.choose.outputs.use-runner }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- id: choose
|
||||||
|
uses: ./.github/actions/runner-fallback
|
||||||
|
with:
|
||||||
|
primary-runner: "self-hosted,ubuntu-latest"
|
||||||
|
fallback-runner: "ubuntu-latest"
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
docs-and-testcov:
|
||||||
|
needs: pick-runner
|
||||||
|
runs-on: ${{ fromJson(needs.pick-runner.outputs.runner) }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@ -28,10 +43,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: Build documentation
|
- name: Build documentation
|
||||||
run: cargo doc --no-deps --release
|
run: cargo doc --no-deps --release
|
||||||
|
|
||||||
- name: Prepare documentation for Pages
|
- name: Prepare documentation for Pages
|
||||||
run: |
|
run: |
|
||||||
|
|
||||||
@ -45,28 +60,26 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir -p testcov
|
mkdir -p testcov
|
||||||
cargo tarpaulin --engine llvm --out Html --out Json
|
cargo tarpaulin --engine llvm --out Html --out Json
|
||||||
|
|
||||||
- name: Check for tarpaulin-report.html
|
- name: Check for tarpaulin-report.html
|
||||||
run: |
|
run: |
|
||||||
if [ ! -f tarpaulin-report.html ]; then
|
if [ ! -f tarpaulin-report.html ]; then
|
||||||
echo "tarpaulin-report.html not found!"
|
echo "tarpaulin-report.html not found!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Export tarpaulin coverage badge JSON
|
- name: Export tarpaulin coverage badge JSON
|
||||||
|
# extract raw coverage and round to 2 decimal places
|
||||||
run: |
|
run: |
|
||||||
# extract raw coverage
|
coverage=$(jq '.coverage' tarpaulin-report.json)
|
||||||
coverage=$(jq '.coverage' tarpaulin-report.json)
|
formatted=$(printf "%.2f" "$coverage")
|
||||||
# round to 2 decimal places
|
jq --arg message "$formatted" \
|
||||||
formatted=$(printf "%.2f" "$coverage")
|
'{schemaVersion:1,
|
||||||
# build the badge JSON using the pre-formatted string
|
label:"tarpaulin-report",
|
||||||
jq --arg message "$formatted" \
|
message:$message,
|
||||||
'{schemaVersion:1,
|
color:"blue"}' \
|
||||||
label:"tarpaulin-report",
|
tarpaulin-report.json \
|
||||||
message:$message,
|
> tarpaulin-badge.json
|
||||||
color:"blue"}' \
|
|
||||||
tarpaulin-report.json \
|
|
||||||
> tarpaulin-badge.json
|
|
||||||
|
|
||||||
- name: Save last commit date JSON
|
- name: Save last commit date JSON
|
||||||
run: |
|
run: |
|
||||||
@ -78,7 +91,7 @@ jobs:
|
|||||||
color:"blue"}' \
|
color:"blue"}' \
|
||||||
<(echo '{}') \
|
<(echo '{}') \
|
||||||
> last-commit-date.json
|
> last-commit-date.json
|
||||||
|
|
||||||
- name: Copy files to output directory
|
- name: Copy files to output directory
|
||||||
run: |
|
run: |
|
||||||
mkdir output
|
mkdir output
|
||||||
|
26
.github/workflows/run-unit-tests.yml
vendored
26
.github/workflows/run-unit-tests.yml
vendored
@ -11,10 +11,24 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
pick-runner:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
runner: ${{ steps.choose.outputs.use-runner }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- id: choose
|
||||||
|
uses: ./.github/actions/runner-fallback
|
||||||
|
with:
|
||||||
|
primary-runner: "self-hosted,ubuntu-latest"
|
||||||
|
fallback-runner: "ubuntu-latest"
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
run-unit-tests:
|
run-unit-tests:
|
||||||
|
needs: pick-runner
|
||||||
if: github.event.pull_request.draft == false
|
if: github.event.pull_request.draft == false
|
||||||
name: run-unit-tests
|
name: run-unit-tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ fromJson(needs.pick-runner.outputs.runner) }}
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
@ -24,12 +38,16 @@ jobs:
|
|||||||
run: rustup update stable
|
run: rustup update stable
|
||||||
- name: Install cargo-llvm-cov
|
- name: Install cargo-llvm-cov
|
||||||
uses: taiki-e/install-action@cargo-llvm-cov
|
uses: taiki-e/install-action@cargo-llvm-cov
|
||||||
- name: Generate code coverage
|
|
||||||
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
|
- name: Run doctests
|
||||||
- name: Run doc-tests
|
|
||||||
run: cargo test --doc --all-features --workspace --release
|
run: cargo test --doc --all-features --workspace --release
|
||||||
|
|
||||||
|
- name: Run unit tests with code coverage
|
||||||
|
run: cargo llvm-cov --all-features --release --workspace --lcov --output-path lcov.info
|
||||||
|
|
||||||
- name: Test docs generation
|
- name: Test docs generation
|
||||||
run: cargo doc --no-deps --release
|
run: cargo doc --no-deps --release
|
||||||
|
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v3
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user