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.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.github/workflows/release.yml +306 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +24 -0
- package/README.md +246 -0
- package/package.json +46 -0
- package/scripts/changeset-version.mjs +38 -0
- package/scripts/create-github-release.mjs +92 -0
- package/scripts/create-manual-changeset.mjs +80 -0
- package/scripts/format-github-release.mjs +83 -0
- package/scripts/format-release-notes.mjs +209 -0
- package/scripts/instant-version-bump.mjs +121 -0
- package/scripts/publish-to-npm.mjs +122 -0
- package/scripts/setup-npm.mjs +37 -0
- package/scripts/validate-changeset.mjs +99 -0
- package/scripts/version-and-commit.mjs +237 -0
- package/src/cli.js +130 -0
- package/src/index.js +312 -0
- package/test/index.test.js +114 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changesets
|
|
2
|
+
|
|
3
|
+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
+
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
6
|
+
|
|
7
|
+
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
|
|
3
|
+
"changelog": "@changesets/cli/changelog",
|
|
4
|
+
"commit": false,
|
|
5
|
+
"fixed": [],
|
|
6
|
+
"linked": [],
|
|
7
|
+
"access": "public",
|
|
8
|
+
"baseBranch": "main",
|
|
9
|
+
"updateInternalDependencies": "patch",
|
|
10
|
+
"ignore": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
name: Checks and release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
types: [opened, synchronize, reopened]
|
|
9
|
+
# Manual release support - consolidated here to work with npm trusted publishing
|
|
10
|
+
# npm only allows ONE workflow file as trusted publisher, so all publishing
|
|
11
|
+
# must go through this workflow (release.yml)
|
|
12
|
+
workflow_dispatch:
|
|
13
|
+
inputs:
|
|
14
|
+
release_mode:
|
|
15
|
+
description: 'Manual release mode'
|
|
16
|
+
required: true
|
|
17
|
+
type: choice
|
|
18
|
+
default: 'instant'
|
|
19
|
+
options:
|
|
20
|
+
- instant
|
|
21
|
+
- changeset-pr
|
|
22
|
+
bump_type:
|
|
23
|
+
description: 'Manual release type'
|
|
24
|
+
required: true
|
|
25
|
+
type: choice
|
|
26
|
+
options:
|
|
27
|
+
- patch
|
|
28
|
+
- minor
|
|
29
|
+
- major
|
|
30
|
+
description:
|
|
31
|
+
description: 'Manual release description (optional)'
|
|
32
|
+
required: false
|
|
33
|
+
type: string
|
|
34
|
+
|
|
35
|
+
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
36
|
+
|
|
37
|
+
jobs:
|
|
38
|
+
# Changeset check - only runs on PRs
|
|
39
|
+
changeset-check:
|
|
40
|
+
name: Check for Changesets
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
if: github.event_name == 'pull_request'
|
|
43
|
+
steps:
|
|
44
|
+
- uses: actions/checkout@v4
|
|
45
|
+
with:
|
|
46
|
+
fetch-depth: 0
|
|
47
|
+
|
|
48
|
+
- name: Setup Node.js
|
|
49
|
+
uses: actions/setup-node@v4
|
|
50
|
+
with:
|
|
51
|
+
node-version: '20.x'
|
|
52
|
+
|
|
53
|
+
- name: Install dependencies
|
|
54
|
+
run: npm install
|
|
55
|
+
|
|
56
|
+
- name: Check for changesets
|
|
57
|
+
run: |
|
|
58
|
+
# Skip changeset check for automated version PRs
|
|
59
|
+
if [[ "${{ github.head_ref }}" == "changeset-release/"* ]]; then
|
|
60
|
+
echo "Skipping changeset check for automated release PR"
|
|
61
|
+
exit 0
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
# Run changeset validation script
|
|
65
|
+
node scripts/validate-changeset.mjs
|
|
66
|
+
|
|
67
|
+
# Linting - runs after changeset check on PRs, immediately on main
|
|
68
|
+
lint:
|
|
69
|
+
name: Lint
|
|
70
|
+
runs-on: ubuntu-latest
|
|
71
|
+
needs: [changeset-check]
|
|
72
|
+
if: always() && (github.event_name == 'push' || needs.changeset-check.result == 'success')
|
|
73
|
+
steps:
|
|
74
|
+
- uses: actions/checkout@v4
|
|
75
|
+
|
|
76
|
+
- name: Setup Node.js
|
|
77
|
+
uses: actions/setup-node@v4
|
|
78
|
+
with:
|
|
79
|
+
node-version: '20.x'
|
|
80
|
+
|
|
81
|
+
- name: Install dependencies
|
|
82
|
+
run: npm install
|
|
83
|
+
|
|
84
|
+
- name: Run lint
|
|
85
|
+
run: npm run lint
|
|
86
|
+
|
|
87
|
+
# Test matrix: 3 runtimes (Node.js, Bun, Deno) x 3 OS (Ubuntu, macOS, Windows)
|
|
88
|
+
# Note: Bun on Windows excluded due to known timeout issues with process spawning
|
|
89
|
+
test:
|
|
90
|
+
name: Test (${{ matrix.runtime }} on ${{ matrix.os }})
|
|
91
|
+
runs-on: ${{ matrix.os }}
|
|
92
|
+
needs: [changeset-check]
|
|
93
|
+
if: always() && (github.event_name == 'push' || needs.changeset-check.result == 'success')
|
|
94
|
+
strategy:
|
|
95
|
+
fail-fast: false
|
|
96
|
+
matrix:
|
|
97
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
98
|
+
runtime: [node, bun, deno]
|
|
99
|
+
exclude:
|
|
100
|
+
# Exclude Bun on Windows due to known timeout issues with process spawning
|
|
101
|
+
- os: windows-latest
|
|
102
|
+
runtime: bun
|
|
103
|
+
steps:
|
|
104
|
+
- uses: actions/checkout@v4
|
|
105
|
+
|
|
106
|
+
- name: Setup Node.js
|
|
107
|
+
if: matrix.runtime == 'node'
|
|
108
|
+
uses: actions/setup-node@v4
|
|
109
|
+
with:
|
|
110
|
+
node-version: '20.x'
|
|
111
|
+
|
|
112
|
+
- name: Install dependencies (Node.js)
|
|
113
|
+
if: matrix.runtime == 'node'
|
|
114
|
+
run: npm install
|
|
115
|
+
|
|
116
|
+
- name: Run tests (Node.js)
|
|
117
|
+
if: matrix.runtime == 'node'
|
|
118
|
+
run: npm test
|
|
119
|
+
|
|
120
|
+
- name: Setup Bun
|
|
121
|
+
if: matrix.runtime == 'bun'
|
|
122
|
+
uses: oven-sh/setup-bun@v2
|
|
123
|
+
with:
|
|
124
|
+
bun-version: latest
|
|
125
|
+
|
|
126
|
+
- name: Install dependencies (Bun)
|
|
127
|
+
if: matrix.runtime == 'bun'
|
|
128
|
+
run: bun install
|
|
129
|
+
|
|
130
|
+
- name: Run tests (Bun)
|
|
131
|
+
if: matrix.runtime == 'bun'
|
|
132
|
+
run: bun test
|
|
133
|
+
|
|
134
|
+
- name: Setup Deno
|
|
135
|
+
if: matrix.runtime == 'deno'
|
|
136
|
+
uses: denoland/setup-deno@v2
|
|
137
|
+
with:
|
|
138
|
+
deno-version: v2.x
|
|
139
|
+
|
|
140
|
+
- name: Install dependencies (Deno)
|
|
141
|
+
if: matrix.runtime == 'deno'
|
|
142
|
+
run: deno install
|
|
143
|
+
|
|
144
|
+
- name: Run tests (Deno)
|
|
145
|
+
if: matrix.runtime == 'deno'
|
|
146
|
+
run: deno test --allow-all
|
|
147
|
+
|
|
148
|
+
# Release - only runs on main after tests pass (for push events)
|
|
149
|
+
release:
|
|
150
|
+
name: Release
|
|
151
|
+
needs: [lint, test]
|
|
152
|
+
# Use always() to ensure this job runs even if changeset-check was skipped
|
|
153
|
+
# This is needed because lint/test jobs have a transitive dependency on changeset-check
|
|
154
|
+
if: always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && needs.lint.result == 'success' && needs.test.result == 'success'
|
|
155
|
+
runs-on: ubuntu-latest
|
|
156
|
+
# Permissions required for npm OIDC trusted publishing
|
|
157
|
+
permissions:
|
|
158
|
+
contents: write
|
|
159
|
+
pull-requests: write
|
|
160
|
+
id-token: write
|
|
161
|
+
steps:
|
|
162
|
+
- uses: actions/checkout@v4
|
|
163
|
+
with:
|
|
164
|
+
fetch-depth: 0
|
|
165
|
+
|
|
166
|
+
- name: Setup Node.js
|
|
167
|
+
uses: actions/setup-node@v4
|
|
168
|
+
with:
|
|
169
|
+
node-version: '20.x'
|
|
170
|
+
registry-url: 'https://registry.npmjs.org'
|
|
171
|
+
|
|
172
|
+
- name: Install dependencies
|
|
173
|
+
run: npm install
|
|
174
|
+
|
|
175
|
+
- name: Update npm for OIDC trusted publishing
|
|
176
|
+
run: node scripts/setup-npm.mjs
|
|
177
|
+
|
|
178
|
+
- name: Check for changesets
|
|
179
|
+
id: check_changesets
|
|
180
|
+
run: |
|
|
181
|
+
# Count changeset files (excluding README.md and config.json)
|
|
182
|
+
CHANGESET_COUNT=$(find .changeset -name "*.md" ! -name "README.md" | wc -l)
|
|
183
|
+
echo "Found $CHANGESET_COUNT changeset file(s)"
|
|
184
|
+
echo "has_changesets=$([[ $CHANGESET_COUNT -gt 0 ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
|
|
185
|
+
|
|
186
|
+
- name: Version packages and commit to main
|
|
187
|
+
if: steps.check_changesets.outputs.has_changesets == 'true'
|
|
188
|
+
id: version
|
|
189
|
+
run: node scripts/version-and-commit.mjs --mode changeset
|
|
190
|
+
|
|
191
|
+
- name: Publish to npm
|
|
192
|
+
# Run if version was committed OR if a previous attempt already committed (for re-runs)
|
|
193
|
+
if: steps.version.outputs.version_committed == 'true' || steps.version.outputs.already_released == 'true'
|
|
194
|
+
id: publish
|
|
195
|
+
run: node scripts/publish-to-npm.mjs --should-pull
|
|
196
|
+
|
|
197
|
+
- name: Create GitHub Release
|
|
198
|
+
if: steps.publish.outputs.published == 'true'
|
|
199
|
+
env:
|
|
200
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
201
|
+
run: node scripts/create-github-release.mjs --release-version "${{ steps.publish.outputs.published_version }}" --repository "${{ github.repository }}"
|
|
202
|
+
|
|
203
|
+
- name: Format GitHub release notes
|
|
204
|
+
if: steps.publish.outputs.published == 'true'
|
|
205
|
+
env:
|
|
206
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
207
|
+
run: node scripts/format-github-release.mjs --release-version "${{ steps.publish.outputs.published_version }}" --repository "${{ github.repository }}" --commit-sha "${{ github.sha }}"
|
|
208
|
+
|
|
209
|
+
# Manual Instant Release - triggered via workflow_dispatch with instant mode
|
|
210
|
+
# This job is in release.yml because npm trusted publishing
|
|
211
|
+
# only allows one workflow file to be registered as a trusted publisher
|
|
212
|
+
instant-release:
|
|
213
|
+
name: Instant Release
|
|
214
|
+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'instant'
|
|
215
|
+
runs-on: ubuntu-latest
|
|
216
|
+
# Permissions required for npm OIDC trusted publishing
|
|
217
|
+
permissions:
|
|
218
|
+
contents: write
|
|
219
|
+
pull-requests: write
|
|
220
|
+
id-token: write
|
|
221
|
+
steps:
|
|
222
|
+
- uses: actions/checkout@v4
|
|
223
|
+
with:
|
|
224
|
+
fetch-depth: 0
|
|
225
|
+
|
|
226
|
+
- name: Setup Node.js
|
|
227
|
+
uses: actions/setup-node@v4
|
|
228
|
+
with:
|
|
229
|
+
node-version: '20.x'
|
|
230
|
+
registry-url: 'https://registry.npmjs.org'
|
|
231
|
+
|
|
232
|
+
- name: Install dependencies
|
|
233
|
+
run: npm install
|
|
234
|
+
|
|
235
|
+
- name: Update npm for OIDC trusted publishing
|
|
236
|
+
run: node scripts/setup-npm.mjs
|
|
237
|
+
|
|
238
|
+
- name: Version packages and commit to main
|
|
239
|
+
id: version
|
|
240
|
+
run: node scripts/version-and-commit.mjs --mode instant --bump-type "${{ github.event.inputs.bump_type }}" --description "${{ github.event.inputs.description }}"
|
|
241
|
+
|
|
242
|
+
- name: Publish to npm
|
|
243
|
+
# Run if version was committed OR if a previous attempt already committed (for re-runs)
|
|
244
|
+
if: steps.version.outputs.version_committed == 'true' || steps.version.outputs.already_released == 'true'
|
|
245
|
+
id: publish
|
|
246
|
+
run: node scripts/publish-to-npm.mjs
|
|
247
|
+
|
|
248
|
+
- name: Create GitHub Release
|
|
249
|
+
if: steps.publish.outputs.published == 'true'
|
|
250
|
+
env:
|
|
251
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
252
|
+
run: node scripts/create-github-release.mjs --release-version "${{ steps.publish.outputs.published_version }}" --repository "${{ github.repository }}"
|
|
253
|
+
|
|
254
|
+
- name: Format GitHub release notes
|
|
255
|
+
if: steps.publish.outputs.published == 'true'
|
|
256
|
+
env:
|
|
257
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
258
|
+
run: node scripts/format-github-release.mjs --release-version "${{ steps.publish.outputs.published_version }}" --repository "${{ github.repository }}" --commit-sha "${{ github.sha }}"
|
|
259
|
+
|
|
260
|
+
# Manual Changeset PR - creates a pull request with the changeset for review
|
|
261
|
+
changeset-pr:
|
|
262
|
+
name: Create Changeset PR
|
|
263
|
+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'changeset-pr'
|
|
264
|
+
runs-on: ubuntu-latest
|
|
265
|
+
permissions:
|
|
266
|
+
contents: write
|
|
267
|
+
pull-requests: write
|
|
268
|
+
steps:
|
|
269
|
+
- uses: actions/checkout@v4
|
|
270
|
+
with:
|
|
271
|
+
fetch-depth: 0
|
|
272
|
+
|
|
273
|
+
- name: Setup Node.js
|
|
274
|
+
uses: actions/setup-node@v4
|
|
275
|
+
with:
|
|
276
|
+
node-version: '20.x'
|
|
277
|
+
|
|
278
|
+
- name: Install dependencies
|
|
279
|
+
run: npm install
|
|
280
|
+
|
|
281
|
+
- name: Create changeset file
|
|
282
|
+
run: node scripts/create-manual-changeset.mjs --bump-type "${{ github.event.inputs.bump_type }}" --description "${{ github.event.inputs.description }}"
|
|
283
|
+
|
|
284
|
+
- name: Create Pull Request
|
|
285
|
+
uses: peter-evans/create-pull-request@v7
|
|
286
|
+
with:
|
|
287
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
288
|
+
commit-message: 'chore: add changeset for manual ${{ github.event.inputs.bump_type }} release'
|
|
289
|
+
branch: changeset-manual-release-${{ github.run_id }}
|
|
290
|
+
delete-branch: true
|
|
291
|
+
title: 'chore: manual ${{ github.event.inputs.bump_type }} release'
|
|
292
|
+
body: |
|
|
293
|
+
## Manual Release Request
|
|
294
|
+
|
|
295
|
+
This PR was created by a manual workflow trigger to prepare a **${{ github.event.inputs.bump_type }}** release.
|
|
296
|
+
|
|
297
|
+
### Release Details
|
|
298
|
+
- **Type:** ${{ github.event.inputs.bump_type }}
|
|
299
|
+
- **Description:** ${{ github.event.inputs.description || 'Manual release' }}
|
|
300
|
+
- **Triggered by:** @${{ github.actor }}
|
|
301
|
+
|
|
302
|
+
### Next Steps
|
|
303
|
+
1. Review the changeset in this PR
|
|
304
|
+
2. Merge this PR to main
|
|
305
|
+
3. The automated release workflow will create a version PR
|
|
306
|
+
4. Merge the version PR to publish to npm and create a GitHub release
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# gh-setup-git-identity
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b8ecb63: Update CI/CD pipeline and testing framework to match test-anywhere patterns
|
|
8
|
+
|
|
9
|
+
- Consolidate GitHub Actions workflow into single release.yml file
|
|
10
|
+
- Add unified test matrix for Node.js, Bun, and Deno across Ubuntu, macOS, and Windows
|
|
11
|
+
- Add Node.js scripts for release automation (validate-changeset, version-and-commit, publish-to-npm, etc.)
|
|
12
|
+
- Add support for manual releases via workflow_dispatch (instant and changeset-pr modes)
|
|
13
|
+
- Add npm OIDC trusted publishing support
|
|
14
|
+
- Add GitHub release formatting with shields.io badges and PR links
|
|
15
|
+
- Update changeset configuration to use @changesets/cli/changelog
|
|
16
|
+
- Add changeset:status script for checking changeset status
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# gh-setup-git-identity
|
|
2
|
+
|
|
3
|
+
A tool to setup git identity based on current GitHub user.
|
|
4
|
+
|
|
5
|
+
[](http://unlicense.org/)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
`gh-setup-git-identity` is a CLI tool that simplifies setting up your git identity using your GitHub account. It automatically fetches your GitHub username and primary email address, then configures git with these values.
|
|
11
|
+
|
|
12
|
+
Instead of manually running:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
gh auth login -h github.com -s repo,workflow,user,read:org,gist
|
|
16
|
+
|
|
17
|
+
USERNAME=$(gh api user --jq '.login')
|
|
18
|
+
EMAIL=$(gh api user/emails --jq '.[] | select(.primary==true) | .email')
|
|
19
|
+
|
|
20
|
+
git config --global user.name "$USERNAME"
|
|
21
|
+
git config --global user.email "$EMAIL"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
You can simply run:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
gh-setup-git-identity
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **Automatic identity setup**: Fetches username and email from GitHub
|
|
33
|
+
- **Global and local configuration**: Configure git globally or per-repository
|
|
34
|
+
- **Authentication check**: Prompts you to login if not authenticated
|
|
35
|
+
- **Dry-run mode**: Preview changes without making them
|
|
36
|
+
- **Cross-platform**: Works on macOS, Linux, and Windows
|
|
37
|
+
- **Verbose mode**: Built-in verbose mode for debugging
|
|
38
|
+
|
|
39
|
+
## Prerequisites
|
|
40
|
+
|
|
41
|
+
- Node.js >= 20.0.0
|
|
42
|
+
- Git (installed and configured)
|
|
43
|
+
- GitHub CLI (`gh`) installed
|
|
44
|
+
|
|
45
|
+
To install GitHub CLI, see: https://cli.github.com/
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
### Global Installation (CLI)
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install -g gh-setup-git-identity
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Local Installation (Library)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install gh-setup-git-identity
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## CLI Usage
|
|
62
|
+
|
|
63
|
+
### Basic Usage
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Setup git identity globally (default)
|
|
67
|
+
gh-setup-git-identity
|
|
68
|
+
|
|
69
|
+
# Setup git identity for current repository only
|
|
70
|
+
gh-setup-git-identity --local
|
|
71
|
+
|
|
72
|
+
# Preview what would be configured (dry run)
|
|
73
|
+
gh-setup-git-identity --dry-run
|
|
74
|
+
|
|
75
|
+
# Enable verbose output
|
|
76
|
+
gh-setup-git-identity --verbose
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### CLI Options
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
Usage: gh-setup-git-identity [options]
|
|
83
|
+
|
|
84
|
+
Options:
|
|
85
|
+
--global, -g Set git config globally (default: true)
|
|
86
|
+
--local, -l Set git config locally (in current repository)
|
|
87
|
+
--dry-run, --dry Dry run - show what would be done without making changes
|
|
88
|
+
--verbose, -v Enable verbose output
|
|
89
|
+
--help, -h Show help
|
|
90
|
+
--version Show version number
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### First Run (Not Authenticated)
|
|
94
|
+
|
|
95
|
+
If you haven't authenticated with GitHub CLI yet, the tool will prompt you:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
GitHub CLI is not authenticated.
|
|
99
|
+
|
|
100
|
+
Please run the following command to login:
|
|
101
|
+
|
|
102
|
+
gh auth login -h github.com -s repo,workflow,user,read:org,gist
|
|
103
|
+
|
|
104
|
+
After logging in, run gh-setup-git-identity again.
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Successful Run
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
Fetching GitHub user information...
|
|
111
|
+
GitHub user: your-username
|
|
112
|
+
GitHub email: your-email@example.com
|
|
113
|
+
|
|
114
|
+
Configuring git (global)...
|
|
115
|
+
Git identity configured successfully!
|
|
116
|
+
|
|
117
|
+
Git configured:
|
|
118
|
+
|
|
119
|
+
user.name: your-username
|
|
120
|
+
user.email: your-email@example.com
|
|
121
|
+
|
|
122
|
+
Scope: global (--global)
|
|
123
|
+
|
|
124
|
+
Git identity setup complete!
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Library Usage
|
|
128
|
+
|
|
129
|
+
### Basic Example
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
import { setupGitIdentity, isGhAuthenticated } from 'gh-setup-git-identity';
|
|
133
|
+
|
|
134
|
+
// Check if authenticated first
|
|
135
|
+
const authenticated = await isGhAuthenticated();
|
|
136
|
+
if (!authenticated) {
|
|
137
|
+
console.log('Please run: gh auth login');
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Setup git identity
|
|
142
|
+
const result = await setupGitIdentity();
|
|
143
|
+
console.log('Configured:', result.username, result.email);
|
|
144
|
+
|
|
145
|
+
// Setup with options
|
|
146
|
+
const result2 = await setupGitIdentity({
|
|
147
|
+
scope: 'local', // 'global' or 'local'
|
|
148
|
+
dryRun: true, // Preview only
|
|
149
|
+
verbose: true // Enable verbose logging
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### API Reference
|
|
154
|
+
|
|
155
|
+
#### `isGhAuthenticated(options?)`
|
|
156
|
+
|
|
157
|
+
Check if GitHub CLI is authenticated.
|
|
158
|
+
|
|
159
|
+
**Returns:** `Promise<boolean>`
|
|
160
|
+
|
|
161
|
+
#### `getGitHubUserInfo(options?)`
|
|
162
|
+
|
|
163
|
+
Get GitHub user information (username and primary email).
|
|
164
|
+
|
|
165
|
+
**Returns:** `Promise<{username: string, email: string}>`
|
|
166
|
+
|
|
167
|
+
#### `setupGitIdentity(options?)`
|
|
168
|
+
|
|
169
|
+
Setup git identity based on GitHub user.
|
|
170
|
+
|
|
171
|
+
**Parameters:**
|
|
172
|
+
- `options.scope` - `'global'` or `'local'` (default: `'global'`)
|
|
173
|
+
- `options.dryRun` - Preview only, don't make changes (default: `false`)
|
|
174
|
+
- `options.verbose` - Enable verbose logging (default: `false`)
|
|
175
|
+
- `options.logger` - Custom logger (default: `console`)
|
|
176
|
+
|
|
177
|
+
**Returns:** `Promise<{username: string, email: string}>`
|
|
178
|
+
|
|
179
|
+
#### `verifyGitIdentity(options?)`
|
|
180
|
+
|
|
181
|
+
Get current git identity configuration.
|
|
182
|
+
|
|
183
|
+
**Returns:** `Promise<{username: string|null, email: string|null}>`
|
|
184
|
+
|
|
185
|
+
## Configuration
|
|
186
|
+
|
|
187
|
+
### Environment Variables
|
|
188
|
+
|
|
189
|
+
- `GH_SETUP_GIT_IDENTITY_GLOBAL` - Set global config (default: `true`)
|
|
190
|
+
- `GH_SETUP_GIT_IDENTITY_LOCAL` - Set local config (default: `false`)
|
|
191
|
+
- `GH_SETUP_GIT_IDENTITY_DRY_RUN` - Enable dry run mode (default: `false`)
|
|
192
|
+
- `GH_SETUP_GIT_IDENTITY_VERBOSE` - Enable verbose output (default: `false`)
|
|
193
|
+
|
|
194
|
+
## Testing
|
|
195
|
+
|
|
196
|
+
Run tests using your preferred runtime:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Node.js
|
|
200
|
+
npm test
|
|
201
|
+
|
|
202
|
+
# Bun
|
|
203
|
+
bun test
|
|
204
|
+
|
|
205
|
+
# Deno
|
|
206
|
+
deno test --allow-all
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Development
|
|
210
|
+
|
|
211
|
+
### Project Structure
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
gh-setup-git-identity/
|
|
215
|
+
├── src/
|
|
216
|
+
│ ├── index.js # Core library
|
|
217
|
+
│ └── cli.js # CLI interface
|
|
218
|
+
├── test/
|
|
219
|
+
│ └── index.test.js # Tests
|
|
220
|
+
├── .changeset/ # Changesets for versioning
|
|
221
|
+
├── .github/
|
|
222
|
+
│ └── workflows/ # CI/CD workflows
|
|
223
|
+
├── package.json
|
|
224
|
+
└── README.md
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Contributing
|
|
228
|
+
|
|
229
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
230
|
+
|
|
231
|
+
## License
|
|
232
|
+
|
|
233
|
+
This is free and unencumbered software released into the public domain. See [LICENSE](LICENSE) for details.
|
|
234
|
+
|
|
235
|
+
## Links
|
|
236
|
+
|
|
237
|
+
- GitHub Repository: https://github.com/link-foundation/gh-setup-git-identity
|
|
238
|
+
- Issue Tracker: https://github.com/link-foundation/gh-setup-git-identity/issues
|
|
239
|
+
- Link Foundation: https://github.com/link-foundation
|
|
240
|
+
|
|
241
|
+
## Related Projects
|
|
242
|
+
|
|
243
|
+
- [gh-upload-log](https://github.com/link-foundation/gh-upload-log) - Upload log files to GitHub
|
|
244
|
+
- [lino-arguments](https://github.com/link-foundation/lino-arguments) - CLI argument parsing
|
|
245
|
+
- [log-lazy](https://github.com/link-foundation/log-lazy) - Efficient lazy evaluation logging
|
|
246
|
+
- [command-stream](https://github.com/link-foundation/command-stream) - Streamable commands
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gh-setup-git-identity",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A tool to setup git identity based on current gh user",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"gh-setup-git-identity": "src/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node --test test/index.test.js",
|
|
12
|
+
"test:bun": "bun test",
|
|
13
|
+
"test:deno": "deno test --allow-all",
|
|
14
|
+
"lint": "node --check src/index.js && node --check src/cli.js",
|
|
15
|
+
"changeset": "changeset",
|
|
16
|
+
"changeset:version": "node scripts/changeset-version.mjs",
|
|
17
|
+
"changeset:publish": "changeset publish",
|
|
18
|
+
"changeset:status": "changeset status --since=origin/main"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"github",
|
|
22
|
+
"git",
|
|
23
|
+
"identity",
|
|
24
|
+
"config",
|
|
25
|
+
"cli",
|
|
26
|
+
"setup"
|
|
27
|
+
],
|
|
28
|
+
"author": "Link Foundation",
|
|
29
|
+
"license": "Unlicense",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/link-foundation/gh-setup-git-identity.git"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20.0.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"lino-arguments": "^0.2.1",
|
|
39
|
+
"log-lazy": "^1.0.4",
|
|
40
|
+
"yargs": "^17.7.2"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@changesets/cli": "^2.29.7",
|
|
44
|
+
"test-anywhere": "^0.7.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom changeset version script that ensures package-lock.json is synchronized
|
|
5
|
+
* with package.json after version bumps.
|
|
6
|
+
*
|
|
7
|
+
* This script:
|
|
8
|
+
* 1. Runs `changeset version` to update package versions
|
|
9
|
+
* 2. Runs `npm install` to synchronize package-lock.json with the new versions
|
|
10
|
+
*
|
|
11
|
+
* Uses link-foundation libraries:
|
|
12
|
+
* - use-m: Dynamic package loading without package.json dependencies
|
|
13
|
+
* - command-stream: Modern shell command execution with streaming support
|
|
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 command-stream for shell command execution
|
|
22
|
+
const { $ } = await use('command-stream');
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
console.log('Running changeset version...');
|
|
26
|
+
await $`npx changeset version`;
|
|
27
|
+
|
|
28
|
+
console.log('\nSynchronizing package-lock.json...');
|
|
29
|
+
await $`npm install --package-lock-only`;
|
|
30
|
+
|
|
31
|
+
console.log('\nVersion bump complete with synchronized package-lock.json');
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error('Error during version bump:', error.message);
|
|
34
|
+
if (process.env.DEBUG) {
|
|
35
|
+
console.error('Stack trace:', error.stack);
|
|
36
|
+
}
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|