Skip to content

Commit

Permalink
Always download Buildifier from GitHub.
Browse files Browse the repository at this point in the history
Previously CI used the Buildifier binary from the Docker container if the user did not request a specific version.
However, since we forgot to update the Docker container, it still contained an ancient version (0.22.0 - for comparison, the most recent release is 4.0.1).

With this commit CI will always download a Buildifier binary from GitHub, with "no version" implying "latest".
Moreover, this commit fixes the download logic to recognize binaries of older releases such as 0.4.3.

Consequently, we no longer ship a Buildifier binary as part of the Docker container.

More progress towards bazelbuild#1080.
  • Loading branch information
fweikert committed Apr 1, 2021
1 parent 15fbac4 commit ae3f5d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
6 changes: 0 additions & 6 deletions buildifier/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
FROM python:alpine

# Latest release from: https://github.com/bazelbuild/buildtools/releases
RUN apk add curl && \
curl -Lo /usr/local/bin/buildifier https://github.com/bazelbuild/buildtools/releases/download/0.22.0/buildifier && \
chown root:root /usr/local/bin/buildifier && \
chmod 0755 /usr/local/bin/buildifier

COPY --chown=root:root buildifier.py /usr/local/bin/buildifier.py

ENTRYPOINT [ "/usr/local/bin/buildifier.py" ]
30 changes: 10 additions & 20 deletions buildifier/buildifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_release_urls(release):
buildifier_assets = [
a
for a in release["assets"]
if a["name"] in ("buildifier", "buildifier-linux-amd64")
if a["name"] in ("buildifier", "buildifier-linux-amd64", "buildifier.linux")
]
if not buildifier_assets:
raise Exception(
Expand Down Expand Up @@ -203,25 +203,15 @@ def main(argv=None):

buildifier_binary = "buildifier"
display_url = BUILDIFIER_DEFAULT_DISPLAY_URL
version = os.environ.get(VERSION_ENV_VAR)
if version:
eprint("+++ :github: Downloading Buildifier version '{}'".format(version))
try:
version, display_url, download_url = get_buildifier_info(version)
eprint("Downloading Buildifier {} from {}".format(version, download_url))
buildifier_binary = download_buildifier(download_url)
except Exception as ex:
print_error("downloading Buildifier", str(ex))
return 1

# Determine Buildifier version if the user did not request a specific version.
if not version:
eprint("+++ :female-detective: Detecting Buildifier version")
version_result = run_buildifier(
buildifier_binary, ["--version"], what="Version info"
)
match = BUILDIFIER_VERSION_PATTERN.search(version_result.stdout)
version = match.group(1) if match and match.group(1) != "redacted" else None
version = os.environ.get(VERSION_ENV_VAR, "latest")
eprint("+++ :github: Downloading Buildifier version '{}'".format(version))
try:
version, display_url, download_url = get_buildifier_info(version)
eprint("Downloading Buildifier {} from {}".format(version, download_url))
buildifier_binary = download_buildifier(download_url)
except Exception as ex:
print_error("downloading Buildifier", str(ex))
return 1

flags = ["--mode=check", "--lint=warn"]
warnings = os.getenv(WARNINGS_ENV_VAR)
Expand Down

0 comments on commit ae3f5d0

Please sign in to comment.