Skip to content

Commit 6f516df

Browse files
committed
Add an install-fish action.
1 parent 7134dff commit 6f516df

13 files changed

Lines changed: 1021 additions & 1 deletion

File tree

.github/workflows/CI.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This is for testing `actions-workflows` itself.
2+
3+
name: CI
4+
5+
on: [push, pull_request]
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: oven-sh/setup-bun@v2
14+
- run: make setup
15+
- run: make lint
16+
17+
fish:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- run: ls /home/runner/work/actions-workflows/actions-workflows/.github/workflows/
22+
- uses: ./actions/install-fish
23+
- run: fish --version

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.PHONY: lint
2+
lint: setup
3+
bun x -- bun-dx --package @biomejs/biome biome -- check
4+
bun x -- bun-dx --package typescript tsc -- --project ./
5+
6+
.PHONY: format
7+
format: setup
8+
bun x -- bun-dx --package @biomejs/biome biome -- check --write
9+
10+
.PHONY: setup
11+
setup:
12+
bun install --frozen-lockfile
13+
14+
.PHONY: install-fish
15+
install-fish: setup
16+
bun run -- ./script/install-fish.ts
17+
18+
.PHONY: clean
19+
clean:
20+
# no-op
21+
22+
.PHONY: reset
23+
reset: clean
24+
rm -rf ./node_modules/

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GitHub Actions workflows
22

3-
[Reusable GitHub Actions workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows) for https://github.com/cubing projects.
3+
[Reusable GitHub Actions workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows) for <https://github.com/cubing> projects.
44

55
## Publish GitHub release
66

@@ -27,3 +27,20 @@ jobs:
2727
uses: cubing/actions-workflows/.github/workflows/publish-github-release.yaml@main
2828
CONTENTS
2929
```
30+
31+
## Install `fish`
32+
33+
Installs `fish` from: <https://github.com/fish-shell/fish-shell/releases>
34+
35+
Because `fish` is already compiled, this is *much* faster than other actions that install from source.
36+
37+
Usage:
38+
39+
```yaml
40+
uses: cubing/actions-workflows/actions/install-fish@main
41+
```
42+
43+
At the moment:
44+
45+
- There is no option to select the `fish` version — a recent version is hardcoded.
46+
- Only Linux x64 is supported.

actions/install-fish/action.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Install `fish`
2+
description: Installs `fish` to `~/.local/share/install-fish/bin/fish`
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Install `bun`
8+
uses: oven-sh/setup-bun@b7a1c7ccf290d58743029c4f6903da283811b979
9+
- name: Add `~/.local/share/install-fish/bin` to `$PATH`
10+
shell: bash
11+
run: echo "$HOME/.local/share/install-fish/bin" >> "$GITHUB_PATH"
12+
- name: PATH
13+
shell: bash
14+
run: echo "$PATH"
15+
- name: Install `fish` to `~/.local/share/install-fish/bin/fish`
16+
shell: bash
17+
run: bun run ${{ github.action_path }}/install-fish.ts
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env -S bun run --
2+
3+
/**
4+
* Note: this file does not use any run-time dependencies, only `bun` built-ins.
5+
* This is less ergonomic, but it allows running the script directly, which in
6+
* turn means fewer opportunities for things to go wrong.
7+
*/
8+
9+
import assert from "node:assert";
10+
import { mkdir, mkdtemp, readFile, rename } from "node:fs/promises";
11+
import { arch, homedir, platform, tmpdir } from "node:os";
12+
import { dirname, join } from "node:path";
13+
import { env, exit } from "node:process";
14+
import { $, write } from "bun";
15+
16+
const BIN_INSTALLATION_DIR = join(
17+
homedir(),
18+
"./.local/share/install-fish/bin/fish",
19+
);
20+
const BIN_INSTALLATION_PATH = join(BIN_INSTALLATION_DIR, "./fish");
21+
22+
console.log("PATH", env["PATH"]);
23+
24+
const metadata: { [version: string]: { url: string; hash: string } } = {
25+
"4.3.3": {
26+
url: "https://github.com/fish-shell/fish-shell/releases/download/4.3.3/fish-4.3.3-linux-x86_64.tar.xz",
27+
hash: "3759c788d7941c5d0ca7713b259612211f4efb9041426ea415aaa8e4022d3392",
28+
},
29+
};
30+
31+
async function installFish(version: string = "4.3.3"): Promise<void> {
32+
assert(metadata[version]);
33+
const { url, hash } = metadata[version];
34+
35+
assert.equal(platform(), "linux");
36+
assert.equal(arch(), "x64");
37+
38+
try {
39+
await $`fish --version`;
40+
console.log("Able to execute `fish`. Skipping installation.");
41+
exit(0);
42+
} catch {
43+
console.log("Unable to execute `fish`. Proceeding with installation.");
44+
}
45+
46+
const tempDir = await mkdtemp(join(tmpdir(), "install-fish-"));
47+
const tempArchive = join(tempDir, "./fish.tar.xz");
48+
await write(tempArchive, await fetch(url));
49+
assert.equal(
50+
new Uint8Array(
51+
await globalThis.crypto.subtle.digest(
52+
"SHA256",
53+
// The `new Uint8Array(…)` is not necessary, but it makes the type checker happy.
54+
new Uint8Array(await readFile(tempArchive)),
55+
),
56+
).toHex(),
57+
hash,
58+
);
59+
60+
await $`cd ${tempDir} && tar -xJvf ${tempArchive}`;
61+
await mkdir(dirname(BIN_INSTALLATION_PATH), { recursive: true });
62+
await rename(join(tempDir, "fish"), BIN_INSTALLATION_PATH);
63+
64+
console.log("Installed fish version:");
65+
await $`fish --version`;
66+
}
67+
68+
await installFish();

biome.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"extends": ["./node_modules/@cubing/dev-config/biome/biome.json"],
4+
"files": {
5+
"includes": ["**", "!!dist"]
6+
}
7+
}

bun.lock

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bunfig.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[install]
2+
auto = "disable"
3+
linker = "isolated"

0 commit comments

Comments
 (0)