From 95f25f8b94a860e6fa0c78a5eead57a65bf2d8ce Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 1 Nov 2023 15:44:30 -0700 Subject: [PATCH 1/2] chore: automate releases just by pushing a tag Based on the "best practices" from the https://github.com/bazel-contrib/rules-template --- .bcr/source.template.json | 6 +++--- .github/workflows/release.yaml | 18 ++++++++++++++++++ .github/workflows/release_prep.sh | 24 ++++++++++++++++++++++++ CONTRIBUTING.md | 9 +++++++++ MODULE.bazel | 5 ++++- 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/release_prep.sh create mode 100644 CONTRIBUTING.md diff --git a/.bcr/source.template.json b/.bcr/source.template.json index f276fcf..1eb36c0 100644 --- a/.bcr/source.template.json +++ b/.bcr/source.template.json @@ -1,5 +1,5 @@ { - "integrity": "", - "strip_prefix": "robolectric-bazel-{TAG}", - "url": "https://github.com/robolectric/robolectric-bazel/archive/refs/tags/{TAG}.tar.gz" + "integrity": "**filled during publishing**", + "strip_prefix": "{REPO}-{TAG}", + "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz" } diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..9e047d6 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,18 @@ +# Automatically perform a release whenever a new "release-like" tag is pushed to the repo. +name: Release + +on: + push: + tags: + # Detect tags that look like a release. + # Note that we don't use a "v" prefix to help anchor this pattern. + # This is purely a matter of preference. + - "*.*.*" + +jobs: + release: + # Re-use https://github.com/bazel-contrib/.github/blob/v5/.github/workflows/release_ruleset.yaml + uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v5 + with: + prerelease: false + release_files: roboelectric-bazel-*.tar.gz diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh new file mode 100644 index 0000000..a196423 --- /dev/null +++ b/.github/workflows/release_prep.sh @@ -0,0 +1,24 @@ +#!/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 +readonly TAG=${GITHUB_REF_NAME} +# The prefix is chosen to match what GitHub generates for source archives. +# This guarantees that users can easily switch from a released artifact to a source archive +# with minimal differences in their code (e.g. strip_prefix remains the same) +readonly PREFIX="roboelectric-bazel-${TAG}" +readonly ARCHIVE="${PREFIX}.tar.gz" + +# NB: configuration for 'git archive' is in /.gitattributes +git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE +SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') + +# The stdout of this program will be used as the top of the release notes for this release. +cat << EOF +Installation +------------ + +Instructions appear in the [README](https://github.com/robolectric/robolectric-bazel/tree/${TAG}#usage) +EOF diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..671a2e4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,9 @@ +## Releasing + +To perform a release, simply tag the commit you wish to release, for example: + +``` +roboelectric-bazel$ git fetch +roboelectric-bazel$ git tag 1.2.3 origin/main +roboelectric-bazel$ git push origin 1.2.3 +``` diff --git a/MODULE.bazel b/MODULE.bazel index 4ea591d..2d598ca 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,9 @@ +"Bazel dependencies" + module( name = "rules_robolectric", - version = "4.11", + # Note: the publish-to-BCR app will patch this line to stamp the version being published. + version = "0.0.0", bazel_compatibility = [">=6.0.0"], compatibility_level = 1, ) From 8e43b3977db71863362582f5c37c3ef5ea25fee1 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 1 Nov 2023 17:55:39 -0700 Subject: [PATCH 2/2] chore: move install instructions to release notes This way they get the version bump and sha256 automatically. --- .github/workflows/release_prep.sh | 37 ++++++++++++++++++-- README.md | 58 +++---------------------------- examples/simple/WORKSPACE | 9 ++--- 3 files changed, 44 insertions(+), 60 deletions(-) diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh index a196423..72a514a 100644 --- a/.github/workflows/release_prep.sh +++ b/.github/workflows/release_prep.sh @@ -17,8 +17,39 @@ SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') # The stdout of this program will be used as the top of the release notes for this release. cat << EOF -Installation ------------- +### Bzlmod (MODULE.bazel) -Instructions appear in the [README](https://github.com/robolectric/robolectric-bazel/tree/${TAG}#usage) +> If using Bazel 6, make sure you set the \`--enable_bzlmod\` flag + +\`\`\`starlark +bazel_dep(name = "rules_robolectric", version = "${TAG}") + +bazel_dep(name = "rules_jvm_external", version = "5.3") +maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") +maven.install( + artifacts = [ + "org.robolectric:robolectric:${TAG}", + ], + repositories = [ + "https://maven.google.com", + "https://repo1.maven.org/maven2", + ], +) +use_repo(maven, "maven") +\`\`\` + +### Workspace + +Add the `robolectric` and `rules_jvm_external` repositories in your WORKSPACE file: + +\`\`\`starlark +http_archive( + name = "robolectric", + sha256 = "${SHA}", + strip_prefix = "${PREFIX}", + urls = ["https://github.com/robolectric/robolectric-bazel/releases/download/${TAG}/${ARCHIVE}"], +) EOF + +awk 'f;/--SNIP--/{f=1}' examples/simple/WORKSPACE +echo "\`\`\`" diff --git a/README.md b/README.md index 1368863..4609872 100644 --- a/README.md +++ b/README.md @@ -8,62 +8,14 @@ projects.
-## Usage - -### Bzlmod (MODULE.bazel) - -```Python -bazel_dep(name = "rules_robolectric", version = "4.11") - -bazel_dep(name = "rules_jvm_external", version = "5.3") -maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") -maven.install( - artifacts = [ - "org.robolectric:robolectric:4.11", - ], - repositories = [ - "https://maven.google.com", - "https://repo1.maven.org/maven2", - ], -) -use_repo(maven, "maven") -``` +## Installation -### Workspace +Follow instructions in the release notes from the release you use: + -Add the `robolectric` and `rules_jvm_external` repositories in your WORKSPACE file: - -```python -http_archive( - name = "robolectric", - urls = ["https://github.com/robolectric/robolectric-bazel/archive/refs/tags/4.11.tar.gz"], - strip_prefix = "robolectric-bazel-4.11", - sha256 = "get the sha256 from github releases", -) -load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories") -robolectric_repositories() - -http_archive( - name = "rules_jvm_external", - strip_prefix = "rules_jvm_external-5.3", - sha256 = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac", - url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/5.3/rules_jvm_external-5.3.tar.gz", -) -load("@rules_jvm_external//:defs.bzl", "maven_install") -maven_install( - artifacts = [ - "org.robolectric:robolectric:4.11", - ], - repositories = [ - "https://maven.google.com", - "https://repo1.maven.org/maven2", - ], -) -``` - -### And Finally +## Usage -Then, in your `android_local_test` targets in the BUILD files, depend on the +In your `android_local_test` targets in the BUILD files, depend on the Robolectric targets `@maven//:org_robolectric_robolectric` and `@robolectric//bazel:android-all`: diff --git a/examples/simple/WORKSPACE b/examples/simple/WORKSPACE index 0840516..75569bf 100644 --- a/examples/simple/WORKSPACE +++ b/examples/simple/WORKSPACE @@ -7,10 +7,6 @@ local_repository( path = "../../", ) -load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories") - -robolectric_repositories() - http_archive( name = "bazel_skylib", sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d", @@ -32,6 +28,11 @@ load("@rules_android//android:rules.bzl", "android_sdk_repository") android_sdk_repository(name = "androidsdk") +#---SNIP--- Below here is re-used in the workspace snippet published on releases +load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories") + +robolectric_repositories() + http_archive( name = "rules_jvm_external", sha256 = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac",