Skip to content

Commit

Permalink
Automate releases just by pushing a tag (#55)
Browse files Browse the repository at this point in the history
This comes from the bazel-contrib/rules-template
  • Loading branch information
alexeagle authored Apr 25, 2022
1 parent 33b65d2 commit 637c2b7
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 102 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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

on:
push:
tags:
- "*.*.*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Mount bazel caches
uses: actions/cache@v2
with:
path: |
"~/.cache/bazel"
"~/.cache/bazel-repo"
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-
- name: bazel test //...
env:
# Bazelisk will download bazel to here
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...
- name: Prepare workspace snippet
run: .github/workflows/workspace_snippet.sh ${{ env.GITHUB_REF_NAME }} > release_notes.txt
- name: Release
uses: softprops/action-gh-release@v1
with:
# Use GH feature to populate the changelog automatically
generate_release_notes: true
body_path: release_notes.txt
42 changes: 42 additions & 0 deletions .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/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}
PREFIX="bazel-mypy-integration-${TAG}"
SHA=$(git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip | shasum -a 256 | awk '{print $1}')

cat << EOF
WORKSPACE snippet:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "mypy_integration",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/thundergolfer/bazel-mypy-integration/archive/refs/tags/${TAG}.tar.gz",
)
load(
"@mypy_integration//repositories:repositories.bzl",
mypy_integration_repositories = "repositories",
)
mypy_integration_repositories()
load("@mypy_integration//:config.bzl", "mypy_configuration")
# Optionally pass a MyPy config file, otherwise pass no argument.
mypy_configuration("//tools/typing:mypy.ini")
load("@mypy_integration//repositories:deps.bzl", mypy_integration_deps = "deps")
mypy_integration_deps(
mypy_requirements_file="//tools/typing:mypy_version.txt",
# python_interpreter = "python3.9" # $PATH is searched for exe.
# OR
# python_interpreter_target = "@python3_interpreter//:bin/python3",
)
\`\`\`
EOF
35 changes: 0 additions & 35 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_python//:version.bzl", "version")

package(default_visibility = ["//visibility:private"])

Expand All @@ -22,36 +20,3 @@ exports_files([
"LICENSE",
"version.bzl",
])

filegroup(
name = "distribution",
srcs = [
"BUILD",
"LICENSE",
"config.bzl",
"current_mypy_version.txt",
"mypy.bzl",
"rules.bzl",
"//mypy:distribution",
"//repositories:distribution",
"//templates:distribution",
"//third_party:distribution",
],
)

version = "0.2.1"

# Build the artifact to put on the github release page.
pkg_tar(
name = "bazel_mypy_integration-{version}".format(version = version),
srcs = [
":distribution",
],
extension = "tar.gz",
# It is all source code, so make it read-only.
mode = "0444",
# Make it owned by root
owner = "0.0",
package_dir = ".",
strip_prefix = ".",
)
34 changes: 3 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,10 @@ mypy==0.790

(In the [`examples/`](examples/) Bazel workspace this file is specified in [`tools/typing/`](examples/tools/typing))

**2. Next, add the following to your `WORKSPACE`:**
**2. Next, copy the `WORKSPACE` snippet**

```python
mypy_integration_version = "0.2.1" # latest @ September 28th 2021

http_archive(
name = "mypy_integration",
sha256 = "e9701c43bdf4082b1719d91954b7838c85021e086a26e1b7c8adbe6fbff3c7ef",
url = "https://github.com/thundergolfer/bazel-mypy-integration/releases/download/{version}/bazel_mypy_integration-{version}.tar.gz".format(
version = mypy_integration_version,
),
)

load(
"@mypy_integration//repositories:repositories.bzl",
mypy_integration_repositories = "repositories",
)
mypy_integration_repositories()

load("@mypy_integration//:config.bzl", "mypy_configuration")
# Optionally pass a MyPy config file, otherwise pass no argument.
mypy_configuration("//tools/typing:mypy.ini")

load("@mypy_integration//repositories:deps.bzl", mypy_integration_deps = "deps")

mypy_integration_deps(
mypy_requirements_file="//tools/typing:mypy_version.txt",
# python_interpreter = "python3.9" # $PATH is searched for exe.
# OR
# python_interpreter_target = "@python3_interpreter//:bin/python3",
)
```
This can be found in the [releases page](https://github.com/thundergolfer/bazel-mypy-integration/releases)
for the release you use.

_Note_ that by default `mypy_integration_deps` will default to passing `"python3"` as the interpreter used at install,
but this can be overridden by setting `python_interpreter` or `python_interpreter_target` (but not both).
Expand Down
13 changes: 0 additions & 13 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,3 @@ http_archive(
strip_prefix = "buildtools-master",
url = "https://github.com/bazelbuild/buildtools/archive/master.zip",
)

########################
# OTHER
########################

http_archive(
name = "rules_pkg",
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
],
)
6 changes: 0 additions & 6 deletions mypy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@ py_binary(
requirement("mypy"),
],
)

filegroup(
name = "distribution",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)
5 changes: 0 additions & 5 deletions repositories/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
filegroup(
name = "distribution",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)
6 changes: 0 additions & 6 deletions templates/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
exports_files(["mypy.sh.tpl"])

filegroup(
name = "distribution",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)
6 changes: 0 additions & 6 deletions third_party/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
exports_files(["mypy.sh.tpl"])

filegroup(
name = "distribution",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)

0 comments on commit 637c2b7

Please sign in to comment.