Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 83 additions & 1 deletion .github/workflows/deploy-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- master

permissions:
contents: write

jobs:
deploy:
name: Deploy frontend
Expand All @@ -16,7 +19,86 @@ jobs:
workflow_id: 42688838
access_token: ${{ github.token }}

- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Check translation label
id: translation-label
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
LABEL_RESULT=$(node .github/workflows/scripts/check-translation-label.js --repo "${{ github.repository }}" --token "$GITHUB_TOKEN" --sha "${{ github.sha }}" --label "docs:translation-impact")
echo "$LABEL_RESULT" >> "$GITHUB_OUTPUT"

- name: Get changed English documentation files
id: changed-files
if: steps.translation-label.outputs.label_present == 'true'
run: |
set -euo pipefail
BEFORE="${{ github.event.before }}"
if git rev-parse "$BEFORE^{commit}" >/dev/null 2>&1; then
DIFF_BASE="$BEFORE"
else
DIFF_BASE=""
fi

if [ -n "$DIFF_BASE" ]; then
CHANGED_FILES=$(git diff --name-only "$DIFF_BASE" "${{ github.sha }}" | grep "^frontend/docs/.*\.md$" || true)
else
CHANGED_FILES=$(git ls-tree --name-only -r "${{ github.sha }}" | grep "^frontend/docs/.*\.md$" || true)
fi

if [ -z "$CHANGED_FILES" ]; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
if [ -n "$DIFF_BASE" ]; then
printf '%s\n' "$CHANGED_FILES" > changed_english_docs_raw.txt
node .github/workflows/scripts/filter-small-doc-changes.js "$DIFF_BASE" "${{ github.sha }}" changed_english_docs_raw.txt changed_english_docs.txt
if [ -s changed_english_docs.txt ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
else
printf '%s\n' "$CHANGED_FILES" > changed_english_docs.txt
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
fi

- name: Mark translations as outdated
if: steps.translation-label.outputs.label_present == 'true' && steps.changed-files.outputs.has_changes == 'true'
run: |
node .github/workflows/scripts/mark-translations-outdated.js

- name: Check if translations were modified
if: steps.translation-label.outputs.label_present == 'true' && steps.changed-files.outputs.has_changes == 'true'
id: check-changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "translations_modified=true" >> "$GITHUB_OUTPUT"
else
echo "translations_modified=false" >> "$GITHUB_OUTPUT"
fi

- name: Commit changes
if: steps.translation-label.outputs.label_present == 'true' && steps.check-changes.outputs.translations_modified == 'true'
run: |
git config --local user.email "omp-bot@users.noreply.github.com"
git config --local user.name "omp-bot"
git add frontend/i18n/
git commit -m "Mark translations as potentially outdated (post-merge)"

- name: Push changes
if: steps.translation-label.outputs.label_present == 'true' && steps.check-changes.outputs.translations_modified == 'true'
run: |
git push origin HEAD:${{ github.ref }}

- name: Cache ~/.npm for npm ci
uses: actions/cache@v4
Expand Down
118 changes: 118 additions & 0 deletions .github/workflows/scripts/check-translation-label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env node

const https = require('https');

const args = process.argv.slice(2);
const options = {
repo: process.env.GITHUB_REPOSITORY || '',
token: process.env.GITHUB_TOKEN || '',
sha: process.env.GITHUB_SHA || '',
label: '',
pr: '',
};

for (let i = 0; i < args.length; i += 2) {
const key = args[i];
const value = args[i + 1] || '';
switch (key) {
case '--repo':
options.repo = value;
break;
case '--token':
options.token = value;
break;
case '--sha':
options.sha = value;
break;
case '--label':
options.label = value;
break;
case '--pr':
options.pr = value;
break;
default:
i -= 1;
}
}

if (!options.repo || !options.token || !options.label) {
console.error('Missing required arguments: repo, token, and label');
process.exit(1);
}

const githubRequest = (path, accept) =>
new Promise((resolve, reject) => {
const req = https.request(
{
hostname: 'api.github.com',
path,
method: 'GET',
headers: {
Authorization: `Bearer ${options.token}`,
'User-Agent': 'translations-workflow',
Accept: accept || 'application/vnd.github+json',
},
},
res => {
let body = '';
res.on('data', chunk => {
body += chunk;
});
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
try {
resolve(JSON.parse(body));
} catch (err) {
reject(err);
}
} else {
reject(new Error(`GitHub API responded with ${res.statusCode}: ${body}`));
}
});
}
);
req.on('error', reject);
req.end();
});

const detectPrNumber = async () => {
if (options.pr) {
return options.pr;
}
if (!options.sha) {
return '';
}

try {
const pulls = await githubRequest(
`/repos/${options.repo}/commits/${options.sha}/pulls`,
'application/vnd.github.groot-preview+json'
);
if (Array.isArray(pulls) && pulls.length > 0) {
return String(pulls[0].number);
}
} catch (error) {
console.error(`Failed to determine PR number: ${error.message}`);
}
return '';
};

const main = async () => {
try {
const prNumber = await detectPrNumber();
if (!prNumber) {
process.stdout.write('label_present=false');
return;
}

const issue = await githubRequest(`/repos/${options.repo}/issues/${prNumber}`);
const labels = Array.isArray(issue.labels) ? issue.labels.map(label => label.name) : [];
const hasLabel = labels.includes(options.label);
process.stdout.write(`label_present=${hasLabel ? 'true' : 'false'}`);
} catch (error) {
console.error(`Failed to load labels: ${error.message}`);
process.stdout.write('label_present=false');
}
};

main();
Loading
Loading