mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-02-07 00:17:07 +01:00
Fix: Translation Verification hard-coded repo properties (#2584)
# Description Please provide a summary of the changes, including relevant motivation and context. Closes #(issue_number) ## Checklist - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have performed a self-review of my own code - [ ] I have attached images of the change if it is UI based - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] If my code has heavily changed functionality I have updated relevant docs on [Stirling-PDFs doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) - [ ] My changes generate no new warnings - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only)
This commit is contained in:
parent
36c4d8552d
commit
7b768db969
68
.github/workflows/check_properties.yml
vendored
68
.github/workflows/check_properties.yml
vendored
@ -15,6 +15,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
issues: write # Allow posting comments on issues/PRs
|
issues: write # Allow posting comments on issues/PRs
|
||||||
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
|
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
|
||||||
@ -29,19 +30,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
python-version: "3.x"
|
python-version: "3.x"
|
||||||
|
|
||||||
- name: Fetch PR changed files
|
|
||||||
id: fetch-pr-changes
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
echo "Fetching PR changed files..."
|
|
||||||
|
|
||||||
gh repo set-default ${{ github.event.pull_request.head.repo.full_name }} # Set the fork repository as default
|
|
||||||
|
|
||||||
# Fetch the list of changed files in the PR
|
|
||||||
echo "Getting list of changed files from PR..."
|
|
||||||
gh pr view ${{ github.event.pull_request.number }} --json files -q ".files[].path" | grep -E '^src/main/resources/messages_[a-zA-Z_]+\.properties$' > changed_files.txt # Filter only matching property files
|
|
||||||
|
|
||||||
- name: Get PR data
|
- name: Get PR data
|
||||||
id: get-pr-data
|
id: get-pr-data
|
||||||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
||||||
@ -62,14 +50,30 @@ jobs:
|
|||||||
core.setOutput("repo_name", repoName);
|
core.setOutput("repo_name", repoName);
|
||||||
core.setOutput("branch", branch);
|
core.setOutput("branch", branch);
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Fetch PR changed files
|
||||||
|
id: fetch-pr-changes
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
echo "Fetching PR changed files..."
|
||||||
|
echo "Getting list of changed files from PR..."
|
||||||
|
gh pr view ${{ steps.get-pr-data.outputs.pr_number }} --json files -q ".files[].path" | grep -E '^src/main/resources/messages_[a-zA-Z_]+\.properties$' > changed_files.txt # Filter only matching property files
|
||||||
|
|
||||||
- name: Determine reference file test
|
- name: Determine reference file test
|
||||||
id: determine-file-1
|
id: determine-file
|
||||||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
const prNumber = ${{ steps.get-pr-data.outputs.pr_number }};
|
const prNumber = ${{ steps.get-pr-data.outputs.pr_number }};
|
||||||
const repoOwner = "${{ steps.get-pr-data.outputs.repo_owner }}";
|
const repoOwner = "${{ steps.get-pr-data.outputs.repo_owner }}";
|
||||||
const repoName = "${{ steps.get-pr-data.outputs.repo_name }}";
|
const repoName = "${{ steps.get-pr-data.outputs.repo_name }}";
|
||||||
|
|
||||||
|
const prRepoOwner = "${{ github.event.pull_request.head.repo.owner.login }}";
|
||||||
|
const prRepoName = "${{ github.event.pull_request.head.repo.name }}";
|
||||||
const branch = "${{ steps.get-pr-data.outputs.branch }}";
|
const branch = "${{ steps.get-pr-data.outputs.branch }}";
|
||||||
|
|
||||||
console.log(`Determining reference file for PR #${prNumber}`);
|
console.log(`Determining reference file for PR #${prNumber}`);
|
||||||
@ -101,28 +105,28 @@ jobs:
|
|||||||
|
|
||||||
// Create a temporary directory for PR files
|
// Create a temporary directory for PR files
|
||||||
const tempDir = "pr-branch";
|
const tempDir = "pr-branch";
|
||||||
if (!require("fs").existsSync(tempDir)) {
|
if (!fs.existsSync(tempDir)) {
|
||||||
require("fs").mkdirSync(tempDir, { recursive: true });
|
fs.mkdirSync(tempDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download and save each changed file
|
// Download and save each changed file
|
||||||
for (const file of changedFiles) {
|
for (const file of changedFiles) {
|
||||||
const { data: fileContent } = await github.rest.repos.getContent({
|
const { data: fileContent } = await github.rest.repos.getContent({
|
||||||
owner: repoOwner,
|
owner: prRepoOwner,
|
||||||
repo: repoName,
|
repo: prRepoName,
|
||||||
path: file,
|
path: file,
|
||||||
ref: branch,
|
ref: branch,
|
||||||
});
|
});
|
||||||
|
|
||||||
const content = Buffer.from(fileContent.content, "base64").toString("utf-8");
|
const content = Buffer.from(fileContent.content, "base64").toString("utf-8");
|
||||||
const filePath = `${tempDir}/${file}`;
|
const filePath = path.join(tempDir, file);
|
||||||
const dirPath = require("path").dirname(filePath);
|
const dirPath = path.dirname(filePath);
|
||||||
|
|
||||||
if (!require("fs").existsSync(dirPath)) {
|
if (!fs.existsSync(dirPath)) {
|
||||||
require("fs").mkdirSync(dirPath, { recursive: true });
|
fs.mkdirSync(dirPath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
require("fs").writeFileSync(filePath, content);
|
fs.writeFileSync(filePath, content);
|
||||||
console.log(`Saved file: ${filePath}`);
|
console.log(`Saved file: ${filePath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,27 +140,27 @@ jobs:
|
|||||||
if (changedFiles.includes("src/main/resources/messages_en_GB.properties")) {
|
if (changedFiles.includes("src/main/resources/messages_en_GB.properties")) {
|
||||||
console.log("Using PR branch reference file.");
|
console.log("Using PR branch reference file.");
|
||||||
const { data: fileContent } = await github.rest.repos.getContent({
|
const { data: fileContent } = await github.rest.repos.getContent({
|
||||||
owner: repoOwner,
|
owner: prRepoOwner,
|
||||||
repo: repoName,
|
repo: prRepoName,
|
||||||
path: "src/main/resources/messages_en_GB.properties",
|
path: "src/main/resources/messages_en_GB.properties",
|
||||||
ref: branch,
|
ref: branch,
|
||||||
});
|
});
|
||||||
|
|
||||||
referenceFilePath = "pr-branch-messages_en_GB.properties";
|
referenceFilePath = "pr-branch-messages_en_GB.properties";
|
||||||
const content = Buffer.from(fileContent.content, "base64").toString("utf-8");
|
const content = Buffer.from(fileContent.content, "base64").toString("utf-8");
|
||||||
require("fs").writeFileSync(referenceFilePath, content);
|
fs.writeFileSync(referenceFilePath, content);
|
||||||
} else {
|
} else {
|
||||||
console.log("Using main branch reference file.");
|
console.log("Using main branch reference file.");
|
||||||
const { data: fileContent } = await github.rest.repos.getContent({
|
const { data: fileContent } = await github.rest.repos.getContent({
|
||||||
owner: "Stirling-Tools",
|
owner: repoOwner,
|
||||||
repo: "Stirling-PDF",
|
repo: repoName,
|
||||||
path: "src/main/resources/messages_en_GB.properties",
|
path: "src/main/resources/messages_en_GB.properties",
|
||||||
ref: "main",
|
ref: "main",
|
||||||
});
|
});
|
||||||
|
|
||||||
referenceFilePath = "main-branch-messages_en_GB.properties";
|
referenceFilePath = "main-branch-messages_en_GB.properties";
|
||||||
const content = Buffer.from(fileContent.content, "base64").toString("utf-8");
|
const content = Buffer.from(fileContent.content, "base64").toString("utf-8");
|
||||||
require("fs").writeFileSync(referenceFilePath, content);
|
fs.writeFileSync(referenceFilePath, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Reference file path: ${referenceFilePath}`);
|
console.log(`Reference file path: ${referenceFilePath}`);
|
||||||
@ -203,13 +207,13 @@ jobs:
|
|||||||
script: |
|
script: |
|
||||||
const { GITHUB_REPOSITORY, SCRIPT_OUTPUT } = process.env;
|
const { GITHUB_REPOSITORY, SCRIPT_OUTPUT } = process.env;
|
||||||
const [repoOwner, repoName] = GITHUB_REPOSITORY.split('/');
|
const [repoOwner, repoName] = GITHUB_REPOSITORY.split('/');
|
||||||
const prNumber = context.issue.number;
|
const issueNumber = context.issue.number;
|
||||||
|
|
||||||
// Find existing comment
|
// Find existing comment
|
||||||
const comments = await github.rest.issues.listComments({
|
const comments = await github.rest.issues.listComments({
|
||||||
owner: repoOwner,
|
owner: repoOwner,
|
||||||
repo: repoName,
|
repo: repoName,
|
||||||
issue_number: prNumber
|
issue_number: issueNumber
|
||||||
});
|
});
|
||||||
|
|
||||||
const comment = comments.data.find(c => c.body.includes("## 🚀 Translation Verification Summary"));
|
const comment = comments.data.find(c => c.body.includes("## 🚀 Translation Verification Summary"));
|
||||||
@ -231,7 +235,7 @@ jobs:
|
|||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
owner: repoOwner,
|
owner: repoOwner,
|
||||||
repo: repoName,
|
repo: repoName,
|
||||||
issue_number: prNumber,
|
issue_number: issueNumber,
|
||||||
body: `## 🚀 Translation Verification Summary\n\n\n${SCRIPT_OUTPUT}\n`
|
body: `## 🚀 Translation Verification Summary\n\n\n${SCRIPT_OUTPUT}\n`
|
||||||
});
|
});
|
||||||
console.log("Created new comment.");
|
console.log("Created new comment.");
|
||||||
|
Loading…
Reference in New Issue
Block a user