Skip to content

Commit e48fe85

Browse files
authored
Merge pull request #11 from sam-mfb/release_1.2
Release 1.2
2 parents 4b1dd71 + dd5cbde commit e48fe85

File tree

9 files changed

+431
-239
lines changed

9 files changed

+431
-239
lines changed

.github/workflows/npm-publish.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: '18.x'
15+
registry-url: 'https://registry.npmjs.org'
16+
17+
- name: Install pnpm
18+
uses: pnpm/action-setup@v2
19+
with:
20+
version: 8
21+
run_install: false
22+
23+
- name: Get pnpm store directory
24+
shell: bash
25+
run: |
26+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
27+
28+
- uses: actions/cache@v3
29+
name: Setup pnpm cache
30+
with:
31+
path: ${{ env.STORE_PATH }}
32+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
33+
restore-keys: |
34+
${{ runner.os }}-pnpm-store-
35+
36+
- name: Install dependencies
37+
run: pnpm install
38+
39+
- name: Lint
40+
run: pnpm run lint
41+
42+
- name: Build
43+
run: pnpm run build
44+
45+
- name: Test
46+
run: pnpm test -- --watchAll=false
47+
48+
- name: Publish to npm
49+
run: pnpm publish --no-git-checks
50+
env:
51+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [18.x, 20.x]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
23+
- name: Install pnpm
24+
uses: pnpm/action-setup@v2
25+
with:
26+
version: 8
27+
run_install: false
28+
29+
- name: Get pnpm store directory
30+
shell: bash
31+
run: |
32+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
33+
34+
- uses: actions/cache@v3
35+
name: Setup pnpm cache
36+
with:
37+
path: ${{ env.STORE_PATH }}
38+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39+
restore-keys: |
40+
${{ runner.os }}-pnpm-store-
41+
42+
- name: Install dependencies
43+
run: pnpm install
44+
45+
- name: Lint
46+
run: pnpm run lint
47+
48+
- name: Build
49+
run: pnpm run build
50+
51+
- name: Run tests
52+
run: pnpm test -- --watchAll=false

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
node_modules
2-
dist
2+
dist
3+
*.tgz
4+
.npmrc
5+
.npm
6+
npm-debug.log*

README.md

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,66 @@ Because this helper is designed to allow sharing credentials on the same machine
1010

1111
## Installation and Usage
1212

13-
This helper is written in Typescript and compiles down to two Javascript scripts, one for the server and one for the client.
13+
This helper is written in TypeScript and can be installed globally via npm or pnpm.
1414

15-
### Download
15+
### Installation Options
1616

17-
Download the latest release from this repo. The release consists of a filed named `git-credential-forwarder.zip` which contains two Javascript scripts: `gcf-server.js` and `gcf-client.js`. These can be placed wherever you want, but these instructions assume they are placed in the home directories of the host and container.
17+
#### Global Installation (Recommended)
18+
19+
Install the package globally using npm or pnpm:
20+
21+
```
22+
npm install -g git-credential-forwarder
23+
# or
24+
pnpm add -g git-credential-forwarder
25+
```
26+
27+
This will make the commands `gcf-server` and `gcf-client` available globally.
28+
29+
#### Manual Download
30+
31+
Alternatively, you can download the latest release from this repo. The release consists of a file named `git-credential-forwarder.zip` which contains two JavaScript scripts: `gcf-server.js` and `gcf-client.js`. These can be placed wherever you want.
32+
33+
After downloading, make the scripts executable:
34+
35+
```
36+
chmod +x gcf-server.js gcf-client.js
37+
```
1838

1939
### On the host
2040

21-
Run `node ~/gcf-server.js`. This will launch the server and it will listen for TCP connections on localhost at a random port which will be displayed in the console. You will need to keep this console/terminal open.
41+
If installed globally:
42+
```
43+
gcf-server
44+
```
45+
46+
If using manual download:
47+
```
48+
./gcf-server.js
49+
```
50+
51+
This will launch the server and it will listen for TCP connections on localhost at a random port which will be displayed in the console. You will need to keep this console/terminal open.
2252

2353
Notes:
2454

2555
- You can tell it to use a specific port by setting the environmental variable `GIT_CREDENTIAL_FORWARDER_PORT`
2656

2757
### In the container
2858

29-
Run `export GIT_CREDENTIAL_FORWARDER_SERVER="host.Docker.internal:PORT` where PORT is replaced with the port displayed when you ran the server.
59+
Run `export GIT_CREDENTIAL_FORWARDER_SERVER="host.docker.internal:PORT"` where PORT is replaced with the port displayed when you ran the server.
60+
61+
Edit your git configuration file to call the client as a git credential helper:
3062

31-
Edit your git configuration file to call the client you just complied as a git credential helper, as follows:
63+
If installed globally:
64+
```
65+
[credential]
66+
helper = "!f() { gcf-client $*; }; f"
67+
```
3268

69+
If using manual download:
3370
```
3471
[credential]
35-
helper = "!f() { node ~/gcf-client.js $*; }; f"
72+
helper = "!f() { /path/to/gcf-client.js $*; }; f"
3673
```
3774

3875
Run git normally and all requests for credentials should be passed through to the host which will handle appropriately on the host side.
@@ -46,14 +83,33 @@ Notes:
4683

4784
Here's a strategy to make this fairly easy to use with a Docker container built with a Dockerfile.
4885

86+
#### Option 1: Using npm or pnpm (Recommended)
87+
88+
On the host, set a specific port that you will listen on by configuring the env variable `GIT_CREDENTIAL_FORWARDER_PORT`.
89+
90+
Add these lines in the Dockerfile:
91+
92+
```
93+
# Install Node.js and npm/pnpm first if needed
94+
RUN npm install -g git-credential-forwarder
95+
# or
96+
RUN pnpm add -g git-credential-forwarder
97+
98+
RUN git config --global credential.helper '!f(){ gcf-client $*; }; f'
99+
ENV GIT_CREDENTIAL_FORWARDER_SERVER host.docker.internal:[PORT]
100+
```
101+
102+
#### Option 2: Using direct download
103+
49104
On the host, set a specific port that you will listen on by configuring the env variable `GIT_CREDENTIAL_FORWARDER_PORT`.
50105

51-
Add these lines in the Dockerfile
106+
Add these lines in the Dockerfile:
52107

53108
```
54109
RUN curl -LO https://github.com/sam-mfb/git-credential-forwarder/releases/download/v[VERSION]/git-credential-forwarder.zip
55-
RUN unzip git-credential-forwarder.zip
56-
RUN git config --global credential.helper '!f(){ node ~/gcf-client.js $*; }; f'
110+
RUN unzip git-credential-forwarder.zip -d /usr/local/bin
111+
RUN chmod +x /usr/local/bin/gcf-*.js
112+
RUN git config --global credential.helper '!f(){ /usr/local/bin/gcf-client.js $*; }; f'
57113
ENV GIT_CREDENTIAL_FORWARDER_SERVER host.docker.internal:[PORT]
58114
```
59115

@@ -77,6 +133,21 @@ Note that this will not work from a Mac OS host per [this Docker issue](https://
77133

78134
You can enable debugging on either the server or the client by setting the environmental variable `GIT_CREDENTIAL_FORWARDER_DEBUG` to `true`.
79135

136+
## Development
137+
138+
### Publishing to npm
139+
140+
This project uses GitHub Actions to automatically publish to npm when a new release is created. To set this up:
141+
142+
1. Generate an npm token with publish permissions
143+
2. Add the token as a GitHub repository secret named `NPM_TOKEN`
144+
3. Update the version in package.json
145+
4. Commit the changes and push to GitHub
146+
5. Create a new tag for the release: `git tag v1.x.x && git push --tags`
147+
6. Create a new release on GitHub using the tag to trigger the publishing workflow
148+
149+
The GitHub Actions workflow will use pnpm to build, test, and publish the package to the npm registry.
150+
80151
## Security
81152

82153
Nothing is perfectly secure, but I have tried to think through the security implications of running a helper like this. Here are some thoughts and I would definitely welcome any others in the issues or discussions sections:

add-shebang.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
// Add shebang and make files executable for global npm installation
6+
const shebang = '#!/usr/bin/env node\n';
7+
const files = ['gcf-server.js', 'gcf-client.js'];
8+
const distDir = path.join(__dirname, 'dist');
9+
10+
for (const file of files) {
11+
const filePath = path.join(distDir, file);
12+
13+
if (fs.existsSync(filePath)) {
14+
const content = fs.readFileSync(filePath, 'utf8');
15+
16+
// Only add shebang if it doesn't already exist
17+
if (!content.startsWith('#!')) {
18+
fs.writeFileSync(filePath, shebang + content);
19+
console.log(`Added shebang to ${file}`);
20+
21+
// Make file executable
22+
try {
23+
fs.chmodSync(filePath, '755');
24+
console.log(`Made ${file} executable`);
25+
} catch (error) {
26+
console.error(`Failed to make ${file} executable:`, error.message);
27+
}
28+
} else {
29+
console.log(`Shebang already exists in ${file}`);
30+
}
31+
} else {
32+
console.error(`File ${file} does not exist in dist directory`);
33+
}
34+
}

0 commit comments

Comments
 (0)