Skip to content

Commit b3813a7

Browse files
feat: add completion graphs (#23)
1 parent 91942f2 commit b3813a7

10 files changed

Lines changed: 1753 additions & 36 deletions
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
# Fetches translation/approval progress for every Crowdin project and:
3+
# 1. Upserts a single pinned GitHub issue whose body contains a Markdown
4+
# table per project with per-language translation and approval percentages,
5+
# sorted by lowest approval percentage first.
6+
# 2. Generates per-project SVG progress graphs and commits them to the
7+
# dedicated `crowdin-progress` branch so they can be embedded in READMEs
8+
# or other documents via jsDelivr or raw GitHub URLs.
9+
#
10+
# Required GitHub repository configuration:
11+
# secrets.CROWDIN_TOKEN – Crowdin personal access token
12+
# secrets.GH_BOT_TOKEN – GitHub PAT with "issues: write" and
13+
# "contents: write" permissions
14+
# vars.CROWDIN_PROJECT_IDS – Comma-separated list of Crowdin project IDs
15+
# (e.g. "123456" or "123456,789012")
16+
# vars.GH_BOT_NAME – Git commit author name
17+
# secrets.GH_BOT_EMAIL – Git commit author email
18+
19+
name: Sync Crowdin Progress
20+
permissions: {}
21+
22+
on:
23+
schedule:
24+
# Run once a day so progress stays reasonably fresh.
25+
- cron: '0 2 * * *'
26+
workflow_dispatch: # Allow ad-hoc manual runs
27+
28+
# Only one sync at a time; never cancel an in-progress run.
29+
concurrency:
30+
group: crowdin-progress-sync
31+
cancel-in-progress: false
32+
33+
jobs:
34+
sync:
35+
name: Sync Crowdin progress to pinned issue and SVG branch
36+
runs-on: ubuntu-latest
37+
permissions:
38+
contents: write
39+
issues: write
40+
if: github.repository_owner == 'LizardByte' # don't run for forks
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
45+
with:
46+
token: ${{ secrets.GH_BOT_TOKEN }}
47+
48+
- name: Set up Node.js
49+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
50+
with:
51+
node-version: 'node'
52+
53+
- name: Install dependencies
54+
run: npm install --ignore-scripts
55+
56+
- name: Sync Crowdin progress
57+
env:
58+
CROWDIN_TOKEN: ${{ secrets.CROWDIN_TOKEN }}
59+
CROWDIN_PROJECT_IDS: ${{ vars.CROWDIN_PROJECT_IDS }}
60+
GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
61+
GITHUB_REPOSITORY: ${{ github.repository }}
62+
SVG_OUTPUT_DIR: /tmp/crowdin-progress
63+
run: node src/crowdin-progress.js
64+
65+
- name: Commit SVG graphs to crowdin-progress branch
66+
env:
67+
GH_BOT_NAME: ${{ vars.GH_BOT_NAME }}
68+
GH_BOT_EMAIL: ${{ secrets.GH_BOT_EMAIL }}
69+
run: |
70+
git config user.name "${GH_BOT_NAME}"
71+
git config user.email "${GH_BOT_EMAIL}"
72+
73+
# Create an orphan branch so it contains only SVG files with no
74+
# history from main (keeps the branch lean).
75+
git checkout --orphan crowdin-progress
76+
77+
# Remove every file inherited from the main checkout.
78+
git rm -rf . --quiet
79+
80+
# Clean up any remaining untracked files / directories.
81+
git clean -fdx
82+
83+
# Populate the branch with the freshly generated SVG files.
84+
cp -r /tmp/crowdin-progress/. .
85+
86+
git add .
87+
88+
# Only commit when there are actual changes.
89+
if git diff --staged --quiet; then
90+
echo "No changes – SVG files are already up to date."
91+
else
92+
git commit -m "chore: update Crowdin progress SVGs"
93+
git push origin crowdin-progress --force
94+
fi

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ and mirrored via [jsdelivr](https://www.jsdelivr.com/) to avoid using Crowdin's
2121

2222
## ✨ Projects
2323

24-
| **Project** | **Completion Status** | **Contributors** |
25-
|----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
26-
| [LizardByte](https://translate.lizardbyte.dev) | ![LizardByte completion](https://app.lizardbyte.dev/dashboard/crowdin/LizardByte_graph.svg) | ![LizardByte Crowdin](https://raw.githubusercontent.com/LizardByte/contributors/refs/heads/dist/crowdin.606145.svg) |
27-
| [LizardByte-docs](https://crowdin.com/project/lizardbyte-docs) | ![LizardByte-docs completion](https://app.lizardbyte.dev/dashboard/crowdin/LizardByte_docs_graph.svg) | ![LizardByte-docs Crowdin](https://raw.githubusercontent.com/LizardByte/contributors/refs/heads/dist/crowdin.614257.svg) |
24+
| **Project** | **Completion Status** | **Contributors** |
25+
|----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
26+
| [LizardByte](https://translate.lizardbyte.dev) | ![LizardByte completion](https://raw.githubusercontent.com/LizardByte/i18n/refs/heads/crowdin-progress/LizardByte_graph.svg?) | ![LizardByte Crowdin](https://raw.githubusercontent.com/LizardByte/contributors/refs/heads/dist/crowdin.606145.svg?) |
27+
| [LizardByte-docs](https://crowdin.com/project/lizardbyte-docs) | ![LizardByte-docs completion](https://raw.githubusercontent.com/LizardByte/i18n/refs/heads/crowdin-progress/LizardByte_docs_graph.svg?) | ![LizardByte-docs Crowdin](https://raw.githubusercontent.com/LizardByte/contributors/refs/heads/dist/crowdin.614257.svg?) |
2828

2929
## 👥 Contributing
3030

src/common.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Shared utilities used across Crowdin sync scripts.
3+
*/
4+
5+
/**
6+
* Parses the CROWDIN_PROJECT_IDS environment variable into an array of
7+
* trimmed, non-empty strings.
8+
*
9+
* @returns {string[]}
10+
*/
11+
function parseCrowdinProjectIds() {
12+
return (process.env.CROWDIN_PROJECT_IDS ?? '')
13+
.split(',')
14+
.map((s) => s.trim())
15+
.filter(Boolean);
16+
}
17+
18+
/**
19+
* Validates that every listed environment variable is set and that
20+
* CROWDIN_PROJECT_IDS contains at least one entry. Exits the process with
21+
* code 1 on the first failure.
22+
*
23+
* Only intended to be called when a script is run directly (i.e. `_isMain`).
24+
*
25+
* @param {string[]} requiredEnvVars Names of environment variables that must be non-empty.
26+
* @param {string[]} projectIds Result of {@link parseCrowdinProjectIds}.
27+
*/
28+
function validateEnv(requiredEnvVars, projectIds) {
29+
for (const name of requiredEnvVars) {
30+
if (process.env[name]) continue;
31+
console.error(`ERROR: environment variable ${name} is required.`);
32+
process.exit(1);
33+
}
34+
35+
if (projectIds.length === 0) {
36+
console.error('ERROR: CROWDIN_PROJECT_IDS environment variable is not set or empty.');
37+
process.exit(1);
38+
}
39+
}
40+
41+
export { parseCrowdinProjectIds, validateEnv };

0 commit comments

Comments
 (0)