-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
146 lines (120 loc) · 4.27 KB
/
action.yml
File metadata and controls
146 lines (120 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: 'Snake Evolution'
description: 'Generate an animated snake eating your GitHub contributions'
author: 'miccy'
branding:
icon: 'activity'
color: 'green'
inputs:
github_user_name:
description: 'GitHub username to generate snake for'
required: true
github_token:
description: 'GitHub token for API access (optional, uses public scraping if not provided)'
required: false
default: ''
outputs:
description: 'Output file path(s) - SVG only while GIF support is in progress'
required: false
default: 'dist/snake.svg'
theme:
description: 'Color theme (github-light, github-dark, ocean, sunset, neon-gamer, cypherpunk; glass planned with future GIF support)'
required: false
default: 'github-dark'
year:
description: 'Year to generate contributions for'
required: false
default: '' # Current year if empty
outputs:
svg_path:
description: 'Path to generated SVG file'
value: ${{ steps.generate.outputs.svg_path }}
runs:
using: 'composite'
steps:
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.7
- name: Install dependencies
shell: bash
run: |
cd ${{ github.action_path }}
bun install --frozen-lockfile
- name: Generate Snake
id: generate
shell: bash
run: |
# Parse inputs
OUTPUTS_RAW="${{ inputs.outputs }}"
THEME="${{ inputs.theme }}"
YEAR="${{ inputs.year }}"
USERNAME="${{ inputs.github_user_name }}"
TOKEN="${{ inputs.github_token }}"
ACTION_PATH="${{ github.action_path }}"
WORKSPACE="${{ github.workspace }}"
# Split outputs on commas and newlines
mapfile -t OUTPUTS <<< "$(printf '%s\n' "$OUTPUTS_RAW" | tr ',' '\n')"
# Base CLI command (run from action path)
CMD_BASE=(bun run "${ACTION_PATH}/packages/cli/src/index.ts" generate -u "$USERNAME")
if [ -n "$YEAR" ]; then
CMD_BASE+=( -y "$YEAR" )
fi
if [ -n "$TOKEN" ]; then
CMD_BASE+=( --token "$TOKEN" )
fi
FIRST_OUTPUT=""
for RAW_OUTPUT in "${OUTPUTS[@]}"; do
ENTRY="$(echo "$RAW_OUTPUT" | xargs)"
# Skip empty lines
if [ -z "$ENTRY" ]; then
continue
fi
# Extract path and query params
OUTPUT_PATH_REL="${ENTRY%%\?*}"
OUTPUT_PALETTE="$THEME"
OUTPUT_FORMAT=""
if [[ "$ENTRY" == *"?"* ]]; then
QUERY_STRING="${ENTRY#*\?}"
IFS='&' read -ra PARAMS <<< "$QUERY_STRING"
for PARAM in "${PARAMS[@]}"; do
KEY="${PARAM%%=*}"
VALUE="${PARAM#*=}"
case "$KEY" in
palette)
OUTPUT_PALETTE="$VALUE"
;;
format)
OUTPUT_FORMAT="$VALUE"
;;
esac
done
fi
if [ -z "$FIRST_OUTPUT" ]; then
FIRST_OUTPUT="$OUTPUT_PATH_REL"
fi
OUTPUT_PATH_ABS="${WORKSPACE}/${OUTPUT_PATH_REL}"
# Ensure parent directory exists to allow path resolution
mkdir -p "$(dirname "$OUTPUT_PATH_ABS")"
# Resolve paths to handle symlinks and ensure robust comparison
RESOLVED_DIR="$(cd "$(dirname "$OUTPUT_PATH_ABS")" >/dev/null 2>&1 && pwd -P)"
RESOLVED_WORKSPACE="$(cd "$WORKSPACE" >/dev/null 2>&1 && pwd -P)"
# Check if the resolved directory is within the workspace
# We append a slash to both to prevent partial matches (e.g. /work/repo2 vs /work/repo)
if [[ "${RESOLVED_DIR}/" != "${RESOLVED_WORKSPACE}/"* ]]; then
echo "Error: Output path escapes workspace: $OUTPUT_PATH_REL"
continue
fi
CMD=("${CMD_BASE[@]}" -t "$OUTPUT_PALETTE" -o "$OUTPUT_PATH_ABS")
if [ -n "$OUTPUT_FORMAT" ]; then
CMD+=( -f "$OUTPUT_FORMAT" )
fi
echo "Running: ${CMD[*]}"
if ! "${CMD[@]}"; then
echo "Error: Failed to generate output for: $OUTPUT_PATH_REL"
exit 1
fi
done
# Set output (relative path for user convenience)
if [ -n "$FIRST_OUTPUT" ]; then
echo "svg_path=$FIRST_OUTPUT" >> $GITHUB_OUTPUT
fi