Skip to content

Commit

Permalink
Add BCR configurations for publishing releases to the central registry (
Browse files Browse the repository at this point in the history
#1038)

Co-authored-by: Corbin McNeely-Smith <58151731+restingbull@users.noreply.github.com>
  • Loading branch information
Bencodes and restingbull committed Oct 20, 2023
1 parent 55f60ec commit 11f55e8
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 55 deletions.
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: Bencodes
email: ben@ben.cm
25 changes: 25 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"homepage": "https://github.com/bazelbuild/rules_kotlin",
"maintainers": [
{
"email": "ben@ben.cm",
"github": "Bencodes",
"name": "Ben Lee"
},
{
"email": "corbin@mcneely-smith.com",
"github": "restingbull",
"name": "Corbin McNeely-Smith"
},
{
"email": "nk@snap.com",
"github": "nkoroste",
"name": "Nick Korostelev"
}
],
"repository": [
"github:bazelbuild/rules_kotlin"
],
"versions": [],
"yanked_versions": {}
}
12 changes: 12 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
matrix:
platform: [ "macos", "ubuntu2004" ]

tasks:
verify_targets:
name: "Verify build targets"
platform: ${{ platform }}
build_flags:
- "--enable_bzlmod=true"
build_targets:
- "@rules_kotlin//kotlin/..."
- "@rules_kotlin//src/..."
4 changes: 4 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"integrity": "",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_kotlin-{TAG}.tar.gz"
}
20 changes: 20 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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
common --curses=no
common --enable_bzlmod

build --verbose_failures
build --worker_verbose

# 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
58 changes: 27 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
# Cut a release whenever a new tag is pushed to the repo.
# You should use an annotated tag, like `git tag -a v1.2.3`
# and put the release notes into the commit message for the tag.
name: Release Binary Package
on:
push:
tags:
- v*
- "v*.*.*"

jobs:
generate:
name: Create release-artifacts
build:
runs-on: ubuntu-latest
steps:
- name: "Checkout the sources"
uses: actions/checkout@v2.3.1
- name: Checkout
uses: actions/checkout@v3
- name: Mount bazel caches
uses: actions/cache@v3
with:
path: |
~/.cache/bazel
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bzlmod') }}
restore-keys: bazel-cache-
- name: Install JDK 11
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "11"
- name: Setup Bazelisk
uses: bazelbuild/setup-bazelisk@v1
- name: Mount bazel cache
uses: actions/cache@v2
with:
path: "/home/runner/.cache/bazel"
key: caches-${{ runner.os }}-release
- name: Build release artifact
run: bazelisk build //:rules_kotlin_release
- name: Create release sha256
run: shasum -a 256 bazel-bin/rules_kotlin_release.tgz > bazel-bin/rules_kotlin_release.tgz.sha256
- name: Upload bazel-bin/rules_kotlin_release.tgz
uses: svenstaro/upload-release-action@2.2.1
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: bazel-bin/rules_kotlin_release.tgz
asset_name: rules_kotlin_release.tgz
tag: ${{ github.ref }}
overwrite: true
- name: Upload bazel-bin/rules_kotlin_release.tgz.sha256
uses: svenstaro/upload-release-action@2.2.1
- name: Prepare release notes and artifacts
env:
# Bazelisk will download bazel to here.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: .github/workflows/release_prep.sh ${{ env.GITHUB_REF_NAME }} > release_notes.txt
- name: Release
uses: softprops/action-gh-release@v1
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: bazel-bin/rules_kotlin_release.tgz.sha256
asset_name: rules_kotlin_release.tgz.sha256
tag: ${{ github.ref }}
overwrite: true
prerelease: true
# Use GH feature to populate the changelog automatically
generate_release_notes: true
body_path: release_notes.txt
fail_on_unmatched_files: true
files: rules_kotlin-*.tar.gz
39 changes: 39 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}
# The prefix is chosen to match what GitHub generates for source archives
PREFIX="rules_kotlin-${TAG:1}"
ARCHIVE="rules_kotlin-$TAG.tar.gz"
bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc build //:rules_kotlin_release
cp bazel-bin/rules_kotlin_release.tgz $ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

cat << EOF
## Using Bzlmod with Bazel 6
1. Enable with \`common --enable_bzlmod\` in \`.bazelrc\`.
2. Add to your \`MODULE.bazel\` file:
\`\`\`starlark
bazel_dep(name = "rules_kotlin", version = "${TAG:1}")
\`\`\`
## Using WORKSPACE
Paste this snippet into your `WORKSPACE.bazel` file:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_kotlin",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/buildfoundation/rules_kotlin/releases/download/${TAG}/${ARCHIVE}",
)
EOF

echo "\`\`\`"
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @ahumesky @cgruber @djwhang @timpeut @restingbull
* @ahumesky @cgruber @restingbull @Bencodes @nkoroste
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ remote_android_extensions = use_extension("@bazel_tools//tools/android:android_e
use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools")

# Development dependencies
# TODO(bencodes) A bunch of these dependencies need to be marked as dev_dependencies but before we can do that
# we need to sort out a few cases around how these rules are consumed in various ways.

bazel_dep(name = "rules_jvm_external", version = "5.3")

Expand Down Expand Up @@ -67,5 +69,3 @@ use_repo(maven, "kotlin_rules_maven")
bazel_dep(name = "rules_pkg", version = "0.7.0")
bazel_dep(name = "stardoc", version = "0.5.6", repo_name = "io_bazel_stardoc")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")

register_toolchains("@rules_kotlin//kotlin/internal:default_toolchain")
8 changes: 1 addition & 7 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@rules_android//android:rules.bzl", "android_sdk_repository")

maybe(
android_sdk_repository,
name = "androidsdk",
)
android_sdk_repository(name = "androidsdk")
8 changes: 1 addition & 7 deletions WORKSPACE.dev.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,4 @@ kotlin_repositories()

register_toolchains("@rules_kotlin//kotlin/internal:default_toolchain")

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@rules_android//android:rules.bzl", "android_sdk_repository")

maybe(
android_sdk_repository,
name = "androidsdk",
)
android_sdk_repository(name = "androidsdk")
8 changes: 1 addition & 7 deletions WORKSPACE.release.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,4 @@ kotlin_repositories()

register_toolchains("@rules_kotlin//kotlin/internal:default_toolchain")

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@rules_android//android:rules.bzl", "android_sdk_repository")

maybe(
android_sdk_repository,
name = "androidsdk",
)
android_sdk_repository(name = "androidsdk")

0 comments on commit 11f55e8

Please sign in to comment.