Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbhmr authored Jun 22, 2024
1 parent 508612c commit 7a70eac
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: npm publish
on:
release:
types: released
types: published
workflow_dispatch:
inputs:
tag:
Expand Down Expand Up @@ -30,4 +30,4 @@ jobs:
- run: npm publish --provenance --tag "$TAG"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
TAG: ${{ inputs.tag }}
TAG: ${{ inputs.tag || ((github.event.release.prerelease && 'next') || 'latest') }}
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,35 @@ console.log(cut);
//=> 'C:\\myproject\\node_modules\\portablegit\\out\\portablegit\\usr\\bin\\cut'
```

This can be useful if you need to resolve the path to a specific binary (`cat.exe`, `cut.exe`, etc.) that isn't exposed by default. Note that you don't need to use the `.exe` suffix since Windows will helpfully add `.exe` suffix when attempting to run the file.
This can be useful if you need to resolve the path to a specific binary (`cat.exe`, `cut.exe`, etc.) that isn't exposed by default.

## Development

![Node.js](https://img.shields.io/static/v1?style=for-the-badge&message=Node.js&color=339933&logo=Node.js&logoColor=FFFFFF&label=)
![Windows](https://img.shields.io/static/v1?style=for-the-badge&message=Windows&color=0078D4&logo=Windows&logoColor=FFFFFF&label=)

You'll need a Windows computer to test this package locally. You can run `npm run build` to make sure everything looks good locally. `npm run generate` redownloads the configured version of Git for Windows PortableGit as a 7zip self-extracting archive.

Each new upcoming release will first be tried as a prerelease `X.Y.Z-rc.N` first to make sure that everything is 99% guarenteed to work when autopublishing. Make sure to `--tag next`!

This package currently relies on **manual updates** to bump the Git for Windows version. Make sure you update the `version` field in `package.json` and the `gfwVersion` and `filename` constants in `scripts.js` `generate()`.

You can publish a release to GitHub releases and npm using [the npm publish GitHub actions workflow](https://github.com/jcbhmr/portablegit.js/actions/workflows/npm-publish.yml).
- You'll need a Windows computer to test this package locally.
- You can run `npm run build` to make sure everything looks good locally.
- `npm run generate` redownloads the configured version of Git for Windows PortableGit as a 7zip self-extracting archive.
- Each new upcoming release should first be tried as a prerelease `X.Y.Z-rc.N`.
- This package currently relies on **manual updates** to bump the Git for Windows version.
- Make sure you update the `version` field in `package.json` and the constants in `scripts.js` `generate()`.
- This project may in the future start squashing Git history or use Git LFS to reduce the repository size.

Steps to release:

1. Change the version in `package.json` to the new version RC like `2.45.21-rc.1`.
2. Change the version in `scripts.js` `generate()` to the new version tag like `2.45.2.windows.1`.
3. Change the file name in `scripts.js` `generate()` to the new version tag like `PortableGit-2.45.2-64-bit.7z.exe`.
4. Run `npm run generate` to vendor the new version.
5. Run `npm run build` and `npm test` to make sure everything works. Check that `git --version` matches the new version.
6. Push to GitHub.
7. Create a new release on GitHub with the new `v2.45.21-rc.1` tag.
8. Watch and wait for CI to pass. This will publush a `next` `2.45.21-rc.1` version to npm.
9. Make sure it works using `npx -p portablegit@next git --version` or similar.
10. Change the version in `package.json` to the new version like `2.45.21`.
11. Push to GitHub.
12. Create a new release on GitHub with the new `v2.45.21` tag.
13. Watch and wait for CI to pass. This will publish a `latest` `2.45.21` version to npm.

**TL;DR:** Do a prelease `-rc.1` first to make sure things work before doing the actual release. This lets us mirror the Git for Windows version numbers without a special suffix if we get things wrong.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"clean": "rimraf out",
"test": "node --test",
"format": "prettier -w .",
"postinstall": "node scripts.js postinstall"
"postinstall": "node scripts.js postinstall",
"squash": "node scripts.js squash"
},
"os": [
"win32"
Expand Down
39 changes: 30 additions & 9 deletions scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,55 @@ async function generate() {
console.debug("url=%o", url);
const response = await fetch(url);
assert(response.status === 200, `${response.status} ${response.url}`);
const dest = new URL(import.meta.resolve("./PortableGit-64-bit.7z.exe"))
await response.body.pipeTo(
Writable.toWeb(createWriteStream(dest)),
);
const dest = new URL(import.meta.resolve("./PortableGit-64-bit.7z.exe"));
await response.body.pipeTo(Writable.toWeb(createWriteStream(dest)));
console.log("Downloaded %s to %s", url, dest);
}

// POSTINSTALL RUNS WITH NO DEV DEPENDENCIES!
async function postinstall() {
const { $ } = await import("execa");
const { existsSync } = await import("node:fs");
const { sep } = await import("node:path")
const { fileURLToPath } = await import("node:url")
const { sep } = await import("node:path");
const { fileURLToPath } = await import("node:url");

if (process.env.INIT_CWD === process.cwd() || process.env.INIT_CWD?.startsWith(process.cwd() + sep)) {
if (
process.env.INIT_CWD === process.cwd() ||
process.env.INIT_CWD?.startsWith(process.cwd() + sep)
) {
// Skip! Local dev `npm install`, not as a dep.
console.debug("Skipping postinstall in local dev");
} else {
// May have already been installed once and had the files deleted.
if (existsSync(new URL(import.meta.resolve("./out/post-install.bat")))) {
await $({
const { failed, exitCode, signal, signalDescription, command } = await $({
cwd: fileURLToPath(import.meta.resolve("./out/")),
stdio: "inherit",
reject: false,
verbose: "short",
})`post-install.bat`;
if (failed) {
console.error("$ %o failed", command);
if (exitCode) {
console.error("exitCode=%o", exitCode);
} else if (signal) {
console.error(
"signal=%o signalDescription=%o",
signal,
signalDescription
);
}
}
} else {
// Assume already ran.
}
}
}

await { generate, postinstall }[process.argv[2]]();
async function squash() {
const { $ } = await import("execa");

await $({ stdio: "inherit", verbose: "short" })`git --version`;
}

await { generate, postinstall, squash }[process.argv[2]]();

0 comments on commit 7a70eac

Please sign in to comment.