Skip to content

Commit

Permalink
Create rules_mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-thm committed Jul 27, 2024
1 parent 352b196 commit 81a4166
Show file tree
Hide file tree
Showing 51 changed files with 1,465 additions and 0 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples/
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
common --enable_bzlmod

common --lockfile_mode=off

test --test_output=errors
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.0.0
9 changes: 9 additions & 0 deletions .bcr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Bazel Central Registry

When the ruleset is released, we want it to be published to the
Bazel Central Registry automatically:
<https://registry.bazel.build>

This folder contains configuration files to automate the publish step.
See <https://github.com/bazel-contrib/publish-to-bcr/blob/main/templates/README.md>
for authoritative documentation about these files.
3 changes: 3 additions & 0 deletions .bcr/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixedReleaser:
login: mark-thm
email: 123787712+mark-thm@users.noreply.github.com
18 changes: 18 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"homepage": "https://github.com/theoremlp/rules_mypy",
"maintainers": [
{
"email": "123787712+mark-thm@users.noreply.github.com",
"github": "mark-thm",
"name": "Mark Elliot"
},
{
"email": "bazel-maintainers@theoremlp.com",
"github": "theoremlp",
"name": "Theorem Bazel Maintainers"
}
],
"repository": ["github:theoremlp/rules_myp"],
"versions": [],
"yanked_versions": {}
}
15 changes: 15 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
matrix:
platform:
- debian10
- ubuntu2004
- macos
- macos_arm64
bazel:
- 7.x
tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- "@rules_mypy//..."
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "**leave this alone**",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{VERSION}.tar.gz"
}
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# In code review, collapse generated files
docs/*.md linguist-generated=true

#################################
# Configuration for 'git archive'
# See https://git-scm.com/docs/git-archive#ATTRIBUTES

# Don't include examples in the distribution artifact, to reduce size.
# You may want to add additional exclusions for folders or files that users don't need.
examples export-ignore
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* @theoremlp/eng

.github/workflows/*.yml @theoremlp/eng @reviewbot-theorem
uv/private/uv.lock.json @theoremlp/eng @reviewbot-theorem
16 changes: 16 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [":semanticCommitsDisabled"],
"enabledManagers": ["github-actions"],
"timezone": "America/New_York",
"schedule": ["every weekday after 9am before 5pm"],
"branchConcurrentLimit": 10,
"labels": ["automerge"],
"dependencyDashboard": true,
"packageRules": [
{
"matchFiles": ["MODULE.bazel"],
"enabled": false
}
]
}
14 changes: 14 additions & 0 deletions .github/reviewers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"teams": {},
"reviewers": {},
"overrides": [
{
"description": "Auto-approve automated PRs",
"onlyModifiedByUsers": ["thm-automation[bot]", "renovate-thm[bot]"],
"onlyModifiedFileRegExs": [
"^.github/workflows/.*",
"^uv/private/uv.lock.json$"
]
}
]
}
24 changes: 24 additions & 0 deletions .github/workflows/automation-autorelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: autorelease
on:
workflow_dispatch: {}
schedule:
# check at 11am every day
- cron: "0 11 * * *"
jobs:
autorelease:
name: autorelease
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Get Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.THM_AUTOMATION_APP_ID }}
private-key: ${{ secrets.THM_AUTOMATION_PRIVATE_KEY }}
- name: autorelease
uses: markelliot/autorelease@v2
with:
github-token: ${{ steps.app-token.outputs.token }}
max-days: 7
tag-only: true
39 changes: 39 additions & 0 deletions .github/workflows/automation-autosquash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: autosquash
on:
pull_request:
types:
# omit "opened" as labeling happens after opening
# and when we include both the two events end up
# canceling each other's runs.
- reopened
- edited
- labeled
- synchronize
- unlabeled
- ready_for_review
concurrency:
# only one autosquash at a time per PR
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
autosquash:
runs-on: ubuntu-latest
steps:
- name: Get Token
if: github.event.pull_request.head.repo.full_name == 'theoremlp/rules_mypy'
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.THM_AUTOMATION_APP_ID }}
private-key: ${{ secrets.THM_AUTOMATION_PRIVATE_KEY }}
- if: github.event.pull_request.head.repo.full_name == 'theoremlp/rules_mypy'
uses: actions/checkout@v4
- if: github.event.pull_request.head.repo.full_name == 'theoremlp/rules_mypy'
uses: theoremlp/autosquash@v1
with:
github-token: ${{ steps.app-token.outputs.token }}
pull-request-number: ${{ github.event.pull_request.number }}
squash-commit-title: "${{ github.event.pull_request.title }} (#${{ github.event.pull_request.number }})"
squash-commit-message: "${{ github.event.pull_request.body }}"
do-not-merge-label: "do not merge"
required-label: "automerge"
15 changes: 15 additions & 0 deletions .github/workflows/automation-reviewbot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: reviewbot
on:
pull_request: {}
pull_request_review: {}
jobs:
required-reviewers:
name: reviewbot
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == 'theoremlp/rules_mypy'
steps:
- name: required-reviewers
uses: theoremlp/required-reviews@v2
with:
github-token: ${{ secrets.REVIEW_TOKEN_PUB }}
post-review: true
18 changes: 18 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file contains Bazel settings to apply on CI only.
# It is referenced with a --bazelrc option in the call to bazel in ci.yaml

# Debug where options came from
build --announce_rc

# This directory is configured in GitHub actions to be persisted between runs.
# We do not enable the repository cache to cache downloaded external artifacts
# as these are generally faster to download again than to fetch them from the
# GitHub actions cache.
build --disk_cache=~/.cache/bazel

# Don't rely on test logs being easily accessible from the test runner,
# though it makes the log noisier.
test --test_output=errors

# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
test --test_env=XDG_CACHE_HOME
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
test:
uses: bazel-contrib/.github/.github/workflows/bazel.yaml@v6
with:
folders: |
[
".",
"examples/demo",
]
# we only support Bazel 7, and only with bzlmod enabled
exclude: |
[
{"bzlmodEnabled": false},
{"bazelversion": "5.4.0"},
{"bazelversion": "6.4.0"},
]
# this ruleset only supports linux and macos
exclude_windows: true
54 changes: 54 additions & 0 deletions .github/workflows/periodic-update-multitool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Periodic - Update Multitool Versions
on:
workflow_dispatch: {}
schedule:
# run every hour on the 5 between 9am and 5pm (4am and 12pm UTC), M-F
- cron: "5 14-22 * * 1-5"
jobs:
update-requirement:
name: Update Multitool Versions
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
env:
LOCKFILE: uv/private/uv.lock.json
# disable running on anything but main
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Get Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.THM_AUTOMATION_APP_ID }}
private-key: ${{ secrets.THM_AUTOMATION_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Download and Extract Latest Multitool
run: |
latest="$(curl https://api.github.com/repos/theoremlp/multitool/releases/latest | jq -r '.assets[].browser_download_url | select(. | test("x86_64-unknown-linux-gnu.tar.xz$"))')"
wget -O multitool.tar.xz "$latest"
tar --strip-components=1 -xf multitool.tar.xz
- name: Find Updates and Render Lockfile
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: ./multitool --lockfile "$LOCKFILE" update
- name: Commit Changes
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
BRANCH_NAME: "automation/update-multitool-lockfile"
run: |
if [[ -n "$(git diff "$LOCKFILE")" ]]
then
git config --local user.name 'Theorem Automation'
git config --local user.email 'thm-automation[bot]@users.noreply.github.com'
git checkout -b "${BRANCH_NAME}"
git add "$LOCKFILE"
git commit -m "Update Multitool Versions
Updated with [update-multitool](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}) by *${GITHUB_ACTOR}*
"
git push origin "${BRANCH_NAME}" -f
gh pr create --fill --label "automerge" >> "$GITHUB_STEP_SUMMARY"
fi
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release
on:
push:
tags:
- "v*.*.*"

jobs:
release:
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v6
permissions:
contents: write
with:
release_files: rules_mypy-*.tar.gz
prerelease: false
30 changes: 30 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# invoked by release workflow
# (via https://github.com/bazel-contrib/.github/blob/master/.github/workflows/release_ruleset.yaml)

set -o errexit -o nounset -o pipefail

RULES_NAME="rules_mypy"
TAG="${GITHUB_REF_NAME}"
PREFIX="${RULES_NAME}-${TAG:1}"
ARCHIVE="${RULES_NAME}-${TAG:1}.tar.gz"

# embed version in MODULE.bazel
perl -pi -e "s/version = \"0\.0\.0\",/version = \"${TAG:1}\",/g" MODULE.bazel

stash_name=`git stash create`;
git archive --format=tar --prefix=${PREFIX}/ "${stash_name}" | gzip > $ARCHIVE

SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

cat << EOF
## Using Bzlmod with Bazel 7
1. Enable with \`common --enable_bzlmod\` in \`.bazelrc\`.
2. Add to your \`MODULE.bazel\` file:
\`\`\`starlark
bazel_dep(name = "${RULES_NAME}", version = "${TAG:1}")
\`\`\`
EOF
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bazel-bin/
bazel-out/
bazel-testlogs/
bazel-*

venv/
.venv/
22 changes: 22 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")

exports_files([
"MODULE.bazel",
])

buildifier(
name = "buildifier.fix",
exclude_patterns = ["./.git/*"],
lint_mode = "fix",
mode = "fix",
visibility = ["//thm/buildtools/fix:__pkg__"],
)

buildifier_test(
name = "buildifier.test",
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
mode = "diff",
no_sandbox = True,
workspace = "//:MODULE.bazel",
)
Loading

0 comments on commit 81a4166

Please sign in to comment.