create-preview-workflow 1.1.2 ā 1.1.4
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 +76 -42
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -46,7 +46,12 @@ function getGitHubInfo() {
|
|
|
46
46
|
type: (prev) => (prev === "sync" ? "text" : null),
|
|
47
47
|
name: "sourcePath",
|
|
48
48
|
message:
|
|
49
|
-
"Enter the source directory to sync (e.g.,
|
|
49
|
+
"Enter the source directory to sync (e.g., qmd) without leading slash:",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "text",
|
|
53
|
+
name: "org",
|
|
54
|
+
message: "Enter the organization:",
|
|
50
55
|
},
|
|
51
56
|
]);
|
|
52
57
|
|
|
@@ -55,14 +60,22 @@ function getGitHubInfo() {
|
|
|
55
60
|
|
|
56
61
|
if (response.action === "sync") {
|
|
57
62
|
const sourceDir = path.join(process.cwd(), response.sourcePath);
|
|
58
|
-
const fileNames = fs
|
|
59
|
-
.readdirSync(sourceDir)
|
|
60
|
-
.filter((file) => fs.statSync(path.join(sourceDir, file)).isFile());
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
// Check if source directory exists and get file names for URL display
|
|
65
|
+
let fileNames = [];
|
|
66
|
+
if (fs.existsSync(sourceDir)) {
|
|
67
|
+
fileNames = fs
|
|
68
|
+
.readdirSync(sourceDir)
|
|
69
|
+
.filter((file) => fs.statSync(path.join(sourceDir, file)).isFile());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const baseUrl = `http://preview.neurasense.io:30010/${username}@${repo}`;
|
|
63
73
|
const urls = fileNames.map((file) => `${baseUrl}/${file}`);
|
|
64
|
-
|
|
65
|
-
urls.
|
|
74
|
+
|
|
75
|
+
if (urls.length > 0) {
|
|
76
|
+
console.log("\nš File access URLs:");
|
|
77
|
+
urls.forEach((url) => console.log(`- ${url}`));
|
|
78
|
+
}
|
|
66
79
|
|
|
67
80
|
workflow = `# .github/workflows/sync.yml
|
|
68
81
|
name: Sync Directory
|
|
@@ -74,7 +87,7 @@ on:
|
|
|
74
87
|
- ".github/workflows/sync.yml"
|
|
75
88
|
|
|
76
89
|
jobs:
|
|
77
|
-
|
|
90
|
+
notify:
|
|
78
91
|
runs-on: ubuntu-latest
|
|
79
92
|
steps:
|
|
80
93
|
- uses: actions/checkout@v3
|
|
@@ -98,27 +111,41 @@ jobs:
|
|
|
98
111
|
echo "PUSH_TIME=\$PUSH_TIME" >> \$GITHUB_ENV
|
|
99
112
|
echo "GITHUB_URL=\$GITHUB_URL" >> \$GITHUB_ENV
|
|
100
113
|
|
|
101
|
-
- name:
|
|
114
|
+
- name: Call Preview Webhook
|
|
102
115
|
run: |
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
curl -X POST http://preview.neurasense.io:30010/deploy \\
|
|
117
|
+
-H "Content-Type: application/json" \\
|
|
118
|
+
-d "\$(jq -n \\
|
|
119
|
+
--arg repo "\${{ github.repository }}" \\
|
|
120
|
+
--arg actor "\${{ github.actor }}" \\
|
|
121
|
+
--arg ref "\${{ github.ref }}" \\
|
|
122
|
+
--arg sha "\${{ github.sha }}" \\
|
|
123
|
+
--arg org "${response.org}" \\
|
|
124
|
+
--arg user "\$USER" \\
|
|
125
|
+
--arg repo_name "\$REPO" \\
|
|
126
|
+
--arg dir "\$DIR" \\
|
|
127
|
+
--arg commit_msg "\$COMMIT_MSG" \\
|
|
128
|
+
--arg commit_sha "\$COMMIT_SHA" \\
|
|
129
|
+
--arg push_time "\$PUSH_TIME" \\
|
|
130
|
+
--arg github_url "\$GITHUB_URL" \\
|
|
131
|
+
--arg source_path "${response.sourcePath}" \\
|
|
132
|
+
'{
|
|
133
|
+
repository: \$repo,
|
|
134
|
+
actor: \$actor,
|
|
135
|
+
ref: \$ref,
|
|
136
|
+
sha: \$sha,
|
|
137
|
+
org: \$org,
|
|
138
|
+
source_path: \$source_path,
|
|
139
|
+
sync_log: {
|
|
140
|
+
"Last sync": \$push_time,
|
|
141
|
+
"Last commit": \$commit_msg,
|
|
142
|
+
"Commit SHA": \$commit_sha,
|
|
143
|
+
"Source": (\$user + "/" + \$repo_name),
|
|
144
|
+
"View diff": \$github_url,
|
|
145
|
+
"Org": \$org,
|
|
146
|
+
directory: \$dir
|
|
147
|
+
}
|
|
148
|
+
}')"
|
|
122
149
|
`;
|
|
123
150
|
} else {
|
|
124
151
|
workflow = `# .github/workflows/sync.yml
|
|
@@ -144,20 +171,21 @@ jobs:
|
|
|
144
171
|
echo "REPO=\$REPO" >> \$GITHUB_ENV
|
|
145
172
|
echo "DIR=\$DIR" >> \$GITHUB_ENV
|
|
146
173
|
|
|
147
|
-
- name:
|
|
174
|
+
- name: Call Delete Webhook
|
|
148
175
|
run: |
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
176
|
+
curl -X POST http://preview.neurasense.io:30010/delete \\
|
|
177
|
+
-H "Content-Type: application/json" \\
|
|
178
|
+
-d "\$(jq -n \\
|
|
179
|
+
--arg repo "\${{ github.repository }}" \\
|
|
180
|
+
--arg actor "\${{ github.actor }}" \\
|
|
181
|
+
--arg user "\$USER" \\
|
|
182
|
+
--arg repo_name "\$REPO" \\
|
|
183
|
+
--arg dir "\$DIR" \\
|
|
184
|
+
'{
|
|
185
|
+
repository: \$repo,
|
|
186
|
+
actor: \$actor,
|
|
187
|
+
directory: \$dir
|
|
188
|
+
}')"
|
|
161
189
|
`;
|
|
162
190
|
}
|
|
163
191
|
|
|
@@ -168,6 +196,12 @@ jobs:
|
|
|
168
196
|
const actionText =
|
|
169
197
|
response.action === "sync" ? "sync content to" : "delete content from";
|
|
170
198
|
console.log(
|
|
171
|
-
`\nā
GitHub Actions workflow to ${actionText} shared directory created at .github/workflows/sync.yml
|
|
199
|
+
`\nā
GitHub Actions workflow to ${actionText} shared directory created at .github/workflows/sync.yml.`
|
|
172
200
|
);
|
|
201
|
+
|
|
202
|
+
if (response.action === "sync") {
|
|
203
|
+
console.log(
|
|
204
|
+
`\nš” The workflow will call the webhook at http://preview.neurasense.io:30010/deploy with the source directory "${response.sourcePath}" included in the payload.`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
173
207
|
})();
|