Skip to content

Commit 180879a

Browse files
Sync 42 files: actions community scripts tools workflows
Source commits from TheKrush/.github-admin (watched paths): - testing public profile
1 parent b7f7616 commit 180879a

42 files changed

Lines changed: 3052 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: 🧱 Build .NET Project
2+
description: Detects and builds a .NET solution or project.
3+
4+
inputs:
5+
# Preferred: explicit project path (e.g. MyBot/MyBot.csproj)
6+
project:
7+
description: "Resolved .csproj path to build"
8+
required: false
9+
default: ""
10+
11+
# Fallback glob if 'project' is not provided
12+
project_pattern:
13+
description: "Glob used to find the project if 'project' is empty"
14+
required: false
15+
default: "*.csproj"
16+
17+
configuration:
18+
description: "Build configuration to use (Debug/Release)"
19+
required: false
20+
default: "Release"
21+
22+
verbosity:
23+
description: "Verbosity for dotnet build"
24+
required: false
25+
default: "minimal"
26+
27+
gh-token:
28+
required: true
29+
30+
outputs:
31+
project:
32+
value: ${{ steps.build.outputs.project }}
33+
34+
runs:
35+
using: "composite"
36+
steps:
37+
- name: 🔑 Export GitHub Token
38+
shell: bash
39+
run: |
40+
if [ -n "${{ inputs.gh-token }}" ]; then
41+
echo "Setting GH_TOKEN and GITHUB_TOKEN from input..."
42+
echo "GH_TOKEN=${{ inputs.gh-token }}" >> "$GITHUB_ENV"
43+
echo "GITHUB_TOKEN=${{ inputs.gh-token }}" >> "$GITHUB_ENV"
44+
else
45+
echo "No gh-token input provided, leaving existing GH_TOKEN/GITHUB_TOKEN unchanged."
46+
fi
47+
48+
- id: build
49+
shell: bash
50+
run: |
51+
# Prefer explicit project; fall back to pattern
52+
project_input='${{ inputs.project }}'
53+
pattern_input='${{ inputs.project_pattern }}'
54+
configuration_input='${{ inputs.configuration }}'
55+
verbosity_input='${{ inputs.verbosity }}'
56+
57+
# If the caller passed empty strings (e.g. workflow push with no inputs),
58+
# fall back to our own defaults.
59+
if [ -z "$pattern_input" ]; then
60+
pattern_input="*.csproj"
61+
fi
62+
63+
if [ -z "$configuration_input" ]; then
64+
configuration_input="Release"
65+
fi
66+
67+
if [ -z "$verbosity_input" ]; then
68+
verbosity_input="minimal"
69+
fi
70+
71+
if [ -n "$project_input" ]; then
72+
echo "🔧 Using explicit project: $project_input"
73+
if [ ! -f "$project_input" ]; then
74+
echo "❌ Explicit project does not exist: $project_input"
75+
exit 1
76+
fi
77+
PROJECT="$project_input"
78+
else
79+
echo "🔍 Searching for pattern: $pattern_input"
80+
PROJECT=$(find . -type f -name "$pattern_input" -print | head -n 1)
81+
if [ -z "$PROJECT" ]; then
82+
echo "❌ No project found matching pattern: $pattern_input"
83+
exit 1
84+
fi
85+
fi
86+
87+
echo "project=$PROJECT" >> "$GITHUB_OUTPUT"
88+
echo "PROJECT=$PROJECT" >> "$GITHUB_ENV"
89+
echo "📦 Found project: $PROJECT"
90+
91+
dotnet restore "$PROJECT" --verbosity quiet
92+
dotnet build "$PROJECT" \
93+
-c "$configuration_input" \
94+
--no-restore \
95+
--nologo \
96+
--verbosity "$verbosity_input"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: 🔢 Bump Version
2+
description: Determines the next semantic version (major/minor/patch) by inspecting git tags.
3+
4+
inputs:
5+
bump:
6+
description: "Version bump type (major, minor, patch)"
7+
default: "patch"
8+
9+
outputs:
10+
version:
11+
description: "The computed semantic version (without 'v' prefix)"
12+
value: ${{ steps.bump.outputs.version }}
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- id: bump
18+
shell: bash
19+
env:
20+
INPUT_BUMP: ${{ inputs.bump }}
21+
run: |
22+
set -euo pipefail
23+
24+
git fetch --tags --quiet || true
25+
26+
echo "Tags in repo:"
27+
git tag --sort=-creatordate || echo "(none)"
28+
echo
29+
30+
LATEST=$(git tag | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1 || echo "")
31+
echo "LATEST detected tag: '${LATEST}'"
32+
33+
if [[ -z "$LATEST" ]]; then
34+
echo "No existing tags found. Starting at v1.0.0"
35+
VERSION="1.0.0"
36+
else
37+
BASE=${LATEST#v}
38+
BASE=${BASE:-$LATEST}
39+
echo "Normalized base version: '${BASE}'"
40+
41+
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE"
42+
MAJOR=${MAJOR:-0}
43+
MINOR=${MINOR:-0}
44+
PATCH=${PATCH:-0}
45+
46+
bump="${INPUT_BUMP:-patch}"
47+
echo "Bump type: '${bump}'"
48+
49+
case "$bump" in
50+
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
51+
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
52+
patch|*) PATCH=$((PATCH + 1)) ;;
53+
esac
54+
55+
VERSION="$MAJOR.$MINOR.$PATCH"
56+
fi
57+
58+
echo
59+
echo "Final computed version: $VERSION"
60+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: "Check GitHub Org Usage"
2+
description: "Checks GitHub Actions minutes and Packages bandwidth for the authenticated organization."
3+
4+
inputs:
5+
gh-token:
6+
description: "GitHub token with billing read access"
7+
required: true
8+
org-name:
9+
description: "Organization name (used only for package bandwidth check)"
10+
required: false
11+
default: "LostMinions"
12+
check-actions:
13+
description: "Run the Actions usage check"
14+
default: "true"
15+
check-packages-bandwidth:
16+
description: "Run the Packages bandwidth check"
17+
default: "false"
18+
actions-limit:
19+
description: "Actions usage limit (minutes)"
20+
default: "2000"
21+
packages-bandwidth-limit:
22+
description: "Packages bandwidth limit (GB)"
23+
default: "1.0"
24+
margin:
25+
description: "Margin percentage before stopping job"
26+
default: "5"
27+
28+
outputs:
29+
over_limit:
30+
description: "True if any usage is near or over the configured limit"
31+
value: ${{ steps.check.outputs.over_limit }}
32+
33+
runs:
34+
using: "composite"
35+
steps:
36+
- name: 🔍 Check Org Usage
37+
id: check
38+
shell: bash
39+
env:
40+
GH_TOKEN: ${{ inputs.gh-token }}
41+
ORG_NAME: ${{ inputs.org-name }}
42+
ACTIONS_LIMIT: ${{ inputs.actions-limit }}
43+
PKG_BANDWIDTH_LIMIT: ${{ inputs.packages-bandwidth-limit }}
44+
MARGIN: ${{ inputs.margin }}
45+
RUN_ACTIONS: ${{ inputs.check-actions }}
46+
RUN_BANDWIDTH: ${{ inputs.check-packages-bandwidth }}
47+
run: |
48+
#!/usr/bin/env bash
49+
# ------------------------------------------------------------
50+
# LostMinions --- GitHub Org Usage Check (Composite Action)
51+
# ------------------------------------------------------------
52+
53+
set -euo pipefail
54+
55+
ORG="${ORG_NAME:-LostMinions}"
56+
TOKEN="${GH_TOKEN:?Missing GH_TOKEN}"
57+
58+
ACTIONS_LIMIT="${ACTIONS_LIMIT:-2000}" # minutes
59+
BANDWIDTH_LIMIT="${PKG_BANDWIDTH_LIMIT:-1.0}" # GB
60+
MARGIN="${MARGIN:-5}" # %
61+
62+
CHECK_ACTIONS=false
63+
CHECK_BANDWIDTH=false
64+
[[ "${RUN_ACTIONS,,}" == "true" ]] && CHECK_ACTIONS=true
65+
[[ "${RUN_BANDWIDTH,,}" == "true" ]] && CHECK_BANDWIDTH=true
66+
67+
API="https://api.github.com/organizations/${ORG}/settings/billing/usage/summary"
68+
69+
safe_cmp() { awk "BEGIN {print ($1) ? 1 : 0}" 2>/dev/null || echo 0; }
70+
71+
# --- Function: Check Actions minutes ---------------------------------------
72+
check_actions() {
73+
set -o pipefail
74+
local mode_tag
75+
if $CHECK_ACTIONS; then mode_tag="(enforced)"; else mode_tag="(info-only)"; fi
76+
77+
echo "Checking Actions usage for $ORG $mode_tag"
78+
resp=$(curl -s -L -H "Accept: application/vnd.github+json" \
79+
-H "Authorization: Bearer ${TOKEN}" "$API" || true)
80+
USED=$(echo "$resp" | jq '[.usageItems[] | select(.sku | test("^actions_(linux|windows|macos)$")) | .grossQuantity] | add // 0')
81+
82+
if [[ -z "$USED" || "$USED" == "null" ]]; then
83+
echo "Could not determine Actions usage (missing data)."
84+
$CHECK_ACTIONS && return 1 || return 0
85+
fi
86+
87+
PCT=$(awk -v u="$USED" -v l="$ACTIONS_LIMIT" 'BEGIN { if (l<=0) print 0; else printf "%.1f", (u/l)*100 }')
88+
THRESHOLD=$(awk -v l="$ACTIONS_LIMIT" -v m="$MARGIN" 'BEGIN { printf "%.0f", l * (1 - m/100) }')
89+
90+
echo "* Actions: ${USED} / ${ACTIONS_LIMIT} minutes (${PCT}%)"
91+
echo "* Threshold for stop: ${THRESHOLD} minutes (${MARGIN}% margin)"
92+
93+
if [[ "$(safe_cmp "$USED >= $THRESHOLD")" == "1" ]]; then
94+
echo "⚠️ Actions usage near or over limit."
95+
$CHECK_ACTIONS && return 1 || return 0
96+
else
97+
echo "✅ Actions usage OK."
98+
return 0
99+
fi
100+
}
101+
102+
# --- Function: Check Packages bandwidth ------------------------------------
103+
check_packages_bandwidth() {
104+
set -o pipefail
105+
local mode_tag
106+
if $CHECK_BANDWIDTH; then mode_tag="(enforced)"; else mode_tag="(info-only)"; fi
107+
108+
echo "Checking Packages bandwidth for $ORG $mode_tag"
109+
resp=$(curl -s -L -H "Accept: application/vnd.github+json" \
110+
-H "Authorization: Bearer ${TOKEN}" \
111+
-H "X-GitHub-Api-Version: 2022-11-28" "$API" || true)
112+
bandwidth_used=$(echo "$resp" | jq -r '.usageItems[] | select(.sku=="packages_bandwidth") | .grossQuantity')
113+
[[ -z "$bandwidth_used" || "$bandwidth_used" == "null" ]] && bandwidth_used=0
114+
115+
limit_adj=$(awk "BEGIN {print $BANDWIDTH_LIMIT * (1 - $MARGIN / 100)}")
116+
117+
printf "* Bandwidth: %.2f GB / Limit: %.2f GB\n" "$bandwidth_used" "$BANDWIDTH_LIMIT"
118+
printf "* Threshold for stop: %.3f GB (%s%% margin)\n" "$limit_adj" "$MARGIN"
119+
120+
if [[ "$(safe_cmp "$bandwidth_used > $limit_adj")" == "1" ]]; then
121+
echo "⚠️ Packages bandwidth near or over limit."
122+
$CHECK_BANDWIDTH && return 1 || return 0
123+
else
124+
echo "✅ Packages bandwidth OK."
125+
return 0
126+
fi
127+
}
128+
129+
# --- Run checks and aggregate exit codes ----------------------------------
130+
FAIL=0
131+
check_actions || FAIL=1
132+
echo ""
133+
check_packages_bandwidth || FAIL=1
134+
echo ""
135+
136+
# --- Final status ----------------------------------------------------------
137+
if [[ "$FAIL" -eq 1 ]]; then
138+
echo "⚠️ One or more usage checks exceeded safe limits."
139+
echo "over_limit=true" >> "$GITHUB_OUTPUT"
140+
else
141+
echo "✅ All usage within safe limits."
142+
echo "over_limit=false" >> "$GITHUB_OUTPUT"
143+
fi
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "Cleanup Runner Workspace"
2+
description: "Safely removes job checkouts and stale self-hosted data without breaking GitHub's post-job cleanup."
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: 🧹 Cleanup workspace
8+
if: always()
9+
shell: bash
10+
run: |
11+
echo "🧹 Cleaning up current job workspace: ${{ github.workspace }}"
12+
13+
# ---------------------------------------------------------------
14+
# 🧽 Remove contents of the current workspace (safe delete only)
15+
# ---------------------------------------------------------------
16+
if [ -d "${{ github.workspace }}" ]; then
17+
echo "Cleaning non-action files only..."
18+
find "${{ github.workspace }}" -mindepth 1 -maxdepth 1 \
19+
! -path "${{ github.workspace }}/.github" \
20+
-exec rm -rf {} + 2>/dev/null || true
21+
fi
22+
23+
# ---------------------------------------------------------------------
24+
# 🧩 Detect correct runner base (actions-runner-01, -02, etc.)
25+
# ---------------------------------------------------------------------
26+
BASE_DIR="$GITHUB_WORKSPACE"
27+
# climb until we find a folder literally named "_work"
28+
while [[ "$BASE_DIR" != "/" && "$(basename "$BASE_DIR")" != "_work" ]]; do
29+
BASE_DIR="$(dirname "$BASE_DIR")"
30+
done
31+
32+
# one level up = runner root
33+
BASE_DIR="$(dirname "$BASE_DIR")"
34+
35+
if [[ -d "$BASE_DIR/_diag" ]]; then
36+
echo "Detected runner base: $BASE_DIR"
37+
else
38+
echo "⚠️ Could not detect runner base from $GITHUB_WORKSPACE"
39+
BASE_DIR="/home/runner/actions-runner"
40+
fi
41+
42+
# ---------------------------------------------------------------
43+
# 🧹 Prune old diagnostics safely (outside the workspace)
44+
# ---------------------------------------------------------------
45+
if [[ "$RUNNER_NAME" != "" && "$RUNNER_NAME" != "GitHub Actions" ]]; then
46+
echo "Pruning old diagnostics (>7 days)..."
47+
find "$BASE_DIR/_diag" -type f -mtime +7 -delete 2>/dev/null || true
48+
49+
echo ""
50+
echo "📊 Post-cleanup disk usage summary (as of $(date)):"
51+
if [[ -d "$BASE_DIR/_work" ]]; then
52+
sudo du -h --max-depth=1 "$BASE_DIR/_work" | sort -hr | grep -v "/_work$" | head || true
53+
echo ""
54+
echo "🪶 Top 5 largest directories under _work:"
55+
sudo du -h --max-depth=2 "$BASE_DIR/_work" | sort -hr | grep -v "/_work$" | head -n 5 || true
56+
else
57+
echo "⚠️ No _work directory found under $BASE_DIR"
58+
fi
59+
fi
60+
61+
echo "Cleanup complete ✔️"

0 commit comments

Comments
 (0)