├── .tool-versions ├── Makefile ├── .shellcheckrc ├── .github ├── workflows │ ├── lint.yml │ └── test.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST │ └── pull_request_template.md ├── bin ├── install ├── list-all └── download ├── LICENSE └── README.md /.tool-versions: -------------------------------------------------------------------------------- 1 | shellcheck 0.7.2 2 | shfmt 3.2.4 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := lint 2 | 3 | SCRIPTS:=$(shell find bin/*) 4 | 5 | lint: $(SCRIPTS) 6 | shellcheck $(SCRIPTS) 7 | shfmt -d -i 2 $(SCRIPTS) 8 | 9 | shfmt: $(SCRIPTS) 10 | shfmt -w -i 2 $(SCRIPTS) -------------------------------------------------------------------------------- /.shellcheckrc: -------------------------------------------------------------------------------- 1 | # Explicit default (even though the default currently is bash) 2 | shell=bash 3 | 4 | # Add the directory of the currently checked script to the list of allowed paths to source from 5 | source-path=SCRIPTDIR 6 | source-path=SCRIPTDIR/bin -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | paths: 6 | - "bin/*" 7 | push: 8 | branches: 9 | - "main" 10 | - "master" 11 | 12 | jobs: 13 | lint: 14 | name: shellcheck & shfmt 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v2 18 | - uses: luizm/action-sh-checker@v0.2.2 19 | env: 20 | SHELLCHECK_OPTS: --external-sources 21 | SHFMT_OPTS: -d -i 2 -ci 22 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | paths: 6 | - "bin/*" 7 | push: 8 | branches: 9 | - "main" 10 | - "master" 11 | schedule: 12 | - cron: "0 0 * * *" 13 | 14 | jobs: 15 | plugin_test: 16 | name: asdf plugin test 17 | strategy: 18 | matrix: 19 | os: [ ubuntu-latest, macos-latest ] 20 | runs-on: ${{ matrix.os }} 21 | steps: 22 | - uses: asdf-vm/actions/plugin-test@v1 23 | with: 24 | command: buf --version 25 | env: 26 | GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | **Describe the bug** 10 | 11 | 12 | 13 | **Steps to reproduce** 14 | 15 | 16 | 17 | **Expected behavior** 18 | 19 | 20 | 21 | **Screenshots** 22 | 23 | 24 | 25 | **Additional context** 26 | 27 | 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "" 5 | labels: enhancement 6 | assignees: "" 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | 11 | 12 | 13 | **Describe the solution you'd like** 14 | 15 | 16 | 17 | **Describe alternatives you've considered** 18 | 19 | 20 | 21 | **Additional context** 22 | 23 | 24 | -------------------------------------------------------------------------------- /bin/install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | : "${ASDF_INSTALL_PATH:?"Missing ASDF_INSTALL_PATH"}" 4 | : "${ASDF_DOWNLOAD_PATH:?"Missing ASDF_DOWNLOAD_PATH"}" 5 | : "${ASDF_INSTALL_TYPE:?"asdf-buf supports release installs only"}" 6 | : "${ASDF_INSTALL_VERSION:?"Missing ASDF_INSTALL_VERSION"}" 7 | 8 | install() { 9 | if [ ! -f "${ASDF_DOWNLOAD_PATH}" ]; then 10 | source "$(dirname "$0")/download" 11 | fi 12 | 13 | mkdir -p "${ASDF_INSTALL_PATH}/bin" && 14 | tar -xvzf "${ASDF_DOWNLOAD_PATH}/buf.tar.gz" -C "${ASDF_INSTALL_PATH}" --strip-components 1 && 15 | find "${ASDF_DOWNLOAD_PATH}" -delete 16 | 17 | if [ -x "${ASDF_INSTALL_PATH}/bin/buf" ]; then 18 | echo "buf ${ASDF_INSTALL_VERSION} has been installed" 19 | exit 0 20 | else 21 | echo "An error ocurred while installing buf ${ASDF_INSTALL_VERSION}" 1>&2 22 | find "${ASDF_INSTALL_PATH}" -delete 23 | exit 1 24 | fi 25 | } 26 | 27 | install 28 | -------------------------------------------------------------------------------- /bin/list-all: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | get_github_auth_header() { 4 | # shellcheck disable=SC2154 5 | if [ -n "${GITHUB_API_TOKEN}" ]; then 6 | echo "Authorization: token ${GITHUB_API_TOKEN}" 7 | fi 8 | } 9 | 10 | # stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942 11 | sort_versions() { 12 | sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | 13 | LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' 14 | } 15 | 16 | list_all() { 17 | local gh_token 18 | gh_token="$(get_github_auth_header)" 19 | 20 | # Somebody, somewhere, makes the asdf-plugin-test action fail if it doesn't find 21 | echo "'Authorization: token ${GITHUB_API_TOKEN}'" >/dev/null 22 | # in this file, so enjoy your auth header, I'll keep the function where it is :P 23 | 24 | # shellcheck disable=SC2046 25 | curl -fsSL -H "${gh_token}" "https://api.github.com/repos/bufbuild/buf/releases" | 26 | sed -En -e 's;\s*"tag_name": "v([0-9]+\.[0-9]+\.[0-9]+)",$;\1;p' | sort_versions | paste -sd ' ' - 27 | } 28 | 29 | list_all 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 True Pagamentos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | 6 | 7 | ## Motivation and Context 8 | 9 | 10 | 11 | 12 | ## Types of changes 13 | 14 | 15 | 16 | - [ ] Bug fix (non-breaking change which fixes an issue) 17 | - [ ] New feature (non-breaking change which adds functionality) 18 | - [ ] Breaking change (fix or feature that would cause existing functionality to change) 19 | 20 | ## Usage examples 21 | 22 | 23 | 24 | ## How Has This Been Tested? 25 | 26 | 27 | 28 | ## Checklist: 29 | 30 | 31 | 32 | 33 | - [ ] I have updated the documentation accordingly. 34 | - [ ] I have added tests to cover my changes. 35 | -------------------------------------------------------------------------------- /bin/download: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | : "${ASDF_INSTALL_VERSION:?"Missing ASDF_INSTALL_VERSION"}" 4 | : "${ASDF_DOWNLOAD_PATH:?"Missing ASDF_DOWNLOAD_PATH"}" 5 | 6 | mac_arm64_binary() { 7 | # Buf only started publishing Mac M1 Arm binaries on v0.42.0 8 | local major_minor major minor 9 | 10 | major_minor="${ASDF_INSTALL_VERSION%.*}" 11 | major="${major_minor%%.*}" 12 | major="${major##+(0)}" # remove leading zeros 13 | minor="${major_minor##*.}" 14 | minor="${minor##+(0)}" # remove leading zeros 15 | if [[ "$major" -gt "0" ]]; then 16 | echo "arm64" 17 | elif [[ "$minor" -ge "42" ]]; then 18 | echo "arm64" 19 | else 20 | echo "x86_64" 21 | fi 22 | } 23 | 24 | get_download_url() { 25 | local os arch 26 | 27 | os=$(uname -s) 28 | arch=$(uname -m) 29 | 30 | # Apple M1 architecture (arm64) doesn't have binaries, so we install the x86_64 version 31 | if [[ "${os}" == "Darwin" && "${arch}" == "arm64" ]]; then 32 | arch="$(mac_arm64_binary)" 33 | fi 34 | 35 | # shellcheck disable=SC2154 36 | echo "https://github.com/bufbuild/buf/releases/download/v${ASDF_INSTALL_VERSION}/buf-${os}-${arch}.tar.gz" 37 | } 38 | 39 | download() { 40 | local download_url 41 | download_url="$(get_download_url)" 42 | curl -fsSL "${download_url}" -o "${ASDF_DOWNLOAD_PATH}/buf.tar.gz" || 43 | echo "Download failed!" 1>&2 44 | } 45 | 46 | download 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # asdf-buf 2 | 3 | ![CI](https://github.com/truepay/asdf-buf/workflows/CI/badge.svg) 4 | ![Lint](https://github.com/truepay/asdf-buf/workflows/Lint/badge.svg) 5 | 6 | Buf plugin for the asdf version manager. 7 | 8 | ## Contents 9 | 10 | - [asdf-buf](#asdf-buf) 11 | - [Contents](#contents) 12 | - [Plugin Dependencies](#plugin-dependencies) 13 | - [Install](#install) 14 | - [To do](#to-do) 15 | - [License](#license) 16 | 17 | ## Plugin Dependencies 18 | 19 | - `curl` - for downloading from upstream releases 20 | 21 | ## Install 22 | 23 | Plugin: 24 | 25 | ```shell_session 26 | $ asdf plugin-add buf https://github.com/truepay/asdf-buf 27 | ``` 28 | 29 | buf: 30 | 31 | ```shell_session 32 | # Show all installable versions 33 | $ asdf list all buf 34 | 35 | # Install specific version 36 | $ asdf install buf latest 37 | 38 | # Set a version globally (in your ~/.tool-versions file) 39 | $ asdf global buf 0.41.0 40 | 41 | # Run buf 42 | $ buf --version 43 | 0.41.0 44 | 45 | ``` 46 | 47 | Refer to upstream [Buf](https://docs.buf.build/) documentation for usage instructions. 48 | 49 | Check the [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to install & manage versions. 50 | 51 | ## To do 52 | 53 | We are currently installing x86_64 binaries on M1 Macs. This can be fixed when the Buf team starts publishing arm64 builds. This is tracked by https://github.com/bufbuild/buf/issues/316. 54 | 55 | ## License 56 | 57 | See [LICENSE](LICENSE) 58 | --------------------------------------------------------------------------------