dsh-publish-helper 0.21.0 → 0.21.2

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 CHANGED
@@ -481,6 +481,11 @@ export function apply(ctx, rawConfig) {
481
481
  path,
482
482
  content: readFileSync(join(directory, path)).toString('base64'),
483
483
  }));
484
+ const workflowPath = '.github/workflows/release.yml';
485
+ if (!files.some((file) => file.path === workflowPath)) {
486
+ const template = readFileSync(new URL('./templates/release.yml', import.meta.url), 'utf8');
487
+ files.push({ path: workflowPath, content: Buffer.from(template, 'utf8').toString('base64') });
488
+ }
484
489
  const written = await uploadFiles({ token, owner: login, name, files, message: `Upload ${name}` });
485
490
  return {
486
491
  text: `repo ${login}/${name}\nbranch ${created.defaultBranch}\n${written.length} file(s): ${written.join(', ')}`,
package/lib/publish.mjs CHANGED
@@ -97,10 +97,19 @@ export async function forkAndOpenPr({
97
97
  // A failed compare/sync must not block the entry PR.
98
98
  }
99
99
 
100
+ const baseRef = await api(`${API}/repos/${forkRepo}/git/ref/heads/main`, { token, fetchImpl });
101
+ const branch = `entry/${repo.replace('/', '__')}-${Date.now().toString(36)}`;
102
+ await api(`${API}/repos/${forkRepo}/git/refs`, {
103
+ token,
104
+ method: 'POST',
105
+ fetchImpl,
106
+ body: { ref: `refs/heads/${branch}`, sha: baseRef.object.sha },
107
+ });
108
+
100
109
  const file = `data/plugins/${repo.replace('/', '__')}.yml`;
101
110
  let sha;
102
111
  try {
103
- const existing = await api(`${API}/repos/${forkRepo}/contents/${file}`, { token, fetchImpl });
112
+ const existing = await api(`${API}/repos/${forkRepo}/contents/${file}?ref=${branch}`, { token, fetchImpl });
104
113
  sha = existing.sha;
105
114
  } catch {
106
115
  sha = undefined;
@@ -113,6 +122,7 @@ export async function forkAndOpenPr({
113
122
  body: {
114
123
  message: `Add ${repo}`,
115
124
  content: Buffer.from(entry, 'utf8').toString('base64'),
125
+ branch,
116
126
  ...(sha ? { sha } : {}),
117
127
  },
118
128
  });
@@ -123,11 +133,11 @@ export async function forkAndOpenPr({
123
133
  fetchImpl,
124
134
  body: {
125
135
  title: title ?? `Add ${repo}`,
126
- head: `${owner}:main`,
136
+ head: `${owner}:${branch}`,
127
137
  base: 'main',
128
138
  body,
129
139
  },
130
140
  });
131
141
 
132
- return { fork: forkRepo, file, sync, pr: { number: pull.number, url: pull.html_url, state: pull.state } };
142
+ return { fork: forkRepo, branch, file, sync, pr: { number: pull.number, url: pull.html_url, state: pull.state } };
133
143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-publish-helper",
3
- "version": "0.21.0",
3
+ "version": "0.21.2",
4
4
  "description": "DSH plugin publishing assistant: discover by topic, check listing readiness, generate the registry entry, open the pull request and show a settings page.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,4 +1,4 @@
1
- # Copy to .github/workflows/release.yml in your package repository.
1
+ # Copy to .github/workflows/release.yml in the package repository.
2
2
  #
3
3
  # Trusted publishing (recommended): configure it once on npmjs.com
4
4
  # package page -> Settings -> Trusted publishing -> GitHub Actions
@@ -35,11 +35,27 @@ jobs:
35
35
  - name: Use the npm CLI that supports trusted publishing
36
36
  run: npm install -g npm@latest
37
37
 
38
+ - name: Verify the tag matches package.json
39
+ if: startsWith(github.ref, 'refs/tags/v')
40
+ run: |
41
+ tag="${GITHUB_REF_NAME#v}"
42
+ version=$(node -p "require('./package.json').version")
43
+ if [ "$tag" != "$version" ]; then
44
+ echo "tag $tag does not match package.json version $version"
45
+ exit 1
46
+ fi
47
+
38
48
  - name: Install dependencies
39
- run: npm ci --ignore-scripts --no-audit --no-fund
49
+ run: npm install --ignore-scripts --no-audit --no-fund
40
50
 
41
51
  - name: Test
42
- run: npm test --if-present
52
+ run: |
53
+ if [ -d test ]; then
54
+ for file in test/*.test.mjs; do
55
+ [ -e "$file" ] || continue
56
+ node "$file"
57
+ done
58
+ fi
43
59
 
44
60
  - name: Publish with provenance
45
61
  run: npm publish --provenance --access public