Skip to content

Commit 8ae3d03

Browse files
Initial commit
0 parents  commit 8ae3d03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1187
-0
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e2e/

.bazelrc

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Bazel settings that apply to this repository.
2+
# Take care to document any settings that you expect users to apply.
3+
# Settings that apply only to CI are in .github/workflows/ci.bazelrc
4+
5+
# Required until this is the default; expected in Bazel 7
6+
common --enable_bzlmod
7+
8+
# Don’t want to push a rules author to update their deps if not needed.
9+
# https://bazel.build/reference/command-line-reference#flag--check_direct_dependencies
10+
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
11+
common --check_direct_dependencies=off
12+
13+
# Load any settings specific to the current user.
14+
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
15+
# This needs to be last statement in this
16+
# config, as the user configuration should be able to overwrite flags from this file.
17+
# See https://docs.bazel.build/versions/master/best-practices.html#bazelrc
18+
# (Note that we use .bazelrc.user so the file appears next to .bazelrc in directory listing,
19+
# rather than user.bazelrc as suggested in the Bazel docs)
20+
try-import %workspace%/.bazelrc.user

.bazelversion

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
7.2.1
2+
# The first line of this file is used by Bazelisk and Bazel to be sure
3+
# the right version of Bazel is used to build and test this repo.
4+
# This also defines which version is used on CI.
5+
#
6+
# Note that you should also run integration_tests against other Bazel
7+
# versions you support.

.bcr/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Bazel Central Registry
2+
3+
When the ruleset is released, we want it to be published to the
4+
Bazel Central Registry automatically:
5+
<https://registry.bazel.build>
6+
7+
This folder contains configuration files to automate the publish step.
8+
See <https://github.com/bazel-contrib/publish-to-bcr/blob/main/templates/README.md>
9+
for authoritative documentation about these files.

.bcr/config.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# See https://github.com/bazel-contrib/publish-to-bcr#a-note-on-release-automation
2+
# for guidance about whether to uncomment this section:
3+
#
4+
# fixedReleaser:
5+
# login: my_github_handle
6+

.bcr/metadata.template.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"homepage": "https://github.com/myorg/rules_mylang",
3+
"maintainers": [],
4+
"repository": ["github:myorg/rules_mylang"],
5+
"versions": [],
6+
"yanked_versions": {}
7+
}

.bcr/presubmit.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bcr_test_module:
2+
module_path: "e2e/smoke"
3+
matrix:
4+
platform: ["debian10", "macos", "ubuntu2004", "windows"]
5+
bazel: ["7.x", "6.x"]
6+
tasks:
7+
run_tests:
8+
name: "Run test module"
9+
platform: ${{ platform }}
10+
bazel: ${{ bazel }}
11+
test_targets:
12+
- "//..."

.bcr/source.template.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrity": "**leave this alone**",
3+
"strip_prefix": "{REPO}-{VERSION}",
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz"
5+
}

.devcontainer/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM mcr.microsoft.com/devcontainers/base:bookworm
2+
3+
# Download bazelisk and place it in $PATH
4+
RUN wget https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/bazelisk-linux-amd64
5+
RUN chmod +x bazelisk-linux-amd64
6+
RUN mv bazelisk-linux-amd64 /usr/local/bin/bazel
7+
8+
# Install python3 and pip to setup pre-commit
9+
RUN apt update && apt install -y --no-install-recommends \
10+
python3-setuptools \
11+
python3-pip \
12+
python3-dev \
13+
python3-venv
14+
15+
# Install pre-commit
16+
RUN pip install --break-system-packages pre-commit

.devcontainer/devcontainer.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"build": {
3+
// instructs devcontainers to use a Dockerfile
4+
// rather than a pre-defined image
5+
"dockerfile": "Dockerfile"
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"ms-azuretools.vscode-docker", // docker support
11+
"BazelBuild.vscode-bazel" // bazel support
12+
]
13+
}
14+
},
15+
// sets up pre-commit hooks
16+
"postStartCommand": "pre-commit install"
17+
}
18+

.gitattributes

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# In code review, collapse generated files
2+
docs/*.md linguist-generated=true
3+
4+
#################################
5+
# Configuration for 'git archive'
6+
# See https://git-scm.com/docs/git-archive#ATTRIBUTES
7+
8+
# Don't include examples in the distribution artifact, to reduce size.
9+
# You may want to add additional exclusions for folders or files that users don't need.
10+
examples export-ignore
11+
12+
# Occasionally there's a need to "stamp" the release version into a file
13+
# See https://blog.aspect.build/releasing-bazel-rulesets-rust for details if you need this.
14+
# mylang/version.bzl export-subst

.github/workflows/BUILD.bazel

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
2+
3+
buildifier(
4+
name = "buildifier.check",
5+
exclude_patterns = ["./.git/*"],
6+
lint_mode = "warn",
7+
mode = "diff",
8+
)

.github/workflows/buildifier.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Buildifier
2+
3+
# Controls when the action will run.
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the main branch
6+
push:
7+
branches: [main]
8+
pull_request:
9+
branches: [main]
10+
# Allows you to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
13+
jobs:
14+
check:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: buildifier
19+
run: bazel run --enable_bzlmod //.github/workflows:buildifier.check

.github/workflows/ci.bazelrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file contains Bazel settings to apply on CI only.
2+
# It is referenced with a --bazelrc option in the call to bazel in ci.yaml
3+
4+
# Debug where options came from
5+
build --announce_rc
6+
# This directory is configured in GitHub actions to be persisted between runs.
7+
# We do not enable the repository cache to cache downloaded external artifacts
8+
# as these are generally faster to download again than to fetch them from the
9+
# GitHub actions cache.
10+
build --disk_cache=~/.cache/bazel
11+
# Don't rely on test logs being easily accessible from the test runner,
12+
# though it makes the log noisier.
13+
test --test_output=errors
14+
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
15+
test --test_env=XDG_CACHE_HOME

.github/workflows/ci.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: CI
2+
3+
# Controls when the action will run.
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the main branch
6+
push:
7+
branches: [main]
8+
pull_request:
9+
branches: [main]
10+
# Allows you to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
13+
concurrency:
14+
# Cancel previous actions from the same PR or branch except 'main' branch.
15+
# See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info.
16+
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main' && format('::{0}', github.run_id) || ''}}
17+
cancel-in-progress: ${{ github.ref_name != 'main' }}
18+
19+
jobs:
20+
test:
21+
uses: bazel-contrib/.github/.github/workflows/bazel.yaml@v6
22+
with:
23+
folders: |
24+
[
25+
".",
26+
"e2e/smoke"
27+
]
28+
exclude: |
29+
[
30+
{"folder": ".", "bzlmodEnabled": false}
31+
]
32+
# For branch protection settings, this job provides a "stable" name that can be used to gate PR merges
33+
# on "all matrix jobs were successful".
34+
conclusion:
35+
needs: test
36+
runs-on: ubuntu-latest
37+
if: always()
38+
steps:
39+
- uses: technote-space/workflow-conclusion-action@45ce8e0eb155657ab8ccf346ade734257fd196a5 # v3.0.3
40+
41+
# Note: possible conclusion values:
42+
# https://github.com/technote-space/workflow-conclusion-action/blob/main/src/constant.ts
43+
- name: report success
44+
if: ${{ env.WORKFLOW_CONCLUSION == 'success' }}
45+
working-directory: /tmp
46+
run: echo ${{ env.WORKFLOW_CONCLUSION }} && exit 0
47+
48+
- name: report failure
49+
if: ${{ env.WORKFLOW_CONCLUSION == 'failure' }}
50+
working-directory: /tmp
51+
run: echo ${{ env.WORKFLOW_CONCLUSION }} && exit 1

.github/workflows/release.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Cut a release whenever a new tag is pushed to the repo.
2+
# You should use an annotated tag, like `git tag -a v1.2.3`
3+
# and put the release notes into the commit message for the tag.
4+
name: Release
5+
6+
on:
7+
push:
8+
tags:
9+
- "v*.*.*"
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
release:
16+
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v6
17+
with:
18+
release_files: rules_mylang-*.tar.gz

.github/workflows/release_prep.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit -o nounset -o pipefail
4+
5+
# Set by GH actions, see
6+
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
7+
TAG=${GITHUB_REF_NAME}
8+
# The prefix is chosen to match what GitHub generates for source archives
9+
# This guarantees that users can easily switch from a released artifact to a source archive
10+
# with minimal differences in their code (e.g. strip_prefix remains the same)
11+
PREFIX="rules_mylang-${TAG:1}"
12+
ARCHIVE="rules_mylang-$TAG.tar.gz"
13+
14+
# NB: configuration for 'git archive' is in /.gitattributes
15+
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
16+
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
17+
18+
cat << EOF
19+
## Using Bzlmod with Bazel 6 or greater
20+
21+
1. (Bazel 6 only) Enable with \`common --enable_bzlmod\` in \`.bazelrc\`.
22+
2. Add to your \`MODULE.bazel\` file:
23+
24+
\`\`\`starlark
25+
bazel_dep(name = "com_myorg_rules_mylang", version = "${TAG:1}")
26+
\`\`\`
27+
28+
## Using WORKSPACE
29+
30+
Paste this snippet into your \`WORKSPACE.bazel\` file:
31+
32+
\`\`\`starlark
33+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
34+
http_archive(
35+
name = "com_myorg_rules_mylang",
36+
sha256 = "${SHA}",
37+
strip_prefix = "${PREFIX}",
38+
url = "https://github.com/myorg/rules_mylang/releases/download/${TAG}/${ARCHIVE}",
39+
)
40+
EOF
41+
42+
awk 'f;/--SNIP--/{f=1}' e2e/smoke/WORKSPACE.bazel
43+
echo "\`\`\`"

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bazel-*
2+
.bazelrc.user
3+
.idea/
4+
.ijwb/

.pre-commit-config.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# See CONTRIBUTING.md for instructions.
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
5+
# Commitizen runs in commit-msg stage
6+
# but we don't want to run the other hooks on commit messages
7+
default_stages: [commit]
8+
9+
# Use a slightly older version of node by default
10+
# as the default uses a very new version of GLIBC
11+
default_language_version:
12+
node: 16.18.0
13+
14+
repos:
15+
# Check formatting and lint for starlark code
16+
- repo: https://github.com/keith/pre-commit-buildifier
17+
rev: 6.1.0.1
18+
hooks:
19+
- id: buildifier
20+
- id: buildifier-lint
21+
# Enforce that commit messages allow for later changelog generation
22+
- repo: https://github.com/commitizen-tools/commitizen
23+
rev: v2.18.0
24+
hooks:
25+
# Requires that commitizen is already installed
26+
- id: commitizen
27+
stages: [commit-msg]
28+
- repo: https://github.com/pre-commit/mirrors-prettier
29+
rev: "v2.4.0"
30+
hooks:
31+
- id: prettier

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/*.md

BUILD.bazel

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
2+
3+
gazelle_binary(
4+
name = "gazelle_bin",
5+
languages = ["@bazel_skylib_gazelle_plugin//bzl"],
6+
)
7+
8+
gazelle(
9+
name = "gazelle",
10+
gazelle = "gazelle_bin",
11+
)

CONTRIBUTING.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# How to Contribute
2+
3+
## Using devcontainers
4+
5+
If you are using [devcontainers](https://code.visualstudio.com/docs/devcontainers/containers)
6+
and/or [codespaces](https://github.com/features/codespaces) then you can start
7+
contributing immediately and skip the next step.
8+
9+
## Formatting
10+
11+
Starlark files should be formatted by buildifier.
12+
We suggest using a pre-commit hook to automate this.
13+
First [install pre-commit](https://pre-commit.com/#installation),
14+
then run
15+
16+
```shell
17+
pre-commit install
18+
```
19+
20+
Otherwise later tooling on CI will yell at you about formatting/linting violations.
21+
22+
## Updating BUILD files
23+
24+
Some targets are generated from sources.
25+
Currently this is just the `bzl_library` targets.
26+
Run `bazel run //:gazelle` to keep them up-to-date.
27+
28+
## Using this as a development dependency of other rules
29+
30+
You'll commonly find that you develop in another WORKSPACE, such as
31+
some other ruleset that depends on rules_mylang, or in a nested
32+
WORKSPACE in the integration_tests folder.
33+
34+
To always tell Bazel to use this directory rather than some release
35+
artifact or a version fetched from the internet, run this from this
36+
directory:
37+
38+
```sh
39+
OVERRIDE="--override_repository=rules_mylang=$(pwd)/rules_mylang"
40+
echo "common $OVERRIDE" >> ~/.bazelrc
41+
```
42+
43+
This means that any usage of `@rules_mylang` on your system will point to this folder.
44+
45+
## Releasing
46+
47+
1. Determine the next release version, following semver (could automate in the future from changelog)
48+
1. Tag the repo and push it (or create a tag in GH UI)
49+
1. Watch the automation run on GitHub actions

0 commit comments

Comments
 (0)