diff --git a/.bazelignore b/.bazelignore index ccaf716..ce2c0bd 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1,3 +1,5 @@ # Convenience symlinks are blindly traversed by Bazel... # https://github.com/bazelbuild/bazel/issues/10653#issuecomment-694230015 bazel-rules_appimage + +example diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4d680bb..8dd7220 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: diff --git a/example/.bazelrc b/example/.bazelrc new file mode 100644 index 0000000..3ce91d2 --- /dev/null +++ b/example/.bazelrc @@ -0,0 +1 @@ +common --enable_bzlmod diff --git a/example/BUILD b/example/BUILD new file mode 100644 index 0000000..2124989 --- /dev/null +++ b/example/BUILD @@ -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", +) diff --git a/example/MODULE.bazel b/example/MODULE.bazel new file mode 100644 index 0000000..8f9c267 --- /dev/null +++ b/example/MODULE.bazel @@ -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") diff --git a/example/hello.py b/example/hello.py new file mode 100644 index 0000000..b5e0831 --- /dev/null +++ b/example/hello.py @@ -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() diff --git a/example/integration_test.sh b/example/integration_test.sh new file mode 100755 index 0000000..07a58f0 --- /dev/null +++ b/example/integration_test.sh @@ -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 diff --git a/example/requirements.txt b/example/requirements.txt new file mode 100644 index 0000000..2f72dd5 --- /dev/null +++ b/example/requirements.txt @@ -0,0 +1 @@ +click==8.1.7 diff --git a/example/resources/BUILD b/example/resources/BUILD new file mode 100644 index 0000000..ead2180 --- /dev/null +++ b/example/resources/BUILD @@ -0,0 +1,5 @@ +filegroup( + name = "resources", + srcs = ["data.txt"], + visibility = ["//visibility:public"], +) diff --git a/example/resources/data.txt b/example/resources/data.txt new file mode 100644 index 0000000..8ab686e --- /dev/null +++ b/example/resources/data.txt @@ -0,0 +1 @@ +Hello, World!