Skip to content

Commit

Permalink
Switch from trunk to pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lalten committed Jul 29, 2024
1 parent 6e0a3ea commit e4e0efd
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 127 deletions.
4 changes: 3 additions & 1 deletion .bcr/metadata.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"name": "lalten"
}
],
"repository": ["github:lalten/rules_appimage"],
"repository": [
"github:lalten/rules_appimage"
],
"versions": [],
"yanked_versions": {}
}
7 changes: 3 additions & 4 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
bcr_test_module:
module_path: ""
module_path: ''
matrix:
bazel: [6.x, 7.x]
tasks:
Expand All @@ -10,6 +11,4 @@ bcr_test_module:
run_tests_macos:
platform: macos
bazel: ${{ bazel }}
test_targets:
- //...
- -//tests/rules_pycross/...
test_targets: [//..., -//tests/rules_pycross/...]
58 changes: 24 additions & 34 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
---
name: CI

"on":
on:
push:
branches: [main]
pull_request:

permissions: read-all

jobs:
test:
runs-on: ${{ matrix.os }}-latest
Expand All @@ -20,30 +18,25 @@ jobs:
os: [ubuntu, macos]
external_dependency_system: [bzlmod, workspace]
exclude:
# Don't expect Bazel compatibility issues depending on OS, so speed this up
- bazel-version: 6.x
os: macos
# Don't expect Bazel compatibility issues depending on OS, so speed this up
- bazel-version: 6.x
os: macos
include:
- external_dependency_system: bzlmod
flags: --enable_bzlmod
- external_dependency_system: workspace
flags: --noenable_bzlmod

- external_dependency_system: bzlmod
flags: --enable_bzlmod
- external_dependency_system: workspace
flags: --noenable_bzlmod
steps:
- uses: actions/checkout@v4

- name: Use BuildBuddy RW API key instead of public readonly key
run: sed -i.bak 's#x-buildbuddy-api-key=.*#x-buildbuddy-api-key=${{ env.BUILDBUDDY_RW_API_KEY }}#' .bazelrc
if: ${{ env.BUILDBUDDY_RW_API_KEY }}

- run: echo "common ${{ matrix.flags }}" >> .bazelrc

# Don't want to bother with hundreds of lines of Workspace setup for the rules_pycross compat test
- if: matrix.external_dependency_system == 'workspace' || matrix.os == 'macos'
run: echo "tests/rules_pycross" >> .bazelignore

- run: bazel test //...

- uses: actions/checkout@v4
- name: Use BuildBuddy RW API key instead of public readonly key
run: sed -i.bak 's#x-buildbuddy-api-key=.*#x-buildbuddy-api-key=${{ env.BUILDBUDDY_RW_API_KEY }}#' .bazelrc
if: ${{ env.BUILDBUDDY_RW_API_KEY }}
- run: echo "common ${{ matrix.flags }}" >> .bazelrc

# Don't want to bother with hundreds of lines of Workspace setup for the rules_pycross compat test
- if: matrix.external_dependency_system == 'workspace' || matrix.os == 'macos'
run: echo "tests/rules_pycross" >> .bazelignore
- run: bazel test //...
examples:
runs-on: ubuntu-latest
env:
Expand All @@ -53,14 +46,11 @@ jobs:
matrix:
bazel-version: [6.x, 7.x]
steps:
- uses: actions/checkout@v4
- run: examples/integration_test.sh

- uses: actions/checkout@v4
- run: examples/integration_test.sh
lint:
runs-on: ubuntu-latest
permissions:
checks: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: trunk-io/trunk-action@v1
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1
52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
exclude: ^bazel-
repos:
- repo: https://github.com/rhysd/actionlint
rev: v1.7.1
hooks:
- id: actionlint
- repo: https://github.com/warchant/pre-commit-buildifier
rev: 0.1.1
hooks:
- id: buildifier
args: [--version=v7.1.2, --lint=warn, --warnings=all, -v]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.8
hooks:
- id: clang-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
- id: ruff-format
- repo: https://github.com/lyz-code/yamlfix
rev: 1.16.0
hooks:
- id: yamlfix
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
hooks:
- id: shellcheck
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.8.0-1
hooks:
- id: shfmt-docker
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: [--write-changes]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0
hooks:
- id: markdownlint
args: [--fix]
- repo: https://github.com/renovatebot/pre-commit-hooks
rev: 38.10.0
hooks:
- id: renovate-config-validator
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
hooks:
- id: mypy
9 changes: 0 additions & 9 deletions .trunk/.gitignore

This file was deleted.

41 changes: 0 additions & 41 deletions .trunk/trunk.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions .yamllint.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions appimage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ toolchain_type(name = "appimage_toolchain_type")
appimage_runtime = "@appimage_runtime_" + arch + "//file",
) for arch in ARCHS.keys()]

# default toolchain for backwards compatability
# default toolchain for backwards compatibility
appimage_toolchain(
name = "default_appimage",
appimage_runtime = select({
Expand All @@ -31,7 +31,7 @@ appimage_toolchain(
toolchain_type = ":appimage_toolchain_type",
) for arch in ARCHS.keys()]

# Register toolchain for backwards compatability
# Register toolchain for backwards compatibility
toolchain(
name = "default_appimage_toolchain",
toolchain = ":default_appimage",
Expand Down
2 changes: 2 additions & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ local_path_override(
)

bazel_dep(name = "rules_python", version = "0.29.0")

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",
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ ignore = ["COM812", "D203", "D213", "PLR2004", "TRY003"]

[tool.ruff]
line-length = 120

[tool.yamlfix]
line_length = 120
indent_sequence = 2
indent_offset = 0
16 changes: 8 additions & 8 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"pip-compile": {
"fileMatch": ["(^|/)requirements\\.in$"],
"lockFileMaintenance": {
"enabled": true,
"branchTopic": "pip-compile-refresh",
"commitMessageAction": "Refresh pip-compile outputs"
}
"extends": [
"config:recommended"
],
"pip_requirements": {
"enabled": false
},
"pre-commit": {
"enabled": true
}
}
10 changes: 5 additions & 5 deletions tests/rules_pycross/test_appimage_isolated.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
schemaVersion: "2.0.0"

---
schemaVersion: 2.0.0
commandTests:
- name: run test
command: "/test.appimage"
args: [--appimage-extract-and-run]
- name: run test
command: /test.appimage
args: [--appimage-extract-and-run]
4 changes: 2 additions & 2 deletions tests/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#include <iostream>
#include <string>

int main(int argc, char** argv, char** envp) {
int main(int argc, char **argv, char **envp) {
(void)argc;
(void)argv;
// Go through the environment variables and find the one we set in the BUILD.
// When running inside the appimage, we want the env to not be lost.
bool have_binary_env = false;
bool have_appimage_env = false;
std::string bazel_version{"unknown"};
for (char** env = envp; *env != 0; env++) {
for (char **env = envp; *env != 0; env++) {
std::string thisEnv{*env};
std::cout << thisEnv << std::endl;
if (thisEnv == "MY_BINARY_ENV=not lost") {
Expand Down
28 changes: 14 additions & 14 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ def test_datadep() -> None:
"""Test that the data dependency of the binary is bundled."""
data_dep = Path("tests/data.txt")
assert data_dep.is_file(), f"{data_dep} does not exist"
assert (size := data_dep.stat().st_size) == 591, f"{data_dep} has wrong size {size}"
assert data_dep.stat().st_size == 591, f"{data_dep} has wrong size {data_dep.stat().st_size}"


def test_appimage_datadep() -> None:
"""Test that data deps to the appimage itself are bundled."""
data_dep = Path("tests/appimage_data_file.txt")
assert data_dep.is_file(), f"{data_dep} does not exist"
assert (size := data_dep.stat().st_size) == 13, f"{data_dep} has wrong size {size}"
assert data_dep.stat().st_size == 13, f"{data_dep} has wrong size {data_dep.stat().st_size}"

data_dep = Path("tests/appimage_data_filegroup.txt")
assert data_dep.is_file(), f"{data_dep} does not exist"
assert (size := data_dep.stat().st_size) == 22, f"{data_dep} has wrong size {size}"
assert data_dep.stat().st_size == 22, f"{data_dep} has wrong size {data_dep.stat().st_size}"


def test_external_bin() -> None:
Expand Down Expand Up @@ -64,52 +64,52 @@ def test_symlinks() -> None:
link_to_declared_dep = Path("tests/dir/subdir/symlink_to_local_file")
assert link_to_declared_dep.is_file()
assert link_to_declared_dep.is_symlink()
assert os.readlink(link_to_declared_dep) == "../local_file"
assert link_to_declared_dep.readlink().as_posix() == "../local_file"

abs_link = Path("tests/dir/link_to_bin_sh")
assert abs_link.is_file()
assert abs_link.is_symlink()
assert os.readlink(abs_link) == "/bin/sh"
assert abs_link.readlink().as_posix() == "/bin/sh"

dir_link = Path("tests/dir/subdir/dir_link")
assert dir_link.is_symlink()
assert os.readlink(dir_link) == "dir"
assert dir_link.readlink().as_posix() == "dir"
assert dir_link.resolve().is_dir()

link = next(Path("..").glob("**/bin/python3"))
# link will be one of these depending on --enable_bzlmod (and rules_python version)
# "rules_appimage_python_x86_64-unknown-linux-gnu/bin/python3"
# "rules_python~0.27.1~python~python_3_11_x86_64-unknown-linux-gnu/bin/python3"
assert link.is_symlink(), f"{link} is not a symlink. {link.is_file()=}"
assert re.match(r"^python3.\d+$", os.readlink(link)), os.readlink(link)
assert re.match(r"^python3.\d+$", link.readlink().as_posix()), link.readlink()


def test_declared_symlinks() -> None:
"""Test that symlinks declared via `ctx.actions.declare_symlink(...)` are handled correctly."""
link = Path("tests/dangling_symlink")
assert link.is_symlink()
target = os.readlink(link)
assert target == "../idonotexist", target
target = link.readlink()
assert target.as_posix() == "../idonotexist", target
assert not link.is_file()

link = Path("tests/dot_symlink")
assert link.is_symlink()
target = os.readlink(link)
assert target == ".", target
target = link.readlink()
assert target.as_posix() == ".", target
assert link.is_dir()

link = Path("tests/dotdot_symlink")
assert link.is_symlink()
target = os.readlink(link)
assert target == "..", target
target = link.readlink()
assert target.as_posix() == "..", target
assert link.is_dir()


def test_runfiles_symlinks() -> None:
"""Test that symlinks coming from `ctx.runfiles(symlinks = {...})` are handled correctly."""
runfiles_symlink = Path("path/to/the/runfiles_symlink")
assert runfiles_symlink.is_symlink()
assert os.readlink(runfiles_symlink) == "../../../tests/data.txt"
assert runfiles_symlink.readlink().as_posix() == "../../../tests/data.txt"
assert runfiles_symlink.resolve().is_file()


Expand Down
Loading

0 comments on commit e4e0efd

Please sign in to comment.