Skip to content

Commit

Permalink
rules_pytest v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Aug 21, 2024
1 parent 6d15a51 commit 44e76c8
Show file tree
Hide file tree
Showing 81 changed files with 3,016 additions and 1 deletion.
55 changes: 55 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
###############################################################################
## Bazel Configuration Flags
##
## `.bazelrc` is a Bazel configuration file.
## https://bazel.build/docs/best-practices#bazelrc-file
###############################################################################

# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
common --enable_platform_specific_config

# Enable the only currently supported report type
# https://bazel.build/reference/command-line-reference#flag--combined_report
coverage --combined_report=lcov

# Avoid fully cached builds reporting no coverage and failing CI
# https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
coverage --experimental_fetch_all_coverage_outputs

###############################################################################
## Incompatibility flags
###############################################################################

# https://github.com/bazelbuild/bazel/issues/8195
build --incompatible_disallow_empty_glob=true

# https://github.com/bazelbuild/bazel/issues/12821
build --nolegacy_external_runfiles

# Required for cargo_build_script support before Bazel 7
build --incompatible_merge_fixed_and_default_shell_env

# Disable legacy __init__.py behavior which is known to conflict with
# modern python versions (3.9+)
build --incompatible_default_to_explicit_init_py

###############################################################################
## Bzlmod
###############################################################################

# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/bazelbuild/rules_rust/issues/2181
common --noenable_bzlmod

# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
common --lockfile_mode=off

###############################################################################
## Custom user flags
##
## This should always be the last thing in the `.bazelrc` file to ensure
## consistent behavior when setting flags in that file as `.bazelrc` files are
## evaluated top to bottom.
###############################################################################

try-import %workspace%/user.bazelrc
14 changes: 14 additions & 0 deletions .github/github.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Bazel settings for use in Github CI

# Always display the flags being used
common --announce_rc

# Show errors in CI
test --test_output=errors

# Show more information about failures
build --verbose_failures

# UI for cleaner CI output
common --color=no
common --show_timestamps
12 changes: 12 additions & 0 deletions .github/release_notes.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# {version}

```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_req_compile",
sha256 = "{sha256}",
urls = ["https://github.com/sputt/req-compile/releases/download/{version}/rules_req_compile-v{version}.tar.gz"],
)
```

Additional documentation can be found at: https://github.com/sputt/req-compile
117 changes: 117 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
name: CI

on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize

env:
BAZEL_STARTUP_FLAGS: --bazelrc=${{ github.workspace }}/.github/github.bazelrc

jobs:
# ci:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# include:
# - os: macos-11
# - os: ubuntu-20.04
# - os: windows-2019
# steps:
# # Checkout the code
# - uses: actions/checkout@v2

# # Caches and restores the Bazel outputs.
# - name: Retain Bazel cache (linux)
# uses: actions/cache@v2
# env:
# cache-name: bazel-cache
# with:
# path: |
# ~/.cache/bazelisk
# ~/.cache/bazel
# key: ${{ runner.os }}-${{ env.cache-name }}
# if: startswith(runner.os, 'Linux')
# - name: Retain Bazel cache (MacOS)
# uses: actions/cache@v2
# env:
# cache-name: bazel-cache
# with:
# path: |
# ~/.cache/bazelisk
# /private/var/tmp/_bazel_runner
# key: ${{ runner.os }}-${{ env.cache-name }}
# if: startswith(runner.os, 'MacOS')
# - name: Retain Bazel cache (Windows)
# uses: actions/cache@v2
# env:
# cache-name: bazel-cache
# with:
# path: |
# ~/.cache/bazelisk
# C:/bzl
# key: ${{ runner.os }}-${{ env.cache-name }}
# if: startswith(runner.os, 'Windows')

# - name: Setup Bazelrc (Windows)
# run: |
# echo "startup --output_user_root=C:/bzl" > ./user.bazelrc
# if: startswith(runner.os, 'Windows')
# - name: Setup Bazelrc
# run: |
# echo "common --noenable_bzlmod" >> ./user.bazelrc
# echo "common --keep_going" >> ./user.bazelrc

# # Build and Test the code
# - name: Test (Unix)
# run: bazel ${BAZEL_STARTUP_FLAGS[@]} test //...
# if: startswith(runner.os, 'Windows') != true
# - name: Test (Windows)
# run: bazel $env:BAZEL_STARTUP_FLAGS test //...
# if: startswith(runner.os, 'Windows')

ci-buildifier:
runs-on: ubuntu-20.04
steps:
# Checkout the code
- uses: actions/checkout@v2
- name: Download Buildifier
run: |
wget "https://github.com/bazelbuild/buildtools/releases/download/v7.1.2/buildifier-linux-amd64" -O buildifier
chmod +x buildifier
- name: Buildifier
run: ./buildifier -lint=warn -mode=check -warnings=all -r ${{ github.workspace }}

ci-lint-and-format:
runs-on: ubuntu-20.04
steps:
# Checkout the code
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Setup pip
run: |
python -m pip install --upgrade pip setuptools
- name: Install dependencies
run: |
pip install -r python/pytest/requirements.linux.txt --user
- name: Run mypy
run: |
python -m mypy python
- name: Run pylint
run: |
PYTHONPATH="$(pwd)" python -m pylint python
- name: Run black
run: |
python -m black --check --diff python
- name: Run isort
run: |
python -m isort --check-only python
53 changes: 53 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: Release
on:
workflow_dispatch:
push:
branches:
- main
paths:
# Only trigger for new releases
- "version.bzl"

defaults:
run:
shell: bash

jobs:
release:
if: ${{ github.repository_owner == 'UebelAndre' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Detect the current version
run: |
version="$(grep 'VERSION =' ./version.bzl | sed 's/VERSION = "//' | sed 's/"//')"
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
- name: Create release artifact
run: |
tar -czf ${{ github.workspace }}/.github/rules_pytest.tar.gz --exclude=".git" --exclude=".github" --exclude="scripts" --exclude="dist" --exclude="build" -C ${{ github.workspace }} .
sha256="$(shasum --algorithm 256 ${{ github.workspace }}/.github/rules_pytest.tar.gz | awk '{ print $1 }')"
echo "ARCHIVE_SHA256=${sha256}" >> $GITHUB_ENV
- name: Generate release notes
run: |
# Generate the release notes
sed 's/{version}/${{env.RELEASE_VERSION}}/g' ${{ github.workspace }}/.github/release_notes.template \
| sed 's/{sha256}/${{env.ARCHIVE_SHA256}}/g' \
> ${{ github.workspace }}/.github/release_notes.txt
- name: Release
uses: softprops/action-gh-release@v1
id: rules_release
with:
generate_release_notes: true
tag_name: ${{ env.RELEASE_VERSION }}
body_path: ${{ github.workspace }}/.github/release_notes.txt
target_commitish: ${{ github.base_ref }}
- name: "Upload the rules archive"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.rules_release.outputs.upload_url }}
asset_name: rules_pytest-v${{ env.RELEASE_VERSION }}.tar.gz
asset_path: ${{ github.workspace }}/.github/rules_pytest.tar.gz
asset_content_type: application/gzip
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Git ignore patterns

/bazel-*
user.bazelrc

/.venv*
/venv*
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile = black
20 changes: 20 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://mypy.readthedocs.io/en/stable/config_file.html
[mypy]

# Improve strictness of checks
strict = True

# Avoid deprecated args in the config file
warn_unused_configs = True

# Improve logging
pretty = True

# Prevent mypy from incorrectly looking in multiple places for
# the same package.
explicit_package_bases = True

# Because mypy is not running in Bazel, the runfiles library will
# not be available
[mypy-python.runfiles.*]
ignore_missing_imports = True
5 changes: 5 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports_files([
"MODULE.bazel",
"README.md",
"version.bzl",
])
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""UebelAndre/rules_pytest"""

module(
name = "rules_pytest",
version = "0.0.1",
)

bazel_dep(name = "rules_python", version = "0.34.0")
bazel_dep(name = "rules_req_compile", version = "1.0.0rc23")
Loading

0 comments on commit 44e76c8

Please sign in to comment.