diff --git a/.github/workflows/precious.yml b/.github/workflows/precious.yml new file mode 100644 index 00000000..0336580c --- /dev/null +++ b/.github/workflows/precious.yml @@ -0,0 +1,31 @@ +name: Precious + +on: + push: + branches: + - 'main' + pull_request: + workflow_dispatch: + +jobs: + code-formatting: + runs-on: ubuntu-latest + name: Code Formatting + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install precious + run: ./bin/install-precious /usr/local/bin + - run: git diff --name-only --diff-filter=ACM upstream... + - name: Select files + id: select-files + run: | + if [[ -n "${{ github.event.pull_request.number }}" ]]; then + echo 'precious-args=--git-diff-from main' >> "$GITHUB_OUTPUT" + else + echo 'precious-args=--all' >> "$GITHUB_OUTPUT" + fi + - name: Lint files + run: precious lint ${{ steps.select-files.outputs.precious-args }} diff --git a/bin/install-precious b/bin/install-precious new file mode 100755 index 00000000..0d712a47 --- /dev/null +++ b/bin/install-precious @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# This is for installing precious and other 3rd party libs needed for linting +# in CI + +set -euo pipefail + +if [ -z "${1:-}" ]; then + echo "usage: ./bin/install-precious /path/to/bin/dir" + exit 1 +fi + +TARGET=$1 +export TARGET + +TARGET=$1 +export TARGET + +curl --silent --location \ + https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh | + sh + +ubi --project houseabsolute/omegasort --in "$TARGET" +ubi --project houseabsolute/precious --in "$TARGET"