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