Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
with:
release_files: rules_d-*.tar.gz
prerelease: false
tag_name: ${{ github.ref_name }}
tag_name: ${{ inputs.tag_name || github.ref_name }}
publish:
needs: release
uses: ./.github/workflows/publish.yaml
with:
tag_name: ${{ github.ref_name }}
tag_name: ${{ inputs.tag_name || github.ref_name }}
secrets:
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}
34 changes: 27 additions & 7 deletions .github/workflows/tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ on:
# Allow devs to tag manually through the GitHub UI.
# For example after landing a fix that customers are waiting for.
workflow_dispatch:
# Run twice a month, on the 1rst and 15th at 3PM UTC (8AM PST)
# This is a trade-off between making too many releases,
# which overwhelms BCR maintainers and over-notifies users,
# and releasing too infrequently which delays delivery of bugfixes and features.
schedule:
- cron: "0 15 1,15 * *"
- cron: "0 15 * * *" # Daily at 3PM UTC
jobs:
tag:
permissions:
Expand All @@ -22,11 +18,33 @@ jobs:
outputs:
new-tag: ${{ steps.ccv.outputs.new-tag }}
new-tag-version: ${{steps.ccv.outputs.new-tag-version}}
new-tag-version-type: ${{steps.ccv.outputs.new-tag-version-type}}
recently-tagged: ${{steps.recent-tag.outputs.recently-tagged}}
steps:
- uses: actions/checkout@v5
with:
# Need enough history to find the prior release tag
fetch-depth: 0
- name: Check if there is a recent tag
id: recent-tag
# Only skip on cron trigger, not manual trigger
if: github.event_name == 'schedule'
run: |
# This is a trade-off between making too many releases,
# which overwhelms BCR maintainers and over-notifies users,
# and releasing too infrequently which delays delivery of bugfixes and features.
MAX_AGE=1209600 # 2 weeks
TAG=$(git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]*' --abbrev=0 2>/dev/null) || {
echo "No matching tag — continue workflow."
exit 0
}
TAG_TIME=$(git log -1 --format=%ct "$TAG")
NOW=$(date +%s)
AGE=$((NOW - TAG_TIME))
echo "Latest tag: $TAG ($AGE seconds ago)"
if [ "$AGE" -lt "$MAX_AGE" ]; then
echo "recently-tagged=true" >> "$GITHUB_OUTPUT"
fi
- name: Bump tag if necessary
id: ccv
uses: smlx/ccv@7318e2f25a52dcd550e75384b84983973251a1f8 # v0.10.0
Expand All @@ -37,6 +55,8 @@ jobs:
tag_name: ${{ needs.tag.outputs.new-tag-version }}
secrets:
publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }}
if: needs.tag.outputs.new-tag == 'true' && needs.tag.outputs.new-tag-version-type != 'major'
if: needs.tag.outputs.new-tag == 'true' && needs.tag.outputs.new-tag-version-type != 'major' && needs.tag.outputs.recently-tagged != 'true'
permissions:
contents: write # allow create release
contents: write
id-token: write
attestations: write
21 changes: 14 additions & 7 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@package_metadata//licenses/rules:license.bzl", "license")
load("@package_metadata//purl:purl.bzl", "purl")
load("@package_metadata//rules:package_metadata.bzl", "package_metadata")

gazelle_binary(
name = "gazelle_bin",
languages = ["@bazel_skylib_gazelle_plugin//bzl"],
package_metadata(
name = "package_metadata",
purl = purl.bazel(
module_name(),
module_version(),
),
visibility = ["//visibility:public"],
)

gazelle(
name = "gazelle",
gazelle = "gazelle_bin",
license(
name = "license",
kind = "@package_metadata//licenses/spdx:Apache-2.0",
text = "LICENSE",
)
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Otherwise later tooling on CI will yell at you about formatting/linting violatio

Some targets are generated from sources.
Currently this is just the `bzl_library` targets.
Run `bazel run //:gazelle` to keep them up-to-date.
Run `bazel run //tools:gazelle` to keep them up-to-date.

## Using this as a development dependency of other rules

Expand Down
30 changes: 28 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,35 @@

module(
name = "rules_d",
version = "0.0.0",

# NOTE:
# Always leave version unset or set to "" (the default). The default value
# can prevent issues when the module is used via non-registry overrides
# (e.g. https://github.com/bazel-contrib/rules_go/issues/4380).
#
# The publish.yaml GitHub Action sets the version in the registry to the
# release version by patching this MODULE.bazel file in the pull request to
# the BCR.
#
# For more info, see this Slack thread:
# https://bazelbuild.slack.com/archives/CA31HN1T3/p1750406404452179
version = "",

# NOTE:
# Bumping compatibility_level too frequently is discouraged because it's
# very disruptive: as soon as a module is requested at two different
# compatibility levels in the dependency tree, users will see an error.
#
# As such, the compatibility_level (1) should be bumped *only* when the
# breaking change affects most use cases and isn't easy to migrate and/or
# work-around, and (2) *in the same commit* that introduces an incompatible
# (breaking) change.
compatibility_level = 1,
)

bazel_dep(name = "bazel_features", version = "1.32.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "package_metadata", version = "0.0.2")
bazel_dep(name = "package_metadata", version = "0.0.5")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_cc", version = "0.0.10")

Expand All @@ -19,6 +41,10 @@ bazel_dep(name = "gazelle", version = "0.42.0", dev_dependency = True, repo_name
bazel_dep(name = "rules_shell", version = "0.3.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.7.1", dev_dependency = True)

# NOTE:
# It is recommended to specify the exact d_version (ex. "dmd-2.111.0") for reproducible builds.
# Setting d_version = "auto" here ensures aarch64 CI works out of the box,
# but using "auto" may lead to non-reproducible builds and is not recommended.
d = use_extension("//d:extensions.bzl", "d")
d.toolchain(d_version = "auto")
use_repo(d, "d_toolchains")
Expand Down
2 changes: 1 addition & 1 deletion REPO.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

repo(
default_package_metadata = [
"//d:package_metadata",
"//:package_metadata",
],
)
32 changes: 11 additions & 21 deletions d/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@package_metadata//rules:package_metadata.bzl", "package_metadata")
load("//d/private:resolved_toolchain.bzl", "resolved_toolchain")

package_metadata(
name = "package_metadata",
purl = "pkg:bazel/{}@{}".format(
module_name(),
module_version(),
),
visibility = ["//visibility:public"],
)

# For stardoc to reference the files
exports_files(["defs.bzl"])

Expand All @@ -30,6 +20,17 @@ resolved_toolchain(
visibility = ["//visibility:public"],
)

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
visibility = ["//visibility:public"],
deps = [
"//d/private/rules:binary",
"//d/private/rules:library",
"//d/private/rules:test",
],
)

bzl_library(
name = "repositories",
srcs = ["repositories.bzl"],
Expand All @@ -49,17 +50,6 @@ bzl_library(
deps = [":repositories"],
)

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
visibility = ["//visibility:public"],
deps = [
"//d/private/rules:binary",
"//d/private/rules:library",
"//d/private/rules:test",
],
)

bzl_library(
name = "toolchain",
srcs = ["toolchain.bzl"],
Expand Down
6 changes: 3 additions & 3 deletions d/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def rules_d_dependencies():
)
http_archive(
name = "package_metadata",
sha256 = "32299ff025ceb859328557fbb3dd42464ad2520e25969188c230b45638feb949",
strip_prefix = "supply-chain-0.0.2/metadata",
url = "https://github.com/bazel-contrib/supply-chain/releases/download/v0.0.2/supply-chain-v0.0.2.tar.gz",
sha256 = "49ed11e5d6b752c55fa539cbb10b2736974f347b081d7bd500a80dacb7dbec06",
strip_prefix = "supply-chain-0.0.5/metadata",
url = "https://github.com/bazel-contrib/supply-chain/releases/download/v0.0.5/supply-chain-v0.0.5.tar.gz",
)

########
Expand Down
11 changes: 11 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")

gazelle_binary(
name = "gazelle_bin",
languages = ["@bazel_skylib_gazelle_plugin//bzl"],
)

gazelle(
name = "gazelle",
gazelle = "gazelle_bin",
)
Loading