Skip to content

Commit

Permalink
chore(ci): make sure to create synced files
Browse files Browse the repository at this point in the history
...and intermediate directories if they don't already exist
  • Loading branch information
rektdeckard committed Dec 30, 2024
1 parent 6d2358f commit 13248a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/sync-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
git checkout -b $BRANCH
# Commit and push changes
git add .
git commit -am "chore(docs): sync readme section"
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ matrix.repository }}.git" $BRANCH
Expand Down
8 changes: 6 additions & 2 deletions scripts/sync-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const SYNC_FILES: Array<string | Array<string>> = [
const targetRepo = process.argv[process.argv.length - 1];
if (!targetRepo) throw new Error("Target repository not provided");


const readmePath = path.resolve(__dirname, `../${README_PATH}`);
const readmeContent = fs.readFileSync(readmePath, "utf8");

Expand All @@ -36,6 +35,7 @@ const SYNC_FILES: Array<string | Array<string>> = [
const filePath = path.resolve(__dirname, `../${fileName}`);
const fileContent = fs.readFileSync(filePath, "utf8");

// If target file has aliases, remove them
if (Array.isArray(file)) {
for (const alias of file) {
const targetPath = path.resolve(__dirname, `../../${targetRepo}/${alias}`);
Expand All @@ -45,8 +45,12 @@ const SYNC_FILES: Array<string | Array<string>> = [
}
}

// Write the target file and intermediate directories, or overwrite if it already exists
const targetPath = path.resolve(__dirname, `../../${targetRepo}/${fileName}`);
fs.writeFileSync(targetPath, fileContent); // Overwrites the target file if it exists
if (!fs.existsSync(path.dirname(targetPath))) {
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
}
fs.writeFileSync(targetPath, fileContent);
}
})();

Expand Down

0 comments on commit 13248a3

Please sign in to comment.