gh-setup-git-identity 0.2.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.
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Create GitHub Release from CHANGELOG.md
5
+ * Usage: node scripts/create-github-release.mjs --release-version <version> --repository <repository>
6
+ * release-version: Version number (e.g., 1.0.0)
7
+ * repository: GitHub repository (e.g., owner/repo)
8
+ *
9
+ * Uses link-foundation libraries:
10
+ * - use-m: Dynamic package loading without package.json dependencies
11
+ * - command-stream: Modern shell command execution with streaming support
12
+ * - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
13
+ */
14
+
15
+ import { readFileSync } from 'fs';
16
+
17
+ // Load use-m dynamically
18
+ const { use } = eval(
19
+ await (await fetch('https://unpkg.com/use-m/use.js')).text()
20
+ );
21
+
22
+ // Import link-foundation libraries
23
+ const { $ } = await use('command-stream');
24
+ const { makeConfig } = await use('lino-arguments');
25
+
26
+ // Parse CLI arguments using lino-arguments
27
+ // Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
28
+ const config = makeConfig({
29
+ yargs: ({ yargs, getenv }) =>
30
+ yargs
31
+ .option('release-version', {
32
+ type: 'string',
33
+ default: getenv('VERSION', ''),
34
+ describe: 'Version number (e.g., 1.0.0)',
35
+ })
36
+ .option('repository', {
37
+ type: 'string',
38
+ default: getenv('REPOSITORY', ''),
39
+ describe: 'GitHub repository (e.g., owner/repo)',
40
+ }),
41
+ });
42
+
43
+ const { releaseVersion: version, repository } = config;
44
+
45
+ if (!version || !repository) {
46
+ console.error('Error: Missing required arguments');
47
+ console.error(
48
+ 'Usage: node scripts/create-github-release.mjs --release-version <version> --repository <repository>'
49
+ );
50
+ process.exit(1);
51
+ }
52
+
53
+ const tag = `v${version}`;
54
+
55
+ console.log(`Creating GitHub release for ${tag}...`);
56
+
57
+ try {
58
+ // Read CHANGELOG.md
59
+ const changelog = readFileSync('./CHANGELOG.md', 'utf8');
60
+
61
+ // Extract changelog entry for this version
62
+ // Read from CHANGELOG.md between this version header and the next version header
63
+ const versionHeaderRegex = new RegExp(`## ${version}[\\s\\S]*?(?=## \\d|$)`);
64
+ const match = changelog.match(versionHeaderRegex);
65
+
66
+ let releaseNotes = '';
67
+ if (match) {
68
+ // Remove the version header itself and trim
69
+ releaseNotes = match[0].replace(`## ${version}`, '').trim();
70
+ }
71
+
72
+ if (!releaseNotes) {
73
+ releaseNotes = `Release ${version}`;
74
+ }
75
+
76
+ // Create release using GitHub API with JSON input
77
+ // This avoids shell escaping issues that occur when passing text via command-line arguments
78
+ const payload = JSON.stringify({
79
+ tag_name: tag,
80
+ name: version,
81
+ body: releaseNotes,
82
+ });
83
+
84
+ await $`gh api repos/${repository}/releases -X POST --input -`.run({
85
+ stdin: payload,
86
+ });
87
+
88
+ console.log(`Created GitHub release: ${tag}`);
89
+ } catch (error) {
90
+ console.error('Error creating release:', error.message);
91
+ process.exit(1);
92
+ }
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Create a changeset file for manual releases
5
+ * Usage: node scripts/create-manual-changeset.mjs --bump-type <major|minor|patch> [--description <description>]
6
+ *
7
+ * Uses link-foundation libraries:
8
+ * - use-m: Dynamic package loading without package.json dependencies
9
+ * - command-stream: Modern shell command execution with streaming support
10
+ * - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
11
+ */
12
+
13
+ import { writeFileSync } from 'fs';
14
+ import { randomBytes } from 'crypto';
15
+
16
+ // Load use-m dynamically
17
+ const { use } = eval(
18
+ await (await fetch('https://unpkg.com/use-m/use.js')).text()
19
+ );
20
+
21
+ // Import link-foundation libraries
22
+ const { $ } = await use('command-stream');
23
+ const { makeConfig } = await use('lino-arguments');
24
+
25
+ // Parse CLI arguments using lino-arguments
26
+ const config = makeConfig({
27
+ yargs: ({ yargs, getenv }) =>
28
+ yargs
29
+ .option('bump-type', {
30
+ type: 'string',
31
+ default: getenv('BUMP_TYPE', ''),
32
+ describe: 'Version bump type: major, minor, or patch',
33
+ choices: ['major', 'minor', 'patch'],
34
+ })
35
+ .option('description', {
36
+ type: 'string',
37
+ default: getenv('DESCRIPTION', ''),
38
+ describe: 'Description for the changeset',
39
+ }),
40
+ });
41
+
42
+ try {
43
+ const { bumpType, description: descriptionArg } = config;
44
+
45
+ // Use provided description or default based on bump type
46
+ const description = descriptionArg || `Manual ${bumpType} release`;
47
+
48
+ if (!bumpType || !['major', 'minor', 'patch'].includes(bumpType)) {
49
+ console.error(
50
+ 'Usage: node scripts/create-manual-changeset.mjs --bump-type <major|minor|patch> [--description <description>]'
51
+ );
52
+ process.exit(1);
53
+ }
54
+
55
+ // Generate a random changeset ID
56
+ const changesetId = randomBytes(4).toString('hex');
57
+ const changesetFile = `.changeset/manual-release-${changesetId}.md`;
58
+
59
+ // Create the changeset file with single quotes to match Prettier config
60
+ const content = `---
61
+ 'gh-setup-git-identity': ${bumpType}
62
+ ---
63
+
64
+ ${description}
65
+ `;
66
+
67
+ writeFileSync(changesetFile, content, 'utf-8');
68
+
69
+ console.log(`Created changeset: ${changesetFile}`);
70
+ console.log('Content:');
71
+ console.log(content);
72
+
73
+ console.log('\nChangeset created successfully');
74
+ } catch (error) {
75
+ console.error('Error creating changeset:', error.message);
76
+ if (process.env.DEBUG) {
77
+ console.error('Stack trace:', error.stack);
78
+ }
79
+ process.exit(1);
80
+ }
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Format GitHub release notes using the format-release-notes.mjs script
5
+ * Usage: node scripts/format-github-release.mjs --release-version <version> --repository <repository> --commit-sha <commit_sha>
6
+ * release-version: Version number (e.g., 1.0.0)
7
+ * repository: GitHub repository (e.g., owner/repo)
8
+ * commit_sha: Commit SHA for PR detection
9
+ *
10
+ * Uses link-foundation libraries:
11
+ * - use-m: Dynamic package loading without package.json dependencies
12
+ * - command-stream: Modern shell command execution with streaming support
13
+ * - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
14
+ */
15
+
16
+ // Load use-m dynamically
17
+ const { use } = eval(
18
+ await (await fetch('https://unpkg.com/use-m/use.js')).text()
19
+ );
20
+
21
+ // Import link-foundation libraries
22
+ const { $ } = await use('command-stream');
23
+ const { makeConfig } = await use('lino-arguments');
24
+
25
+ // Parse CLI arguments using lino-arguments
26
+ // Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
27
+ const config = makeConfig({
28
+ yargs: ({ yargs, getenv }) =>
29
+ yargs
30
+ .option('release-version', {
31
+ type: 'string',
32
+ default: getenv('VERSION', ''),
33
+ describe: 'Version number (e.g., v0.8.36)',
34
+ })
35
+ .option('repository', {
36
+ type: 'string',
37
+ default: getenv('REPOSITORY', ''),
38
+ describe: 'GitHub repository (e.g., owner/repo)',
39
+ })
40
+ .option('commit-sha', {
41
+ type: 'string',
42
+ default: getenv('COMMIT_SHA', ''),
43
+ describe: 'Commit SHA for PR detection',
44
+ }),
45
+ });
46
+
47
+ const { releaseVersion: version, repository, commitSha } = config;
48
+
49
+ if (!version || !repository || !commitSha) {
50
+ console.error('Error: Missing required arguments');
51
+ console.error(
52
+ 'Usage: node scripts/format-github-release.mjs --release-version <version> --repository <repository> --commit-sha <commit_sha>'
53
+ );
54
+ process.exit(1);
55
+ }
56
+
57
+ const tag = `v${version}`;
58
+
59
+ try {
60
+ // Get the release ID for this version
61
+ let releaseId = '';
62
+ try {
63
+ const result =
64
+ await $`gh api "repos/${repository}/releases/tags/${tag}" --jq '.id'`.run(
65
+ { capture: true }
66
+ );
67
+ releaseId = result.stdout.trim();
68
+ } catch {
69
+ console.log(`Could not find release for ${tag}`);
70
+ process.exit(0);
71
+ }
72
+
73
+ if (releaseId) {
74
+ console.log(`Formatting release notes for ${tag}...`);
75
+ // Pass the trigger commit SHA for PR detection
76
+ // This allows proper PR lookup even if the changelog doesn't have a commit hash
77
+ await $`node scripts/format-release-notes.mjs --release-id "${releaseId}" --release-version "${tag}" --repository "${repository}" --commit-sha "${commitSha}"`;
78
+ console.log(`Formatted release notes for ${tag}`);
79
+ }
80
+ } catch (error) {
81
+ console.error('Error formatting release:', error.message);
82
+ process.exit(1);
83
+ }
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Script to format GitHub release notes with proper formatting:
5
+ * - Fix special characters like \n
6
+ * - Add link to PR that contains the release commit (if found)
7
+ * - Add shields.io NPM version badge
8
+ * - Format nicely with proper markdown
9
+ *
10
+ * PR Detection Logic:
11
+ * 1. Extract commit hash from changelog entry (if present)
12
+ * 2. Fall back to --commit-sha argument (passed from workflow)
13
+ * 3. Look up PRs that contain the commit via GitHub API
14
+ * 4. If no PR found, simply don't display any PR link (no guessing)
15
+ *
16
+ * Uses link-foundation libraries:
17
+ * - use-m: Dynamic package loading without package.json dependencies
18
+ * - command-stream: Modern shell command execution with streaming support
19
+ * - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
20
+ *
21
+ * Note: Uses --release-version instead of --version to avoid conflict with yargs' built-in --version flag.
22
+ */
23
+
24
+ // Load use-m dynamically
25
+ const { use } = eval(
26
+ await (await fetch('https://unpkg.com/use-m/use.js')).text()
27
+ );
28
+
29
+ // Import link-foundation libraries
30
+ const { $ } = await use('command-stream');
31
+ const { makeConfig } = await use('lino-arguments');
32
+
33
+ // Parse CLI arguments using lino-arguments
34
+ // Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
35
+ const config = makeConfig({
36
+ yargs: ({ yargs, getenv }) =>
37
+ yargs
38
+ .option('release-version', {
39
+ type: 'string',
40
+ default: getenv('VERSION', ''),
41
+ describe: 'Version number (e.g., v0.8.36)',
42
+ })
43
+ .option('release-id', {
44
+ type: 'string',
45
+ default: getenv('RELEASE_ID', ''),
46
+ describe: 'GitHub release ID',
47
+ })
48
+ .option('repository', {
49
+ type: 'string',
50
+ default: getenv('REPOSITORY', ''),
51
+ describe: 'GitHub repository (e.g., owner/repo)',
52
+ })
53
+ .option('commit-sha', {
54
+ type: 'string',
55
+ default: getenv('COMMIT_SHA', ''),
56
+ describe: 'Commit SHA for PR detection',
57
+ }),
58
+ });
59
+
60
+ const releaseId = config.releaseId;
61
+ const version = config.releaseVersion;
62
+ const repository = config.repository;
63
+ const passedCommitSha = config.commitSha;
64
+
65
+ if (!releaseId || !version || !repository) {
66
+ console.error(
67
+ 'Usage: format-release-notes.mjs --release-id <releaseId> --release-version <version> --repository <repository> [--commit-sha <sha>]'
68
+ );
69
+ process.exit(1);
70
+ }
71
+
72
+ const packageName = 'gh-setup-git-identity';
73
+
74
+ try {
75
+ // Get current release body
76
+ const result = await $`gh api repos/${repository}/releases/${releaseId}`.run({
77
+ capture: true,
78
+ });
79
+ const releaseData = JSON.parse(result.stdout);
80
+
81
+ const currentBody = releaseData.body || '';
82
+
83
+ // Skip if already formatted (has shields.io badge image)
84
+ if (currentBody.includes('img.shields.io')) {
85
+ console.log('Release notes already formatted');
86
+ process.exit(0);
87
+ }
88
+
89
+ // Extract the patch changes section
90
+ // This regex handles two formats:
91
+ // 1. With commit hash: "- abc1234: Description"
92
+ // 2. Without commit hash: "- Description"
93
+ const patchChangesMatchWithHash = currentBody.match(
94
+ /### Patch Changes\s*\n\s*-\s+([a-f0-9]+):\s+(.+?)$/s
95
+ );
96
+ const patchChangesMatchNoHash = currentBody.match(
97
+ /### Patch Changes\s*\n\s*-\s+(.+?)$/s
98
+ );
99
+
100
+ let commitHash = null;
101
+ let rawDescription = null;
102
+
103
+ if (patchChangesMatchWithHash) {
104
+ // Format: - abc1234: Description
105
+ [, commitHash, rawDescription] = patchChangesMatchWithHash;
106
+ } else if (patchChangesMatchNoHash) {
107
+ // Format: - Description (no commit hash)
108
+ [, rawDescription] = patchChangesMatchNoHash;
109
+ } else {
110
+ console.log('Could not parse patch changes from release notes');
111
+ process.exit(0);
112
+ }
113
+
114
+ // Clean up the description:
115
+ // 1. Convert literal \n sequences (escaped newlines from GitHub API) to actual newlines
116
+ // 2. Remove leading/trailing quotes (including escaped quotes from command-stream shell escaping)
117
+ // 3. Remove any trailing npm package links or markdown that might be there
118
+ // 4. Normalize whitespace while preserving line breaks
119
+ const cleanDescription = rawDescription
120
+ .replace(/\\n/g, '\n') // Convert escaped \n to actual newlines
121
+ .replace(/^(\\['"])+/g, '') // Remove leading escaped quotes (e.g., \', \", \'', \'')
122
+ .replace(/(['"])+$/g, '') // Remove trailing unescaped quotes (e.g., ', ", '', '')
123
+ .replace(/^(['"])+/g, '') // Remove leading unescaped quotes
124
+ .replace(/📦.*$/s, '') // Remove any existing npm package info
125
+ .replace(/---.*$/s, '') // Remove any existing separators and everything after
126
+ .trim()
127
+ .split('\n') // Split by lines
128
+ .map((line) => line.trim()) // Trim whitespace from each line
129
+ .join('\n') // Rejoin with newlines
130
+ .replace(/\n{3,}/g, '\n\n'); // Normalize excessive blank lines (3+ becomes 2)
131
+
132
+ // Find the PR that contains the release commit
133
+ // Uses commit hash from changelog or passed commit SHA from workflow
134
+ let prNumber = null;
135
+
136
+ // Determine which commit SHA to use for PR lookup
137
+ const commitShaToLookup = commitHash || passedCommitSha;
138
+
139
+ if (commitShaToLookup) {
140
+ const source = commitHash ? 'changelog' : 'workflow';
141
+ console.log(
142
+ `Looking up PR for commit ${commitShaToLookup} (from ${source})`
143
+ );
144
+
145
+ try {
146
+ const prResult =
147
+ await $`gh api "repos/${repository}/commits/${commitShaToLookup}/pulls"`.run(
148
+ { capture: true }
149
+ );
150
+ const prsData = JSON.parse(prResult.stdout);
151
+
152
+ // Find the PR that's not the version bump PR (not "chore: version packages")
153
+ const relevantPr = prsData.find(
154
+ (pr) => !pr.title.includes('version packages')
155
+ );
156
+
157
+ if (relevantPr) {
158
+ prNumber = relevantPr.number;
159
+ console.log(`Found PR #${prNumber} containing commit`);
160
+ } else if (prsData.length > 0) {
161
+ console.log(
162
+ 'Found PRs but all are version bump PRs, not linking any'
163
+ );
164
+ } else {
165
+ console.log(
166
+ 'No PR found containing this commit - not adding PR link'
167
+ );
168
+ }
169
+ } catch (error) {
170
+ console.log('Could not find PR for commit', commitShaToLookup);
171
+ console.log(' Error:', error.message);
172
+ if (process.env.DEBUG) {
173
+ console.error(error);
174
+ }
175
+ }
176
+ } else {
177
+ // No commit hash available from any source
178
+ console.log('No commit SHA available - not adding PR link');
179
+ }
180
+
181
+ // Build formatted release notes
182
+ const versionWithoutV = version.replace(/^v/, '');
183
+ const npmBadge = `[![npm version](https://img.shields.io/badge/npm-${versionWithoutV}-blue.svg)](https://www.npmjs.com/package/${packageName}/v/${versionWithoutV})`;
184
+
185
+ let formattedBody = `${cleanDescription}`;
186
+
187
+ // Add PR link if available
188
+ if (prNumber) {
189
+ formattedBody += `\n\n**Related Pull Request:** #${prNumber}`;
190
+ }
191
+
192
+ formattedBody += `\n\n---\n\n${npmBadge}`;
193
+
194
+ // Update the release using JSON input to properly handle special characters
195
+ const updatePayload = JSON.stringify({ body: formattedBody });
196
+ await $`gh api repos/${repository}/releases/${releaseId} -X PATCH --input -`.run(
197
+ { stdin: updatePayload }
198
+ );
199
+
200
+ console.log(`Formatted release notes for v${versionWithoutV}`);
201
+ if (prNumber) {
202
+ console.log(` - Added link to PR #${prNumber}`);
203
+ }
204
+ console.log(' - Added shields.io npm badge');
205
+ console.log(' - Cleaned up formatting');
206
+ } catch (error) {
207
+ console.error('Error formatting release notes:', error.message);
208
+ process.exit(1);
209
+ }
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Instant version bump script for manual releases
5
+ * Bypasses the changeset workflow and directly updates version and changelog
6
+ *
7
+ * Usage: node scripts/instant-version-bump.mjs --bump-type <major|minor|patch> [--description <description>]
8
+ *
9
+ * Uses link-foundation libraries:
10
+ * - use-m: Dynamic package loading without package.json dependencies
11
+ * - command-stream: Modern shell command execution with streaming support
12
+ * - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
13
+ */
14
+
15
+ import { readFileSync, writeFileSync } from 'fs';
16
+
17
+ // Load use-m dynamically
18
+ const { use } = eval(
19
+ await (await fetch('https://unpkg.com/use-m/use.js')).text()
20
+ );
21
+
22
+ // Import link-foundation libraries
23
+ const { $ } = await use('command-stream');
24
+ const { makeConfig } = await use('lino-arguments');
25
+
26
+ // Parse CLI arguments using lino-arguments
27
+ const config = makeConfig({
28
+ yargs: ({ yargs, getenv }) =>
29
+ yargs
30
+ .option('bump-type', {
31
+ type: 'string',
32
+ default: getenv('BUMP_TYPE', ''),
33
+ describe: 'Version bump type: major, minor, or patch',
34
+ choices: ['major', 'minor', 'patch'],
35
+ })
36
+ .option('description', {
37
+ type: 'string',
38
+ default: getenv('DESCRIPTION', ''),
39
+ describe: 'Description for the version bump',
40
+ }),
41
+ });
42
+
43
+ try {
44
+ const { bumpType, description } = config;
45
+ const finalDescription = description || `Manual ${bumpType} release`;
46
+
47
+ if (!bumpType || !['major', 'minor', 'patch'].includes(bumpType)) {
48
+ console.error(
49
+ 'Usage: node scripts/instant-version-bump.mjs --bump-type <major|minor|patch> [--description <description>]'
50
+ );
51
+ process.exit(1);
52
+ }
53
+
54
+ console.log(`\nBumping version (${bumpType})...`);
55
+
56
+ // Get current version
57
+ const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
58
+ const oldVersion = packageJson.version;
59
+ console.log(`Current version: ${oldVersion}`);
60
+
61
+ // Bump version using npm version (doesn't create git tag)
62
+ await $`npm version ${bumpType} --no-git-tag-version`;
63
+
64
+ // Get new version
65
+ const updatedPackageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
66
+ const newVersion = updatedPackageJson.version;
67
+ console.log(`New version: ${newVersion}`);
68
+
69
+ // Update CHANGELOG.md
70
+ console.log('\nUpdating CHANGELOG.md...');
71
+ const changelogPath = 'CHANGELOG.md';
72
+ let changelog = readFileSync(changelogPath, 'utf-8');
73
+
74
+ // Create new changelog entry
75
+ const newEntry = `## ${newVersion}
76
+
77
+ ### ${bumpType.charAt(0).toUpperCase() + bumpType.slice(1)} Changes
78
+
79
+ - ${finalDescription}
80
+
81
+ `;
82
+
83
+ // Insert new entry after the first heading (# Changelog or similar)
84
+ // Look for the first ## heading and insert before it
85
+ const firstVersionMatch = changelog.match(/^## /m);
86
+
87
+ if (firstVersionMatch) {
88
+ const insertPosition = firstVersionMatch.index;
89
+ changelog =
90
+ changelog.slice(0, insertPosition) +
91
+ newEntry +
92
+ changelog.slice(insertPosition);
93
+ } else {
94
+ // If no version headings exist, append after the main heading
95
+ const mainHeadingMatch = changelog.match(/^# .+$/m);
96
+ if (mainHeadingMatch) {
97
+ const insertPosition =
98
+ mainHeadingMatch.index + mainHeadingMatch[0].length;
99
+ changelog = `${changelog.slice(0, insertPosition)}\n\n${newEntry}${changelog.slice(insertPosition)}`;
100
+ } else {
101
+ // If no headings at all, prepend
102
+ changelog = `${newEntry}\n${changelog}`;
103
+ }
104
+ }
105
+
106
+ writeFileSync(changelogPath, changelog, 'utf-8');
107
+ console.log('CHANGELOG.md updated');
108
+
109
+ // Synchronize package-lock.json
110
+ console.log('\nSynchronizing package-lock.json...');
111
+ await $`npm install --package-lock-only`;
112
+
113
+ console.log('\nInstant version bump complete');
114
+ console.log(`Version: ${oldVersion} -> ${newVersion}`);
115
+ } catch (error) {
116
+ console.error('Error during instant version bump:', error.message);
117
+ if (process.env.DEBUG) {
118
+ console.error('Stack trace:', error.stack);
119
+ }
120
+ process.exit(1);
121
+ }