Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
lalten committed Dec 17, 2023
1 parent e35630f commit 51bd277
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Convenience symlinks are blindly traversed by Bazel...
# https://github.com/bazelbuild/bazel/issues/10653#issuecomment-694230015
bazel-rules_appimage

example
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- run: bazel test --enable_bzlmod //...
if: ${{ matrix.bazel-version != '5.x' }}

- run: example/integration_test.sh
if: ${{ matrix.bazel-version != '5.x' }}

lint:
runs-on: ubuntu-latest
permissions:
Expand Down
1 change: 1 addition & 0 deletions example/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --enable_bzlmod
15 changes: 15 additions & 0 deletions example/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@py_deps//:requirements.bzl", "requirement")
load("@rules_appimage//appimage:appimage.bzl", "appimage")
load("@rules_python//python:defs.bzl", "py_binary")

py_binary(
name = "hello",
srcs = ["hello.py"],
data = ["//resources"],
deps = [requirement("click")],
)

appimage(
name = "hello.appimage",
binary = ":hello",
)
16 changes: 16 additions & 0 deletions example/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Example workspace using rules_appimage."""

module(name = "rules_appimage_example", version = "0.0.0")

bazel_dep(name = "rules_appimage", version = "1.5.0")

bazel_dep(name = "rules_python", version = "0.27.1")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.11")
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "py_deps",
python_version = "3.11",
requirements_lock = "requirements.txt",
)
use_repo(pip, "py_deps")
18 changes: 18 additions & 0 deletions example/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Example Python application."""

from pathlib import Path

import click

DATA_FILE = Path("resources/data.txt")


@click.command() # type: ignore [misc]
def main() -> None:
"""Print "Hello, world!" to the console."""
data = DATA_FILE.read_text().strip()
click.echo(data)


if __name__ == "__main__":
main()
19 changes: 19 additions & 0 deletions example/integration_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -euxo pipefail

bazel build //:hello.appimage

trap "rm -f hello.appimage" EXIT
cp -f bazel-bin/hello.appimage .

ls -lah hello.appimage
file hello.appimage

if ! output="$(./hello.appimage 2>&1)"; then
echo "Unexpected failure: $output"
exit 1
elif [[ $output != "Hello, World!" ]]; then
echo "Unexpected output: $output"
exit 1
fi
1 change: 1 addition & 0 deletions example/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
click==8.1.7
5 changes: 5 additions & 0 deletions example/resources/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "resources",
srcs = ["data.txt"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions example/resources/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, World!

0 comments on commit 51bd277

Please sign in to comment.