Skip to content

Commit 82220db

Browse files
committed
+tea.xyz/brewkit
1 parent 59b4b5f commit 82220db

28 files changed

+1539
-0
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
on:
2+
pull_request:
3+
jobs:
4+
integration-tests:
5+
runs-on: ubuntu-latest
6+
env:
7+
GITHUB_TOKEN: ${{ github.token }}
8+
strategy:
9+
matrix:
10+
pkgs:
11+
- zlib.net
12+
- openssl.org curl.se/ca-certs
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: teaxyz/setup@v0
16+
17+
- uses: actions/cache@v3
18+
with:
19+
path: ${{ env.HOME }}/.cache/deno
20+
key: deno-get-platform-${{ hashFiles('deno.jsonc')}}
21+
22+
- name: prefetch deno deps
23+
# this makes the output from the build step more legible
24+
run: deno cache libexec/*.ts
25+
26+
- run: bin/build ${{matrix.pkgs}}
27+
id: build
28+
29+
- run: test -n '${{ steps.build.outputs.srcs }}'
30+
- run: test -n '${{ steps.build.outputs.pkgs }}'
31+
- run: test -n '${{ steps.build.outputs.srcs-relative-paths }}'
32+
- run: test -n '${{ steps.build.outputs.relative-paths }}'
33+
34+
- run: bin/test ${{matrix.pkgs}}
35+
36+
typecheck:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v3
40+
- uses: teaxyz/setup@v0
41+
- run: deno check libexec/*.ts

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.DS_Store
2+
/deno.lock

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"deno.enable": true,
3+
"deno.lint": true,
4+
"deno.unstable": true,
5+
"deno.config": "deno.jsonc",
6+
"deno.importMap": "../cli/import-map.json"
7+
}

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
![tea](https://tea.xyz/banner.png)
2+
3+
# BrewKit
4+
5+
The BrewKit builds packages.
6+
7+
```sh
8+
tea +tea.xyz/brewkit build zlib.net
9+
```
10+
11+
If you are inside a pantry and tea magic is installed you can omit package
12+
names, BrewKit will figure out what packages you are editing and build them.
13+
14+
```sh
15+
xc build
16+
```
17+
18+
Here [`xc`](xcfile.dev) reads the instructions from the pantry README to know
19+
to call the full command.

bin/build

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if test -n "$RUNNER_DEBUG" -a -n "$GITHUB_ACTIONS" -o -n "$VERBOSE"; then
6+
set -x
7+
fi
8+
9+
d="$(cd $(dirname $0)/.. && pwd)"
10+
PATH="$d/libexec:$PATH"
11+
12+
if test -z "$1"; then
13+
if test -z "$TEA_PANTRY_PATH"; then
14+
echo "error: TEA_PANTRY_PATH is not set" >&2
15+
exit 1
16+
fi
17+
for x in $(echo "$TEA_PANTRY_PATH" | tr ':' '\n'); do
18+
if test -d "$x"/.git; then
19+
PKGS="$(GIT_DIR="$x"/.git peek.sh) $PKGS"
20+
fi
21+
done
22+
else
23+
PKGS="$@"
24+
fi
25+
26+
if test -z "$GITHUB_TOKEN"; then
27+
export GITHUB_TOKEN=$(tea gh auth token)
28+
fi
29+
30+
# should one of these depend on the other:
31+
# ensure they are build in the correct order
32+
PKGS="$(sort.ts $PKGS --delimiter ' ')"
33+
34+
for PKG in $PKGS; do
35+
PKG="$(resolve.ts $PKG)"
36+
ZIP="$(query.ts $PKG --src)"
37+
PREFIX="$(query.ts $PKG --prefix)"
38+
SRCDIR="$(query.ts $PKG --srcdir)"
39+
40+
if test -n "$ZIP"; then
41+
fetch.ts $PKG -o "$ZIP"
42+
fi
43+
44+
if test -f "$ZIP"; then
45+
extract.ts "$ZIP" --pkg $PKG --output-dir "$SRCDIR"
46+
else
47+
mkdir -p "$SRCDIR"
48+
fi
49+
50+
DEPS=$(deps.ts $PKG --build) # eg. nodejs.org^4
51+
DEPS=$(install.ts $DEPS) # eg. ~/.tea/nodejs.org/v4.3.2
52+
53+
mkdir -p "$SRCDIR"
54+
BUILD_SCRIPT="$(stage.ts $PKG --srcdir "$SRCDIR" --prefix "$PREFIX" --deps "$DEPS")"
55+
56+
if command -v bash 2>/dev/null; then
57+
BASH=bash
58+
else
59+
BASH="tea bash"
60+
fi
61+
62+
$BASH -e "$BUILD_SCRIPT"
63+
64+
PATH="$d/share/brewkit:$PATH" fixup.ts "$PREFIX" --deps "$DEPS"
65+
66+
find "$PREFIX" -type f -name \*.la -delete
67+
68+
link.ts "$PREFIX" $PKG
69+
70+
if test -n "$GITHUB_ACTIONS"; then
71+
GH_RELATIVE_PATHS="$GH_RELATIVE_PATHS ${PREFIX#$TEA_PREFIX/}"
72+
73+
if test -f "$ZIP"; then
74+
GH_SRCS="$GH_SRCS ${ZIP#$TEA_PREFIX/}"
75+
GH_SRCS_RELATIVE_PATHS="$GH_SRCS_RELATIVE_PATHS ${ZIP#$TEA_PREFIX/}"
76+
else
77+
GH_SRCS="$GH_SRCS ~"
78+
fi
79+
fi
80+
done
81+
82+
if test -n "$GITHUB_ACTIONS"; then
83+
echo "pkgs=$PKGS" >> $GITHUB_OUTPUT
84+
echo "relative-paths=$GH_RELATIVE_PATHS" >> $GITHUB_OUTPUT
85+
echo "srcs=$GH_SRCS" >> $GITHUB_OUTPUT
86+
echo "srcs-relative-paths=$GH_SRCS_RELATIVE_PATHS" >> $GITHUB_OUTPUT
87+
fi

bin/edit

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
d="$(cd $(dirname $0)/.. && pwd)"
6+
PATH="$d/libexec:$PATH"
7+
8+
if test -z "$1"; then
9+
if test -z "$TEA_PANTRY_PATH"; then
10+
echo "error: TEA_PANTRY_PATH is not set" >&2
11+
exit 1
12+
fi
13+
for x in $(echo "$TEA_PANTRY_PATH" | tr ':' '\n'); do
14+
if test -d "$x"/.git; then
15+
PKGS="$(GIT_DIR="$x"/.git peek.sh --print-paths) $PKGS"
16+
fi
17+
done
18+
else
19+
#TODO search TEA_PANTRY_PATH and implicit pantry path
20+
echo "unimplemented" >&2
21+
exit 1
22+
fi
23+
24+
if test -z "$EDITOR"; then
25+
if command -v code 2>/dev/null; then
26+
EDITOR=code
27+
elif command -v vim 2>/dev/null; then
28+
EDITOR=vim
29+
elif command -v vi 2>/dev/null; then
30+
EDITOR=vi
31+
elif command -v emacs 2>/dev/null; then
32+
EDITOR=emacs
33+
else
34+
echo "error: \`\$EDITOR\` is not set" >&2
35+
exit 1
36+
fi
37+
elif test $EDITOR = code_wait; then
38+
# this is for mxcl who generally prefers his editor to wait
39+
# but not in this case. #perks-of-making-the-thing
40+
EDITOR=code
41+
fi
42+
43+
if test -z "$PKGS"; then
44+
echo "error: no new packages in \`\$TEA_PANTRY_PATH\`" >&2
45+
exit 1
46+
else
47+
exec $EDITOR $PKGS
48+
fi

bin/fetch

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
d="$(cd $(dirname $0)/.. && pwd)"
6+
PATH="$d/libexec:$PATH"
7+
8+
if test -z "$1"; then
9+
if test -z "$TEA_PANTRY_PATH"; then
10+
echo "error: TEA_PANTRY_PATH is not set" >&2
11+
exit 1
12+
fi
13+
for x in $(echo "$TEA_PANTRY_PATH" | tr ':' '\n'); do
14+
if test -d "$x"/.git; then
15+
PKGS="$(GIT_DIR="$x"/.git peek.sh) $PKGS"
16+
fi
17+
done
18+
else
19+
PKGS="$1"
20+
fi
21+
22+
for PKG in $PKGS; do
23+
#TODO allow specifying the destination
24+
fetch.ts $PKG
25+
done

bin/init

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
if test -z "$TEA_PANTRY_PATH"; then
6+
echo "error: TEA_PANTRY_PATH is not set" >&2
7+
exit 1
8+
fi
9+
10+
d="$(cd $(dirname $0)/.. && pwd)"
11+
PATH="$d/libexec:$PATH"
12+
13+
BLEND="$1"
14+
if test -z "$BLEND"; then
15+
BLEND="wip/$(tea sample-blend.rb)"
16+
fi
17+
WHERE="$(echo "$TEA_PANTRY_PATH" | cut -d: -f1)"
18+
19+
mkdir -p "$WHERE/projects/$BLEND"
20+
cp "$d/share/TEMPLATE.pkg.yml" "$WHERE/projects/$BLEND/package.yml"
21+
22+
if test "$WHERE" = "$PWD"; then
23+
PRETTY="./projects/$BLEND/package.yml"
24+
else
25+
PRETTY="$WHERE/projects/$BLEND"
26+
fi
27+
28+
tea gum format <<EOF
29+
# created \`$PRETTY\`
30+
31+
Now type \`xc edit\` to open the yaml in your \`\$EDITOR\`
32+
33+
the package will need renaming before we can merge it.
34+
we typically name packages after their homepage.
35+
36+
if you aren’t sure about the name you can submit and we’ll assist.
37+
EOF

bin/test

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
d="$(cd $(dirname $0)/.. && pwd)"
6+
PATH="$d/libexec:$PATH"
7+
8+
if test -z "$1"; then
9+
if test -z "$TEA_PANTRY_PATH"; then
10+
echo "error: TEA_PANTRY_PATH is not set" >&2
11+
exit 1
12+
fi
13+
for x in $(echo "$TEA_PANTRY_PATH" | tr ':' '\n'); do
14+
if test -d "$x"/.git; then
15+
PKGS="$(GIT_DIR="$x"/.git peek.sh) $PKGS"
16+
fi
17+
done
18+
else
19+
PKGS="$1"
20+
fi
21+
22+
for PKG in $PKGS; do
23+
PKG="$(resolve.ts $PKG --cellar)"
24+
DEPS="$(deps.ts $PKG --test)"
25+
DEPS="$(install.ts $DEPS)"
26+
DSTDIR="$(query.ts $PKG --testdir)"
27+
28+
mkdir -p "$DSTDIR"
29+
30+
stage-test.ts $PKG --deps "$DEPS" --dstdir "$DSTDIR"
31+
32+
if command -v bash 2>/dev/null; then
33+
BASH=bash
34+
else
35+
BASH="tea bash"
36+
fi
37+
38+
$BASH -e "$DSTDIR"/xyz.tea.test.sh
39+
done

deno.jsonc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": false,
4+
"strict": true
5+
},
6+
"tasks": {
7+
"typecheck": "deno check --unstable scripts/*.ts"
8+
// ^^ doesn't work yet due to lack of glob support
9+
},
10+
"fmt": {
11+
"files": {
12+
"exclude": [
13+
"./"
14+
]
15+
}
16+
},
17+
"tea": {
18+
"dependencies": {
19+
"deno.land": "^1.30"
20+
}
21+
},
22+
"importMap": "https://raw.githubusercontent.com/teaxyz/cli/v0.22/import-map.json"
23+
}

0 commit comments

Comments
 (0)