Skip to content

Commit

Permalink
Move print_rel_notes to a releasing tree and make part of distro (#68)
Browse files Browse the repository at this point in the history
* change print_rel_notes to take package as args

* move print_rel_notes to a releasing tree and make part of distro
  • Loading branch information
aiuto committed Aug 5, 2019
1 parent 5223103 commit da130c4
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 161 deletions.
37 changes: 10 additions & 27 deletions pkg/distro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package(
)

load("@rules_pkg//:pkg.bzl", "pkg_tar", "version")
load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")

# Build the artifact to put on the github release page.
pkg_tar(
name = "rules_pkg-%s" % version,
srcs = [
"@rules_pkg//:standard_package",
"@rules_pkg//releasing:standard_package",
],
strip_prefix = ".",
extension = "tar.gz",
# It is all source code, so make it read-only.
mode = "0444",
Expand All @@ -18,39 +21,19 @@ pkg_tar(
package_dir = ".",
)

py_library(
name = "util",
srcs = [
"__init__.py",
"release_tools.py",
":release_version.py",
],
srcs_version = "PY3",
deps = [
"@bazel_tools//tools/python/runfiles",
],
)

py_binary(
name = "print_rel_notes",
srcs = [
"print_rel_notes.py",
],
data = [
":rules_pkg-%s.tar.gz" % version,
],
python_version = "PY3",
deps = [
":util",
"@bazel_tools//tools/python/runfiles",
],
print_rel_notes(
name = "relnotes",
repo = "rules_pkg",
version = version,
outs = ["relnotes.txt"],
)

py_test(
name = "packaging_test",
size = "large",
srcs = [
"packaging_test.py",
":release_version.py",
],
data = [
":rules_pkg-%s.tar.gz" % version,
Expand All @@ -63,7 +46,7 @@ py_test(
"noci",
],
deps = [
":util",
"@rules_pkg//releasing:release_utils",
"@bazel_tools//tools/python/runfiles",
],
)
Expand Down
15 changes: 9 additions & 6 deletions pkg/distro/packaging_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import unittest

from bazel_tools.tools.python.runfiles import runfiles
from distro import release_tools
from releasing import release_tools
from distro import release_version

_VERBOSE = True
Expand All @@ -30,20 +30,23 @@ class PackagingTest(unittest.TestCase):

def setUp(self):
self.data_files = runfiles.Create()
self.repo = 'rules_pkg'
self.version = release_version.RELEASE_VERSION

def testBuild(self):
# Set up a fresh Bazel workspace
# Set up a fresh Bazel workspace using the currently build repo.
tempdir = os.path.join(os.environ['TEST_TMPDIR'], 'build')
if not os.path.exists(tempdir):
os.makedirs(tempdir)
with open(os.path.join(tempdir, 'WORKSPACE'), 'w') as workspace:
version = release_version.RELEASE_VERSION
file_name = release_tools.package_basename(version)
local_path, sha256 = release_tools.get_package_info(version)
file_name = release_tools.package_basename(self.repo, self.version)
local_path = runfiles.Create().Rlocation(
os.path.join('rules_pkg', 'distro', file_name))
sha256 = release_tools.get_package_sha256(local_path)
workspace_content = '\n'.join((
'workspace(name = "test_rules_pkg_packaging")',
release_tools.workspace_content(
'file://%s' % local_path, sha256)
'file://%s' % local_path, self.repo, sha256)
))
workspace.write(workspace_content)
if _VERBOSE:
Expand Down
55 changes: 0 additions & 55 deletions pkg/distro/print_rel_notes.py

This file was deleted.

73 changes: 0 additions & 73 deletions pkg/distro/release_tools.py

This file was deleted.

42 changes: 42 additions & 0 deletions pkg/releasing/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package(
default_visibility = ["//visibility:public"],
)

# WARNING: 2019-08-05. This is experimental and subject to change.
# It is expected to be available for use concurently with the Bazel
# 1.0 release.

# Sample usage:
# load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")
# print_rel_notes(
# name = "relnotes",
# repo = "rules_pkg",
# version = "2.1",
# outs = ["relnotes.txt"],
# )

filegroup(
name = "standard_package",
srcs = glob(["BUILD", "*.bzl", "*.py", "*.md"]),
visibility = ["@//distro:__pkg__"],
)

py_library(
name = "release_utils",
srcs = [
"__init__.py",
"release_tools.py",
],
srcs_version = "PY3",
)

py_binary(
name = "print_rel_notes",
srcs = [
"print_rel_notes.py",
],
python_version = "PY3",
deps = [
":release_utils",
],
)
Empty file added pkg/releasing/__init__.py
Empty file.
63 changes: 63 additions & 0 deletions pkg/releasing/print_rel_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2019 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Print release notes for a package.
"""

import sys
from string import Template
import textwrap

from releasing import release_tools


def print_notes(repo, version, tarball_path, org='bazelbuild'):
file_name = release_tools.package_basename(repo, version)
sha256 = release_tools.get_package_sha256(tarball_path)

url = 'https://github.com/%s/%s/releases/download/%s/%s' % (
org, repo, version, file_name)
workspace_stanza = release_tools.workspace_content(url, repo, sha256)
relnotes_template = Template(textwrap.dedent(
"""
------------------------ snip ----------------------------
**New Features**
**Incompatible Changes**
**WORKSPACE setup**
```
${workspace_stanza}
```
**Using the rules**
See [the source](https://github.com/${org}/${repo}/tree/master).
------------------------ snip ----------------------------
""").strip())
print(relnotes_template.substitute({
'org': org,
'repo': repo,
'workspace_stanza': workspace_stanza,
}))


def main(args):
print_notes(repo=args[1], version=args[2], tarball_path=args[3])


if __name__ == '__main__':
main(sys.argv)
49 changes: 49 additions & 0 deletions pkg/releasing/release_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2019 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities to help create a rule set release."""

import hashlib
import os
from string import Template
import textwrap


def package_basename(repo, version):
return '%s-%s.tar.gz' % (repo, version)


def get_package_sha256(tarball_path):
with open(tarball_path, 'rb') as pkg_content:
tar_sha256 = hashlib.sha256(pkg_content.read()).hexdigest()
return tar_sha256


def workspace_content(url, repo, sha256):
# Set up a fresh Bazel workspace
workspace_stanza_template = Template(textwrap.dedent(
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "${repo}",
url = "${url}",
sha256 = "${sha256}",
)
load("@${repo}//:deps.bzl", "${repo}_dependencies")
${repo}_dependencies()
""").strip())
return workspace_stanza_template.substitute({
'url': url,
'sha256': sha256,
'repo': repo,
})

0 comments on commit da130c4

Please sign in to comment.