diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c5368cf..540f4b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: ./ + 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 'A newcomer bonsai: a young tree in its first pot | A comeback bonsai: deadwood from the quiet years, new growth since | A veteran bonsai: tall, thick and full | -| 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 |
What every part shows @@ -36,18 +36,18 @@ The tree is yours: it grows from your own GitHub activity, week by week. The tru
-## 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 (`/`); [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 --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 `/`. It regrows the tree every week. Then add this to your README: +Then add this to your README: ```html

@@ -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. + +## Run it locally + +Needs the [GitHub CLI](https://cli.github.com), logged in. + +```sh +cargo install gitbonsai +gitbonsai collect --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 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..bcaf173 --- /dev/null +++ b/action.yml @@ -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" diff --git a/assets/veteran-legend-dark.svg b/assets/veteran-legend-dark.svg index 58633b1..98c0844 100644 --- a/assets/veteran-legend-dark.svg +++ b/assets/veteran-legend-dark.svg @@ -1 +1 @@ -Bonsai for @fixture-veteranJapanese maple bonsai grown over 16 years, level 8. Leaves of Rust, TypeScript, Python. Four languages have turned to deadwood.gitbonsai 0.1.1; observed 2026-W44; moyogi; darkLeavesRustTypeScriptPythondeadwood: Go, JavaScript, +2Signs16 years, 26,301 contributionsnew growth this weeklifetime level 8669-week streaklongest streak 669 weeks +Bonsai for @fixture-veteranJapanese maple bonsai grown over 16 years, level 8. Leaves of Rust, TypeScript, Python. Four languages have turned to deadwood.gitbonsai 0.1.1; observed 2026-W44; moyogi; darkLeavesRustTypeScriptPythondeadwood: Go, JavaScript, +2Signs16 years, 26,301 contributionsnew growth this weeklifetime level 8669-week streaklongest streak 669 weeks diff --git a/assets/veteran-legend-light.svg b/assets/veteran-legend-light.svg index a0327bc..cc58972 100644 --- a/assets/veteran-legend-light.svg +++ b/assets/veteran-legend-light.svg @@ -1 +1 @@ -Bonsai for @fixture-veteranJapanese maple bonsai grown over 16 years, level 8. Leaves of Rust, TypeScript, Python. Four languages have turned to deadwood.gitbonsai 0.1.1; observed 2026-W44; moyogi; lightLeavesRustTypeScriptPythondeadwood: Go, JavaScript, +2Signs16 years, 26,301 contributionsnew growth this weeklifetime level 8669-week streaklongest streak 669 weeks +Bonsai for @fixture-veteranJapanese maple bonsai grown over 16 years, level 8. Leaves of Rust, TypeScript, Python. Four languages have turned to deadwood.gitbonsai 0.1.1; observed 2026-W44; moyogi; lightLeavesRustTypeScriptPythondeadwood: Go, JavaScript, +2Signs16 years, 26,301 contributionsnew growth this weeklifetime level 8669-week streaklongest streak 669 weeks diff --git a/examples/profile-workflow.yml b/examples/profile-workflow.yml index 0078fbf..fd4f72c 100644 --- a/examples/profile-workflow.yml +++ b/examples/profile-workflow.yml @@ -1,7 +1,7 @@ # Regrows the bonsai every week. Copy to .github/workflows/bonsai.yml in your # profile repository (/). # -# - 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. @@ -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 + # 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