From 637c2b7e3473b89ccf9a6c5efde312b82e1cd963 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Mon, 25 Apr 2022 06:56:59 -0700 Subject: [PATCH] Automate releases just by pushing a tag (#55) This comes from the bazel-contrib/rules-template --- .github/workflows/release.yml | 37 +++++++++++++++++++++++ .github/workflows/workspace_snippet.sh | 42 ++++++++++++++++++++++++++ BUILD | 35 --------------------- README.md | 34 ++------------------- WORKSPACE | 13 -------- mypy/BUILD | 6 ---- repositories/BUILD | 5 --- templates/BUILD | 6 ---- third_party/BUILD | 6 ---- 9 files changed, 82 insertions(+), 102 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 .github/workflows/workspace_snippet.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..813b53a --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/.github/workflows/workspace_snippet.sh b/.github/workflows/workspace_snippet.sh new file mode 100755 index 0000000..e6dadc5 --- /dev/null +++ b/.github/workflows/workspace_snippet.sh @@ -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 diff --git a/BUILD b/BUILD index e426387..0d5cce9 100644 --- a/BUILD +++ b/BUILD @@ -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"]) @@ -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 = ".", -) diff --git a/README.md b/README.md index 6b03399..9bb31a4 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/WORKSPACE b/WORKSPACE index 5582dcd..9bff0a4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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", - ], -) diff --git a/mypy/BUILD b/mypy/BUILD index c15c946..63bb405 100644 --- a/mypy/BUILD +++ b/mypy/BUILD @@ -10,9 +10,3 @@ py_binary( requirement("mypy"), ], ) - -filegroup( - name = "distribution", - srcs = glob(["**"]), - visibility = ["//:__pkg__"], -) diff --git a/repositories/BUILD b/repositories/BUILD index 07947ee..e69de29 100644 --- a/repositories/BUILD +++ b/repositories/BUILD @@ -1,5 +0,0 @@ -filegroup( - name = "distribution", - srcs = glob(["**"]), - visibility = ["//:__pkg__"], -) diff --git a/templates/BUILD b/templates/BUILD index 54ecb63..820e9a3 100644 --- a/templates/BUILD +++ b/templates/BUILD @@ -1,7 +1 @@ exports_files(["mypy.sh.tpl"]) - -filegroup( - name = "distribution", - srcs = glob(["**"]), - visibility = ["//:__pkg__"], -) diff --git a/third_party/BUILD b/third_party/BUILD index 54ecb63..820e9a3 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -1,7 +1 @@ exports_files(["mypy.sh.tpl"]) - -filegroup( - name = "distribution", - srcs = glob(["**"]), - visibility = ["//:__pkg__"], -)