Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,33 @@ jobs:
files: |
gitbonsai-*
generate_release_notes: true

# The GitHub Action end to end against the release just published: download,
# sha256 check, collect, render. A release made with the built-in token
# triggers no other workflow, so the check runs here.
action:
name: Action (${{ matrix.os }})
needs: release
runs-on: ${{ matrix.os }}
# It runs the downloaded binary with the token: reading is all it needs.
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v7

- uses: ./
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
id: bonsai
with:
output-dir: out
legend: left

- name: Check the outputs
shell: bash
run: |
for f in "${{ steps.bonsai.outputs.light }}" "${{ steps.bonsai.outputs.dark }}"; do
test -s "$f" && grep -q '<svg' "$f" && grep -q '<text' "$f" || { echo "::error::$f is not a rendered SVG"; exit 1; }
done
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to gitbonsai are recorded here. Any change to how a tree
grows or looks is at least a minor version, because people will notice their
tree changing.

## 0.1.2

- A GitHub Action: `uses: StevenBtw/gitbonsai@v0.1.2` downloads the release,
checks its sha256, then collects and renders, with inputs for style, legend
and config. The profile workflow example uses it.

## 0.1.1

Trees change look in this release: smoother wood and softer leaves.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gitbonsai"
version = "0.1.1"
version = "0.1.2"
edition = "2024"
rust-version = "1.99.0"
license = "MIT OR Apache-2.0"
Expand Down
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The tree is yours: it grows from your own GitHub activity, week by week. The tru
| Newbie | Comeback | Veteran |
| :---: | :---: | :---: |
| <picture><source media="(prefers-color-scheme: dark)" srcset="assets/newbie-dark.svg" /><img src="assets/newbie-light.svg" width="260" alt="A newcomer bonsai: a young tree in its first pot" /></picture> | <picture><source media="(prefers-color-scheme: dark)" srcset="assets/comeback-dark.svg" /><img src="assets/comeback-light.svg" width="260" alt="A comeback bonsai: deadwood from the quiet years, new growth since" /></picture> | <picture><source media="(prefers-color-scheme: dark)" srcset="assets/veteran-dark.svg" /><img src="assets/veteran-light.svg" width="260" alt="A veteran bonsai: tall, thick and full" /></picture> |
| a few months in | quiet for two years, then back | 16 years, busy since 2023 |
| a few months in | quiet for two years, then back | 16 years, busier the last few years |

<details>
<summary>What every part shows</summary>
Expand All @@ -36,18 +36,18 @@ The tree is yours: it grows from your own GitHub activity, week by week. The tru

</details>

## Use it
## Use it on your profile

Needs the [GitHub CLI](https://cli.github.com), logged in.
Add the action to a weekly workflow in your profile repository (`<you>/<you>`); [examples/profile-workflow.yml](examples/profile-workflow.yml) is a complete one to copy to `.github/workflows/bonsai.yml`:

```sh
cargo install gitbonsai
gitbonsai collect <login> --output me.snapshot.json
gitbonsai render me.snapshot.json # bonsai/: light and dark SVG, PNG, preview.html
gitbonsai explain me.snapshot.json # every number behind the tree
```yaml
- uses: StevenBtw/gitbonsai@v0.1.2
with:
output-dir: assets # bonsai-light.svg and bonsai-dark.svg
legend: left # optional: off (default), left or right
```

On your profile, copy [examples/profile-workflow.yml](examples/profile-workflow.yml) to `.github/workflows/bonsai.yml` in `<you>/<you>`. It regrows the tree every week. Then add this to your README:
Then add this to your README:

```html
<p align="center">
Expand All @@ -60,7 +60,18 @@ On your profile, copy [examples/profile-workflow.yml](examples/profile-workflow.

On its own, `width="600"` suits a desktop column, and phones scale it down to fit. Next to other cards, use `400`.

Styles, leaf colors, the pot glaze and an optional legend (left or right of the tree) go in a `bonsai.toml`; see [examples/bonsai.toml](examples/bonsai.toml).
Styles, leaf colors, the pot glaze and the legend go in a `bonsai.toml`; see [examples/bonsai.toml](examples/bonsai.toml). The action reads it from the repository root, and its inputs `style` and `legend` override it.
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved

## Run it locally

Needs the [GitHub CLI](https://cli.github.com), logged in.

```sh
cargo install gitbonsai
gitbonsai collect <login> --output me.snapshot.json
gitbonsai render me.snapshot.json # bonsai/: light and dark SVG, PNG, preview.html
gitbonsai explain me.snapshot.json # every number behind the tree
```

## Credits

Expand Down
105 changes: 105 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: gitbonsai
description:
Grow a Japanese maple bonsai from a GitHub account's activity, as light and
dark animated SVGs for a profile README.
branding:
icon: feather
color: green

inputs:
login:
description: Account whose bonsai to grow.
default: ${{ github.repository_owner }}
output-dir:
description:
Folder, relative to the workspace, that receives bonsai-light.svg,
bonsai-dark.svg, bonsai.png and preview.html.
default: bonsai
style:
description:
moyogi, chokkan, shakan or fukinagashi; empty uses the config or the
default (moyogi).
default: ""
legend:
description:
off, left or right; a legend beside the tree. Empty uses the config or
the default (off).
default: ""
config:
description: A bonsai.toml in the workspace; a missing file means defaults.
default: bonsai.toml
token:
description:
Token for reading the account's public data; the built-in token is enough.
default: ${{ github.token }}

outputs:
light:
description: Path of the light SVG.
value: ${{ steps.render.outputs.light }}
dark:
description: Path of the dark SVG.
value: ${{ steps.render.outputs.dark }}

runs:
using: composite
steps:
- name: Download the gitbonsai release this action belongs to
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
run: |
version=$(grep -m1 '^version' "$GITHUB_ACTION_PATH/Cargo.toml" | cut -d'"' -f2)
repository=$(grep -m1 '^repository' "$GITHUB_ACTION_PATH/Cargo.toml" | cut -d'"' -f2)
case "$RUNNER_OS-$RUNNER_ARCH" in
Linux-X64) target=x86_64-unknown-linux-musl ;;
Linux-ARM64) target=aarch64-unknown-linux-musl ;;
macOS-X64) target=x86_64-apple-darwin ;;
macOS-ARM64) target=aarch64-apple-darwin ;;
*)
echo "gitbonsai has no build for $RUNNER_OS $RUNNER_ARCH; use ubuntu-latest" >&2
exit 1
;;
esac
archive="gitbonsai-$target.tar.gz"
install_dir="$RUNNER_TEMP/gitbonsai"
mkdir -p "$install_dir"
if ! gh release download "v$version" --repo "$repository" --dir "$install_dir" \
--pattern "$archive" --pattern "$archive.sha256" --clobber; then
echo "release v$version has no asset $archive; reference the action at a release tag" >&2
exit 1
fi
cd "$install_dir"
if command -v sha256sum > /dev/null; then
sha256sum -c "$archive.sha256"
else
shasum -a 256 -c "$archive.sha256"
fi
tar -xzf "$archive"
echo "$install_dir" >> "$GITHUB_PATH"
- name: Collect the account's activity
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
BONSAI_LOGIN: ${{ inputs.login }}
run: gitbonsai collect "$BONSAI_LOGIN" --output "$RUNNER_TEMP/bonsai.snapshot.json"
- name: Grow the bonsai
id: render
shell: bash
env:
BONSAI_OUTPUT_DIR: ${{ inputs.output-dir }}
BONSAI_STYLE: ${{ inputs.style }}
BONSAI_LEGEND: ${{ inputs.legend }}
BONSAI_CONFIG: ${{ inputs.config }}
run: |
# Style and legend override the config only when given.
args=(--output-dir "$BONSAI_OUTPUT_DIR" --config "$BONSAI_CONFIG")
if [ -n "$BONSAI_STYLE" ]; then
args+=(--style "$BONSAI_STYLE")
fi
if [ -n "$BONSAI_LEGEND" ]; then
args+=(--legend "$BONSAI_LEGEND")
fi
gitbonsai render "$RUNNER_TEMP/bonsai.snapshot.json" "${args[@]}"
echo "light=$BONSAI_OUTPUT_DIR/bonsai-light.svg" >> "$GITHUB_OUTPUT"
echo "dark=$BONSAI_OUTPUT_DIR/bonsai-dark.svg" >> "$GITHUB_OUTPUT"
2 changes: 1 addition & 1 deletion assets/veteran-legend-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/veteran-legend-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 7 additions & 21 deletions examples/profile-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Regrows the bonsai every week. Copy to .github/workflows/bonsai.yml in your
# profile repository (<you>/<you>).
#
# - The built-in token is enough: everything `collect` reads is public.
# - The built-in token is enough: everything gitbonsai reads is public.
# - It commits as github-actions[bot], never as you, so the tree doesn't water itself.
# - Each SVG records the week it was grown, so every run commits a change and
# GitHub never pauses the schedule.
Expand All @@ -20,30 +20,16 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Install gitbonsai (latest release)
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release download --repo StevenBtw/gitbonsai \
--pattern 'gitbonsai-x86_64-unknown-linux-musl.tar.gz*' --dir /tmp/gb
cd /tmp/gb
sha256sum -c gitbonsai-x86_64-unknown-linux-musl.tar.gz.sha256
tar -xzf gitbonsai-x86_64-unknown-linux-musl.tar.gz
echo /tmp/gb >> "$GITHUB_PATH"

- name: Grow the bonsai
env:
GH_TOKEN: ${{ github.token }}
run: |
gitbonsai collect ${{ github.repository_owner }} --output /tmp/bonsai.snapshot.json
gitbonsai render /tmp/bonsai.snapshot.json --output-dir /tmp/bonsai
mkdir -p assets
cp /tmp/bonsai/bonsai-light.svg /tmp/bonsai/bonsai-dark.svg assets/
- uses: StevenBtw/gitbonsai@v0.1.2
id: bonsai
with:
output-dir: assets
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
# legend: left # what the colors and signs mean, beside the tree

- name: Commit if it changed
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add assets/bonsai-light.svg assets/bonsai-dark.svg
git add "${{ steps.bonsai.outputs.light }}" "${{ steps.bonsai.outputs.dark }}"
git diff --cached --quiet || git commit -m "Grow bonsai"
git push
Loading