Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: automate releases by pushing a tag #81

Merged
merged 3 commits into from
Nov 2, 2023
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
6 changes: 3 additions & 3 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -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"
}
18 changes: 18 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/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
### Bzlmod (MODULE.bazel)

> 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}",
utzcoz marked this conversation as resolved.
Show resolved Hide resolved
],
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
utzcoz marked this conversation as resolved.
Show resolved Hide resolved
echo "\`\`\`"
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
```
5 changes: 4 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"Bazel dependencies"

module(
name = "rules_robolectric",
version = "4.11.1",
# 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,
)
Expand Down
58 changes: 5 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,14 @@ projects.
<a href="https://github.com/robolectric/robolectric-bazel/releases/latest"><img src="https://img.shields.io/github/v/release/robolectric/robolectric-bazel?display_name=tag&label=Latest%20Stable%20Release"/></a>
<br/>

## Usage

### Bzlmod (MODULE.bazel)

```Python
bazel_dep(name = "rules_robolectric", version = "4.11.1")

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.1",
],
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:
<https://github.com/robolectric/robolectric-bazel/releases>

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.1.tar.gz"],
strip_prefix = "robolectric-bazel-4.11.1",
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.1",
],
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`:

Expand Down
9 changes: 5 additions & 4 deletions examples/simple/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ local_repository(
path = "../../",
)

load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")

robolectric_repositories()

http_archive(
name = "bazel_skylib",
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
Expand All @@ -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",
Expand Down