Skip to content

Commit 34d21fa

Browse files
committed
Initial import of project
0 parents  commit 34d21fa

File tree

19 files changed

+2254
-0
lines changed

19 files changed

+2254
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Cache Cleanup
2+
3+
on:
4+
schedule:
5+
# Run every Sunday at 2 AM UTC
6+
- cron: "0 2 * * 0"
7+
workflow_dispatch:
8+
inputs:
9+
max_age_days:
10+
description: "Maximum age of caches to keep (in days)"
11+
required: false
12+
default: "30"
13+
type: string
14+
15+
jobs:
16+
cleanup:
17+
name: Clean up old caches
18+
runs-on: ubuntu-latest
19+
permissions:
20+
actions: write
21+
contents: read
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Get cache cleanup parameters
28+
id: params
29+
run: |
30+
MAX_AGE_DAYS="${{ github.event.inputs.max_age_days || '30' }}"
31+
echo "max_age_days=${MAX_AGE_DAYS}" >> $GITHUB_OUTPUT
32+
echo "cleanup_date=$(date -d "${MAX_AGE_DAYS} days ago" '+%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
33+
34+
- name: List current caches
35+
run: |
36+
echo "Current caches in repository:"
37+
gh api \
38+
-H "Accept: application/vnd.github+json" \
39+
-H "X-GitHub-Api-Version: 2022-11-28" \
40+
"/repos/${{ github.repository }}/actions/caches" \
41+
--jq '.actions_caches[] | "\(.key) - \(.size_in_bytes) bytes - \(.created_at)"'
42+
env:
43+
GH_TOKEN: ${{ github.token }}
44+
45+
- name: Clean up old caches
46+
run: |
47+
echo "Cleaning up caches older than ${{ steps.params.outputs.cleanup_date }}"
48+
49+
# Get list of cache IDs older than specified date
50+
CLEANUP_DATE="${{ steps.params.outputs.cleanup_date }}"
51+
CACHE_IDS=$(gh api \
52+
-H "Accept: application/vnd.github+json" \
53+
-H "X-GitHub-Api-Version: 2022-11-28" \
54+
"/repos/${{ github.repository }}/actions/caches" \
55+
--jq --arg cleanup_date "$CLEANUP_DATE" '.actions_caches[] | select(.created_at < $cleanup_date) | .id')
56+
57+
if [ -z "$CACHE_IDS" ]; then
58+
echo "No old caches found to clean up"
59+
exit 0
60+
fi
61+
62+
echo "Found caches to delete:"
63+
echo "$CACHE_IDS"
64+
65+
# Delete each cache
66+
for cache_id in $CACHE_IDS; do
67+
echo "Deleting cache ID: $cache_id"
68+
gh api \
69+
-X DELETE \
70+
-H "Accept: application/vnd.github+json" \
71+
-H "X-GitHub-Api-Version: 2022-11-28" \
72+
"/repos/${{ github.repository }}/actions/caches/$cache_id" || true
73+
done
74+
env:
75+
GH_TOKEN: ${{ github.token }}
76+
77+
- name: Clean up caches from deleted branches
78+
run: |
79+
echo "Cleaning up caches from non-existent branches"
80+
81+
# Get all remote branches
82+
git fetch --all
83+
EXISTING_BRANCHES=$(git branch -r | sed 's/origin\///' | grep -v HEAD | tr -d ' ')
84+
85+
# Get all cache keys
86+
CACHE_KEYS=$(gh api \
87+
-H "Accept: application/vnd.github+json" \
88+
-H "X-GitHub-Api-Version: 2022-11-28" \
89+
"/repos/${{ github.repository }}/actions/caches" \
90+
--jq '.actions_caches[] | .key')
91+
92+
# Find caches that might be from deleted branches
93+
for cache_key in $CACHE_KEYS; do
94+
# Extract potential branch name from cache key (this is heuristic)
95+
# Cache keys often contain branch names or refs
96+
if [[ "$cache_key" == *"refs/heads/"* ]]; then
97+
BRANCH_IN_KEY=$(echo "$cache_key" | sed -n 's/.*refs\/heads\/\([^-]*\).*/\1/p')
98+
if [ -n "$BRANCH_IN_KEY" ] && ! echo "$EXISTING_BRANCHES" | grep -q "^$BRANCH_IN_KEY$"; then
99+
echo "Found cache from potentially deleted branch: $cache_key (branch: $BRANCH_IN_KEY)"
100+
101+
# Get cache ID and delete
102+
CACHE_ID=$(gh api \
103+
-H "Accept: application/vnd.github+json" \
104+
-H "X-GitHub-Api-Version: 2022-11-28" \
105+
"/repos/${{ github.repository }}/actions/caches" \
106+
--jq --arg key "$cache_key" \
107+
'.actions_caches[] | select(.key == $key) | .id')
108+
109+
if [ -n "$CACHE_ID" ]; then
110+
echo "Deleting cache ID: $CACHE_ID"
111+
gh api \
112+
-X DELETE \
113+
-H "Accept: application/vnd.github+json" \
114+
-H "X-GitHub-Api-Version: 2022-11-28" \
115+
"/repos/${{ github.repository }}/actions/caches/$CACHE_ID" || true
116+
fi
117+
fi
118+
fi
119+
done
120+
env:
121+
GH_TOKEN: ${{ github.token }}
122+
123+
- name: Show cache statistics after cleanup
124+
run: |
125+
echo "Cache statistics after cleanup:"
126+
CACHE_INFO=$(gh api \
127+
-H "Accept: application/vnd.github+json" \
128+
-H "X-GitHub-Api-Version: 2022-11-28" \
129+
"/repos/${{ github.repository }}/actions/caches")
130+
131+
CACHE_COUNT=$(echo "$CACHE_INFO" | jq '.actions_caches | length')
132+
TOTAL_SIZE=$(echo "$CACHE_INFO" | jq '.actions_caches | map(.size_in_bytes) | add // 0')
133+
TOTAL_SIZE_MB=$((TOTAL_SIZE / 1024 / 1024))
134+
135+
echo "Total caches: $CACHE_COUNT"
136+
echo "Total size: ${TOTAL_SIZE_MB} MB"
137+
echo "Remaining caches:"
138+
echo "$CACHE_INFO" | jq '.actions_caches[] | "\(.key) - \(.size_in_bytes) bytes - \(.created_at)"'
139+
env:
140+
GH_TOKEN: ${{ github.token }}

.github/workflows/ci.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- name: "macOS Universal"
20+
runner: macos-15
21+
platform: "macOS"
22+
xcode: "16.4"
23+
arch: "universal"
24+
comprehensive_test: true
25+
lint_check: true
26+
- name: "Linux x86_64"
27+
runner: ubuntu-latest
28+
platform: "Linux"
29+
arch: "x86_64"
30+
triple: "x86_64-unknown-linux-gnu"
31+
comprehensive_test: true
32+
lint_check: true
33+
- name: "Linux ARM64"
34+
runner: ubuntu-24.04-arm
35+
platform: "Linux"
36+
arch: "aarch64"
37+
triple: "aarch64-unknown-linux-gnu"
38+
comprehensive_test: true
39+
lint_check: true
40+
41+
runs-on: ${{ matrix.runner }}
42+
name: ${{ matrix.name }}
43+
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Xcode
49+
if: matrix.platform == 'macOS'
50+
uses: maxim-lobanov/setup-xcode@v1
51+
with:
52+
xcode-version: ${{ matrix.xcode }}
53+
54+
- name: Setup Swift (Linux only)
55+
if: matrix.platform == 'Linux'
56+
run: |
57+
# Check if Swift is already available
58+
if command -v swift >/dev/null 2>&1; then
59+
echo "Swift is already available:"
60+
swift --version
61+
else
62+
echo "Installing Swift using Swiftly..."
63+
64+
# Install Swiftly
65+
curl -L https://swift-server.github.io/swiftly/swiftly-install.sh | bash
66+
67+
# Add Swiftly to PATH for current session
68+
export PATH="$HOME/.local/bin:$PATH"
69+
echo "$HOME/.local/bin" >> $GITHUB_PATH
70+
71+
# Install latest Swift toolchain
72+
swiftly install latest
73+
swiftly use latest
74+
75+
echo "Swift installation completed:"
76+
swift --version
77+
fi
78+
79+
- name: Cache Swift Package Manager
80+
uses: actions/cache@v4
81+
with:
82+
path: |
83+
.build
84+
~/.cache/org.swift.swiftpm
85+
key: ${{ runner.os }}-${{ matrix.arch }}-spm-${{ hashFiles('Package.swift', 'Package.resolved') }}-ci
86+
restore-keys: |
87+
${{ runner.os }}-${{ matrix.arch }}-spm-
88+
89+
- name: Swift format lint (check only)
90+
if: matrix.lint_check
91+
run: |
92+
if command -v swift-format >/dev/null 2>&1; then
93+
swift-format lint --recursive Sources/ Plugins/
94+
else
95+
echo "swift-format not available, skipping lint check"
96+
fi
97+
98+
- name: Build package
99+
run: |
100+
if [ "${{ matrix.platform }}" = "macOS" ] && [ "${{ matrix.arch }}" = "universal" ]; then
101+
# Build universal binary for macOS
102+
swift build --configuration release --arch arm64
103+
swift build --configuration release --arch x86_64
104+
elif [ "${{ matrix.platform }}" = "Linux" ]; then
105+
swift build --configuration release --triple ${{ matrix.triple }} --static-swift-stdlib
106+
else
107+
swift build --configuration release
108+
fi
109+
110+
- name: Run tests
111+
if: matrix.comprehensive_test
112+
run: swift test
113+
114+
- name: Smoke test CLI tools
115+
if: matrix.comprehensive_test
116+
run: |
117+
# Basic smoke tests - just verify help works
118+
swift run BuildEnvironmentExtractor --help
119+
swift run GitInfoExtractor --help

0 commit comments

Comments
 (0)