create-preview-workflow 1.0.4 → 1.0.6

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.
Files changed (2) hide show
  1. package/index.js +13 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  const fs = require("fs");
4
3
  const path = require("path");
5
4
  const prompts = require("prompts");
6
-
7
5
  (async () => {
8
6
  const response = await prompts([
9
7
  {
@@ -13,34 +11,41 @@ const prompts = require("prompts");
13
11
  "Enter the source directory to sync (e.g., 2_scripts) without leading slash:",
14
12
  },
15
13
  ]);
16
-
17
14
  const workflow = `# .github/workflows/sync.yml
18
15
  name: Sync Directory
19
-
20
16
  on:
21
17
  push:
22
-
23
18
  jobs:
24
19
  sync:
25
20
  runs-on: ubuntu-latest
26
21
  steps:
27
22
  - uses: actions/checkout@v3
28
-
29
23
  - name: Set variables
30
24
  run: |
31
25
  USER="\${{ github.actor }}"
32
26
  REPO="\${{ github.event.repository.name }}"
33
27
  DIR="\${USER}@\${REPO}"
28
+ COMMIT_MSG="\$(git log -1 --pretty=format:'%s')"
29
+ PUSH_TIME="\$(date -u '+%Y-%m-%d %H:%M:%S UTC')"
34
30
  echo "USER=\$USER" >> \$GITHUB_ENV
35
31
  echo "REPO=\$REPO" >> \$GITHUB_ENV
36
32
  echo "DIR=\$DIR" >> \$GITHUB_ENV
37
-
33
+ echo "COMMIT_MSG=\$COMMIT_MSG" >> \$GITHUB_ENV
34
+ echo "PUSH_TIME=\$PUSH_TIME" >> \$GITHUB_ENV
38
35
  - name: Clone target repo
39
36
  run: |
40
37
  git clone https://\${{ secrets.GH_SYNC_TOKEN }}@github.com/ssm123ssm/preview.git
41
38
  rm -rf preview/public/protected/\$DIR
42
39
  mkdir -p preview/public/protected/\$DIR
43
40
  cp -r ${response.sourcePath}/. preview/public/protected/\$DIR/
41
+ - name: Create log file
42
+ run: |
43
+ cd preview/public/protected/\$DIR
44
+ echo "Last sync: \$PUSH_TIME" > .sync_log
45
+ echo "Last commit: \$COMMIT_MSG" >> .sync_log
46
+ echo "Source: \$USER/\$REPO" >> .sync_log
47
+ - name: Commit and push changes
48
+ run: |
44
49
  cd preview
45
50
  git config user.name "GitHub Actions"
46
51
  git config user.email "actions@github.com"
@@ -52,12 +57,10 @@ jobs:
52
57
  echo "No changes to commit"
53
58
  fi
54
59
  `;
55
-
56
60
  const destDir = path.join(process.cwd(), ".github", "workflows");
57
61
  fs.mkdirSync(destDir, { recursive: true });
58
62
  fs.writeFileSync(path.join(destDir, "sync.yml"), workflow);
59
-
60
63
  console.log(
61
- "GitHub Actions workflow for Preview created at .github/workflows/sync.yml. Make sure to add the GH_SYNC_TOKEN secret in your repository settings."
64
+ "GitHub Actions workflow for Preview created at .github/workflows/sync.yml. Make sure to add the GH_SYNC_TOKEN secret in your repository settings."
62
65
  );
63
66
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-preview-workflow",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "bin": {
5
5
  "create-preview-workflow": "index.js"
6
6
  },