Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
92 lines (90 loc) · 4.05 KB
/
Copy pathaction.yml
File metadata and controls
92 lines (90 loc) · 4.05 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
name: GitHub City
description: Draws an isometric SVG city of your repositories for your profile README. Building height grows with commits.
author: codebywater
branding:
icon: home
color: blue
inputs:
user:
description: GitHub user whose city to draw. Defaults to the repository owner.
default: ${{ github.repository_owner }}
out:
description: Folder for city-light.svg and city-dark.svg.
default: assets
exclude:
description: Comma-separated repositories to hide.
default: ""
forks:
description: Include forks (true/false).
default: "false"
max-repos:
description: How many buildings to draw (the largest by commits). 0 = no limit.
default: "36"
commit:
description: Commit the images when they change (true/false).
default: "true"
token:
description: Token for the GitHub API.
default: ${{ github.token }}
lang:
description: Language of the labels on the picture, en or ru.
default: en
season:
description: auto (snow from December to February), winter (always) or none.
default: auto
runs:
using: composite
steps:
- name: Draw the city
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
CITY_USER: ${{ inputs.user }}
CITY_OUT: ${{ inputs.out }}
CITY_EXCLUDE: ${{ inputs.exclude }}
CITY_FORKS: ${{ inputs.forks }}
CITY_MAX: ${{ inputs.max-repos }}
CITY_LANG: ${{ inputs.lang }}
CITY_SEASON: ${{ inputs.season }}
# Репозиторий, куда коммитится картинка, в город не попадает: иначе каждый
# коммит «Update GitHub City» менял бы картинку и коммиты шли бы каждый день.
CITY_HOST: ${{ github.repository }}
run: |
args=("$CITY_USER" --out "$CITY_OUT" --host "$CITY_HOST" --lang "${CITY_LANG:-en}" --season "${CITY_SEASON:-auto}")
# Пустое max-repos — значение по умолчанию, а не «без ограничения».
[ -n "$CITY_MAX" ] && args+=(--max "$CITY_MAX")
[ -n "$CITY_EXCLUDE" ] && args+=(--exclude "$CITY_EXCLUDE")
[ "$CITY_FORKS" = "true" ] && args+=(--forks)
node "$GITHUB_ACTION_PATH/src/cli.js" "${args[@]}"
- name: Commit
if: inputs.commit == 'true'
shell: bash
env:
CITY_OUT: ${{ inputs.out }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "$CITY_OUT"/city-*.svg
if git diff --cached --quiet; then
echo "The city has not changed."
# GitHub отключает расписание в публичном репозитории после 60 дней без активности.
last=$(git log -1 --format=%ct 2>/dev/null || echo 0)
days=$(( ($(date +%s) - last) / 86400 ))
if [ "$days" -ge 50 ]; then
echo "::warning title=GitHub City::No commits in this repository for $days days. GitHub disables scheduled runs after 60 days of inactivity. Make any commit; if the schedule is already disabled, use Actions → GitHub City → Enable workflow."
fi
exit 0
fi
git commit -m "Update GitHub City"
# Пока шёл запуск, в ветку могли запушить (правка README, параллельный запуск).
# Подтягиваем и пробуем снова; при конфликте в картинках берём только что нарисованные.
branch="${GITHUB_REF_NAME:-$(git rev-parse --abbrev-ref HEAD)}"
for attempt in 1 2 3; do
git push origin "HEAD:$branch" && exit 0
echo "Push rejected (attempt $attempt), pulling changes from $branch."
sleep "$attempt"
git fetch origin "$branch"
git rebase -X theirs FETCH_HEAD || { git rebase --abort; exit 1; }
done
echo "::error title=GitHub City::Could not push the images to $branch."
exit 1