diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ed705e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +.bin diff --git a/README.md b/README.md index d666cb9..87ffa17 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,22 @@ A GitHub action that provides [buf](https://github.com/bufbuild/buf). ## Usage -TODO +```yaml +name: Generate and Lint buf + +on: + pull_request: + branches: + - * + +jobs: + lint: + name: buf check lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ory/build-buf-action@v0 + with: + bufVersion: v0.31.1 + bufArgs: check lint --config buf/api/buf.yaml +``` diff --git a/action.yml b/action.yml index d0baca6..492ee57 100644 --- a/action.yml +++ b/action.yml @@ -1,8 +1,27 @@ name: Build Buf description: A GitHub action that provides buildbuf/buf + +inputs: + bufVersion: + description: The version of buf to use (as in their GitHub releases) + default: v0.31.1 + required: false + bufArgs: + description: The arguments to pass to buf + default: generate + required: false + runs: using: composite - steps: [ ] + steps: + # requires actions within actions as tracked in https://github.com/actions/runner/issues/646 + # - uses: actions/cache@v2 + - name: Maybe install and definitely invoke buf + shell: bash + run: | + source scripts/install-buf.sh ${{ inputs.bufVersion }} + buf ${{ inputs.bufArgs }} + branding: color: blue icon: box diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e429f88 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,19 @@ +{ + "name": "build-buf-action", + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "ory-prettier-styles": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ory-prettier-styles/-/ory-prettier-styles-1.1.1.tgz", + "integrity": "sha512-Kv5GUQw0nFDO6w/HcIMNQAh75QeG4ZhrpNuRJaHSlsTvTx9rwpr+bVfeXrhXQsovUW51PF6OvLW3LA0AdDdSzw==", + "dev": true + }, + "prettier": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.0.tgz", + "integrity": "sha512-yYerpkvseM4iKD/BXLYUkQV5aKt4tQPqaGW6EsZjzyu0r7sVZZNPJW4Y8MyKmicp6t42XUPcBVA+H6sB3gqndw==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..e784ef5 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "build-buf-action", + "private": true, + "description": "A GitHub action that provides [buf](https://github.com/bufbuild/buf).", + "main": "index.js", + "prettier": "ory-prettier-styles", + "config": { + "prettierTarget": "{*.yml,*.md}" + }, + "scripts": { + "format": "prettier --write ${npm_package_config_prettierTarget}", + "format:check": "prettier --check ${npm_package_config_prettierTarget}" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ory/build-buf-action.git" + }, + "bugs": { + "url": "https://github.com/ory/build-buf-action/issues" + }, + "homepage": "https://github.com/ory/build-buf-action#readme", + "devDependencies": { + "ory-prettier-styles": "^1.1.1", + "prettier": "^2.2.0" + } +} diff --git a/scripts/install-buf.sh b/scripts/install-buf.sh new file mode 100755 index 0000000..aa9a8d4 --- /dev/null +++ b/scripts/install-buf.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail + +UNAME_OS=$(uname -s) +UNAME_ARCH=$(uname -m) + +BUF_VERSION=$1 + +if [ ! -f ".bin/buf" ]; then + echo "Installing buf $BUF_VERSION for OS $UNAME_OS Arch $UNAME_ARCH" + mkdir -p .bin + curl --fail -sSL "https://github.com/bufbuild/buf/releases/download/$BUF_VERSION/buf-$UNAME_OS-$UNAME_ARCH" -o .bin/buf + chmod +x .bin/buf +fi + +PATH=PATH:"$(pwd)/.bin" +export PATH