create-preview-workflow 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +68 -0
- package/package.json +10 -0
package/index.js
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const fs = require("fs");
|
4
|
+
const path = require("path");
|
5
|
+
const prompts = require("prompts");
|
6
|
+
|
7
|
+
(async () => {
|
8
|
+
const response = await prompts([
|
9
|
+
{
|
10
|
+
type: "text",
|
11
|
+
name: "sourcePath",
|
12
|
+
message:
|
13
|
+
"Enter the source file or directory to sync (e.g., tests.nb.html or dist/):",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
type: "text",
|
17
|
+
name: "token",
|
18
|
+
message: "Enter your GitHub personal access token:",
|
19
|
+
},
|
20
|
+
]);
|
21
|
+
|
22
|
+
const workflow = `# .github/workflows/sync.yml
|
23
|
+
name: Sync Directory
|
24
|
+
|
25
|
+
on:
|
26
|
+
push:
|
27
|
+
|
28
|
+
jobs:
|
29
|
+
sync:
|
30
|
+
runs-on: ubuntu-latest
|
31
|
+
steps:
|
32
|
+
- uses: actions/checkout@v3
|
33
|
+
|
34
|
+
- name: Set variables
|
35
|
+
run: |
|
36
|
+
USER="\${{ github.actor }}"
|
37
|
+
REPO="\${{ github.event.repository.name }}"
|
38
|
+
DIR="\${USER}@\${REPO}"
|
39
|
+
echo "USER=\$USER" >> \$GITHUB_ENV
|
40
|
+
echo "REPO=\$REPO" >> \$GITHUB_ENV
|
41
|
+
echo "DIR=\$DIR" >> \$GITHUB_ENV
|
42
|
+
|
43
|
+
- name: Clone target repo
|
44
|
+
run: |
|
45
|
+
git clone https://${response.token}@github.com/ssm123ssm/preview.git
|
46
|
+
rm -rf preview/public/protected/\$DIR
|
47
|
+
mkdir -p preview/public/protected/\$DIR
|
48
|
+
cp -r ${response.sourcePath} preview/public/protected/\$DIR/
|
49
|
+
cd preview
|
50
|
+
git config user.name "GitHub Actions"
|
51
|
+
git config user.email "actions@github.com"
|
52
|
+
git add .
|
53
|
+
if ! git diff --cached --quiet; then
|
54
|
+
git commit -m "Sync from source repo"
|
55
|
+
git push
|
56
|
+
else
|
57
|
+
echo "No changes to commit"
|
58
|
+
fi
|
59
|
+
`;
|
60
|
+
|
61
|
+
const destDir = path.join(process.cwd(), ".github", "workflows");
|
62
|
+
fs.mkdirSync(destDir, { recursive: true });
|
63
|
+
fs.writeFileSync(path.join(destDir, "sync.yml"), workflow);
|
64
|
+
|
65
|
+
console.log(
|
66
|
+
"✅ GitHub Actions workflow for Preview created at .github/workflows/sync.yml"
|
67
|
+
);
|
68
|
+
})();
|