-
Notifications
You must be signed in to change notification settings - Fork 7k
121 lines (111 loc) · 4.91 KB
/
metrics.yml
File metadata and controls
121 lines (111 loc) · 4.91 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
name: github-metrics
on:
schedule:
- cron: '15 0 * * *'
workflow_dispatch:
permissions:
contents: read
jobs:
metrics:
name: Generate issue and PR activity SVG
if: github.repository == 'nexu-io/open-design'
runs-on: ubuntu-latest
steps:
- name: Generate Open Design bot token
id: open-design-bot-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.BOT_APP_ID }}
private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
owner: nexu-io
repositories: open-design
permission-administration: read
permission-contents: read
permission-issues: read
permission-pull-requests: read
- name: Generate issue and PR activity
uses: lowlighter/metrics@latest
with:
# Render into the action workspace only. The upload step publishes the
# SVG to repository-assets R2 so generated metrics never write back to
# the git history.
filename: github-metrics.svg
# Auth: use the Open Design GitHub App for follow-up metrics
# that need private repository API access, but do not grant write
# permissions because this workflow publishes to R2 instead of git.
token: ${{ steps.open-design-bot-token.outputs.token }}
output_action: none
# Use the repository template (per-repo metrics, not user metrics).
# Organization-owned repositories must be targeted explicitly, otherwise
# lowlighter/metrics infers the token owner and treats the target as an org.
template: repository
base: ''
user: nexu-io
repo: open-design
# Keep this README image focused on the maintenance signal that is not
# covered elsewhere: issue and PR follow-up status. Contributors and
# star history have dedicated README sections, and languages are
# already summarized by GitHub.
plugin_followup: yes
plugin_followup_sections: pr, issue
config_timezone: Asia/Shanghai
config_display: large
- name: Normalize activity SVG layout
shell: bash
run: |
set -euo pipefail
svg="/metrics_renders/github-metrics.svg"
if [ ! -s "$svg" ]; then
echo "Expected metrics SVG not found at $svg" >&2
exit 1
fi
node <<'NODE'
const fs = require('node:fs');
const svg = '/metrics_renders/github-metrics.svg';
let content = fs.readFileSync(svg, 'utf8');
content = content.replace(
/<svg xmlns="http:\/\/www\.w3\.org\/2000\/svg" width="[^"]+" height="[^"]+"([^>]*)>/,
'<svg xmlns="http://www.w3.org/2000/svg" width="720" height="110" viewBox="0 0 720 110"$1>'
);
content = content.replace(
'<span class="followup-title">Overall issues and pull requests status</span>',
'<span class="followup-title">Issue and pull request status</span>'
);
const layoutCss = [
'foreignObject>div{width:100%;display:flex;flex-direction:column;align-items:center;transform:scale(1.1);transform-origin:top center}',
'.field{justify-content:center}',
'.followup-title{text-align:center}',
'svg.large .largeable{width:520px}',
'svg.large .chart.largeable{width:504px}'
].join('');
content = content.replace('</style>', `${layoutCss}</style>`);
fs.writeFileSync(svg, content);
NODE
- name: Publish metrics SVG to repository assets
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_R2_REPOSITORY_ASSETS_AK }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_REPOSITORY_ASSETS_SK }}
AWS_DEFAULT_REGION: auto
AWS_EC2_METADATA_DISABLED: "true"
CLOUDFLARE_R2_REPOSITORY_ASSETS_BUCKET: ${{ secrets.CLOUDFLARE_R2_REPOSITORY_ASSETS_BUCKET }}
CLOUDFLARE_R2_REPOSITORY_ASSETS_PUBLIC_ORIGIN: ${{ vars.CLOUDFLARE_R2_REPOSITORY_ASSETS_PUBLIC_ORIGIN }}
CLOUDFLARE_R2_REPOSITORY_ASSETS_URL: ${{ secrets.CLOUDFLARE_R2_REPOSITORY_ASSETS_URL }}
shell: bash
run: |
set -euo pipefail
svg="/metrics_renders/github-metrics.svg"
if [ ! -s "$svg" ]; then
echo "Expected metrics SVG not found at $svg" >&2
exit 1
fi
endpoint="${CLOUDFLARE_R2_REPOSITORY_ASSETS_URL%/}"
bucket="$CLOUDFLARE_R2_REPOSITORY_ASSETS_BUCKET"
key="resources/images/github-metrics.svg"
aws --endpoint-url "$endpoint" s3api put-object \
--bucket "$bucket" \
--key "$key" \
--body "$svg" \
--content-type "image/svg+xml" \
--cache-control "public, max-age=300" \
--no-cli-pager
echo "Published ${CLOUDFLARE_R2_REPOSITORY_ASSETS_PUBLIC_ORIGIN%/}/$key"