Skip to content

Commit

Permalink
Add Changesets to release fnm (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz authored Jul 3, 2022
1 parent fd2a6eb commit 6e6bdd8
Show file tree
Hide file tree
Showing 13 changed files with 3,465 additions and 872 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
5 changes: 5 additions & 0 deletions .changeset/clever-carrots-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

Add changesets
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
13 changes: 0 additions & 13 deletions .ci/generate-changelog.sh

This file was deleted.

35 changes: 19 additions & 16 deletions .ci/prepare-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@ const cp = require("child_process");
const path = require("path");
const cmd = require("cmd-ts");
const toml = require("toml");
const assert = require("assert");

const CARGO_TOML_PATH = path.join(__dirname, "../Cargo.toml");

const command = cmd.command({
name: "prepare-version",
description: "Prepare a new fnm version",
args: {
versionType: cmd.positional({
displayName: "version type",
type: cmd.oneOf(["patch", "minor", "major"]),
}),
},
async handler({ versionType }) {
exec("git pull --ff-only");
const nextVersion = updateCargoToml(versionType);
args: {},
async handler({}) {
updateCargoToml(await getPackageVersion());
exec("cargo build --release");
exec("yarn generate-command-docs --binary-path=./target/release/fnm");
exec("./docs/record_screen.sh");
exec(`yarn changelog ${nextVersion}`);
exec("./.ci/record_screen.sh");
},
});

Expand All @@ -35,14 +29,23 @@ cmd.run(cmd.binary(command), process.argv);
// Helper functions //
//////////////////////

function updateCargoToml(versionType) {
/**
* @returns {Promise<string>}
*/
async function getPackageVersion() {
const pkgJson = await fs.promises.readFile(
path.join(__dirname, "../package.json"),
"utf8"
);
const version = JSON.parse(pkgJson).version;
assert(version, "package.json version is not set");
return version;
}

function updateCargoToml(nextVersion) {
const cargoToml = fs.readFileSync(CARGO_TOML_PATH, "utf8");
const cargoTomlContents = toml.parse(cargoToml);
const currentVersion = cargoTomlContents.package.version;
const nextVersion = changeVersion(
versionType,
cargoTomlContents.package.version
);

const newToml = cargoToml.replace(
`version = "${currentVersion}"`,
Expand Down
10 changes: 8 additions & 2 deletions docs/record_screen.sh → .ci/record_screen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
DIRECTORY="$(dirname "$0")"

function setup_binary() {
TEMP_DIR="$(mktemp -d -t fnm)"
TEMP_DIR="/tmp/fnm-$(date '+%s')"
mkdir "$TEMP_DIR"
cp ./target/release/fnm "$TEMP_DIR/fnm"
export PATH=$TEMP_DIR:$PATH
export FNM_DIR=$TEMP_DIR/.fnm
Expand All @@ -20,4 +21,9 @@ RECORDING_PATH=$DIRECTORY/screen_recording
(rm -rf "$RECORDING_PATH" &> /dev/null || true)

asciinema rec -c "$DIRECTORY/recorded_screen_script.sh" "$RECORDING_PATH"
sed "s@$TEMP_DIR@~@g" "$RECORDING_PATH" | svg-term --window --out "$DIRECTORY/fnm.svg" --height=17 --width=70
sed "s@$TEMP_DIR@~@g" "$RECORDING_PATH" | \
svg-term \
--window \
--out "docs/fnm.svg" \
--height=17 \
--width=70
11 changes: 7 additions & 4 deletions docs/recorded_screen_script.sh → .ci/recorded_screen_script.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/bin/zsh
#!/bin/bash

set -e

GAL_PROMPT_PREFIX='\e[34m✡ \e[0m'
export PATH=$PATH_ADDITION:$PATH

GAL_PROMPT_PREFIX="\e[34m✡\e[m "

function type() {
printf $GAL_PROMPT_PREFIX
echo $* | pv -qL $[10+(-2 + RANDOM%5)]
echo -n " "
echo $* | node .ci/type-letters.js
}

type 'eval "$(fnm env)"'
eval `fnm env`
eval "$(fnm env)"

type 'fnm --version'
fnm --version
Expand Down
13 changes: 13 additions & 0 deletions .ci/type-letters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(async () => {
for await (const chunk of process.stdin) {
const letters = chunk.toString("utf8").split("");
for (const letter of letters) {
process.stdout.write(letter);
await sleep(Math.random() * 100 + 20);
}
}
})();

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: release
on:
push:
branches:
- master
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:

create_pull_request:
runs-on: ubuntu-latest
steps:
# set up
- uses: actions/checkout@v3

- uses: hecrj/setup-rust-action@v1
with:
rust-version: stable

- uses: Swatinem/rust-cache@v1

- uses: pnpm/action-setup@v2.2.1
with:
run_install: false

# pnpm
- uses: actions/setup-node@v2
with:
node-version: 16.x
cache: 'pnpm'

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install script dependencies
run: |
sudo apt-get update
sudo apt-get install -y asciinema
- name: Install Node.js project dependencies
run: pnpm install

- name: Create Release Pull Request
uses: changesets/action@v1
with:
version: "pnpm version:prepare"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TERM: xterm
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
docs/screen_recording
.ci/screen_recording
/benchmarks/results
/target
**/*.rs.bk
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "fnm",
"version": "0.0.0",
"version": "1.31.0",
"private": true,
"repository": "git@github.com:Schniz/fnm.git",
"author": "Gal Schlezinger <gal@spitfire.co.il>",
"packageManager": "pnpm@7.3.0",
"license": "GPLv3",
"scripts": {
"changelog": "./.ci/generate-changelog.sh",
"version:prepare": "./.ci/prepare-version.js",
"version:prepare": "changeset version && ./.ci/prepare-version.js",
"generate-command-docs": "./.ci/print-command-docs.js"
},
"changelog": {
Expand All @@ -20,10 +20,13 @@
}
},
"devDependencies": {
"@changesets/cli": "^2.23.0",
"cmd-ts": "0.10.1",
"execa": "5.1.1",
"lerna-changelog": "2.2.0",
"prettier": "2.6.2",
"pv": "^1.0.1",
"svg-term-cli": "^2.1.1",
"toml": "3.0.0"
}
}
Loading

0 comments on commit 6e6bdd8

Please sign in to comment.