Skip to content

Commit

Permalink
fix sed opts on macOS (#25)
Browse files Browse the repository at this point in the history
Change-Id: I433f834e9ec28f85d42584c5f6c16bd645bf0afd
  • Loading branch information
oliverlee authored Sep 1, 2024
1 parent 5736056 commit 189b83e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
26 changes: 26 additions & 0 deletions .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ runs:
steps:

- name: install libtinfo5
if: runner.os == 'Linux'
shell: bash
run: |
# this is required by the hermetic llvm 16 toolchain
sudo apt-get install -y libtinfo5
- name: install clang-${{ inputs.clang }}
if: runner.os == 'Linux'
shell: bash
run: |
set -x
Expand All @@ -36,3 +38,27 @@ runs:
clang-tidy --version
clang-apply-replacements --version
- name: define HOME
if: runner.os == 'macOS'
shell: bash
run: |
set -x
# https://github.com/bazelbuild/continuous-integration/issues/485#issuecomment-466336418
# https://pkg.go.dev/os#UserCacheDir
echo "build --action_env=HOME=$HOME" \
>> "$HOME/.bazelrc"
- name: install clang-${{ inputs.clang }}
if: runner.os == 'macOS'
shell: bash
run: |
set -x
brew install llvm@${{ inputs.clang }}
# homebrew no longer installs into the default PATH
# https://github.com/bazelbuild/bazel/issues/12049#issuecomment-1439637677
echo "build --action_env=PATH=$(brew --prefix llvm@${{ inputs.clang }})/bin:$PATH" \
>> "$HOME/.bazelrc"
32 changes: 25 additions & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,53 @@ on:
env:
CC: clang

defaults:
run:
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_iddefaultsrunshell
shell: bash

jobs:
buildifier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- shell: bash
run: |
- run: |
bazel run //tools:format.check
matrix-single-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- bazel: latest
clang: 18
os: macos-latest
- bazel: latest
clang: 18
os: ubuntu-latest
- bazel: latest
clang: 17
os: ubuntu-latest
- bazel: latest
clang: 16
os: ubuntu-latest
- bazel: latest
clang: 15
os: ubuntu-latest
- bazel: latest
clang: 14
os: ubuntu-latest
- bazel: 7.x
clang: 18
os: ubuntu-latest
- bazel: 6.x
clang: 18
os: ubuntu-latest
- bazel: 5.x
clang: 18
os: ubuntu-latest

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
Expand All @@ -52,7 +68,6 @@ jobs:
clang: ${{ matrix.clang }}

- name: run clang-tidy
shell: bash
env:
USE_BAZEL_VERION: ${{ matrix.bazel }}
run: |
Expand All @@ -67,16 +82,19 @@ jobs:
uses: ./.github/actions/setup-env

- name: run clang-tidy
shell: bash
run: |
bazel test //...
# https://emmer.dev/blog/skippable-github-status-checks-aren-t-really-required/
# https://github.com/marketplace/actions/alls-green
all:
runs-on: ubuntu-latest
if: ${{ github.base_ref == 'main' }}
if: always()
needs:
- buildifier
- matrix-single-test
- test
steps:
- run: true
- uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
8 changes: 7 additions & 1 deletion apply-fixes.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ set -euo pipefail
apply_bin="$1"
output_path="$2"

if [ "$(uname)" == "Darwin" ]; then
SED_INPLACE="-i''"
else
SED_INPLACE="-i"
fi

find "$output_path" -type f -name "*.yaml" \
| xargs sed -i -e "s+%workspace%+$BUILD_WORKSPACE_DIRECTORY+g"
| xargs sed "$SED_INPLACE" -e "s+%workspace%+$BUILD_WORKSPACE_DIRECTORY+g"

"$apply_bin" "$output_path"
12 changes: 11 additions & 1 deletion make_clang_tidy_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def _do_tidy(ctx, compilation_ctx, source_file, **kwargs):
#!/usr/bin/env bash
set -euo pipefail
env
echo $PATH
({clang_tidy} \
--config-file={config} \
{tidy_options} \
Expand All @@ -105,7 +109,12 @@ touch {fixes}
# replace sandbox path prefix from file paths and
# hope `+` isn't used anywhere
sed --in-place --expression "s+$(pwd)+%workspace%+g" {fixes}
if [ "$(uname)" == "Darwin" ]; then
SED_INPLACE="-i''"
else
SED_INPLACE="--in-place"
fi
sed "$SED_INPLACE" -e "s+$(pwd)+%workspace%+g" {fixes}
""".format(
clang_tidy = clang_tidy.path,
config = ctx.file._config.path,
Expand All @@ -126,6 +135,7 @@ sed --in-place --expression "s+$(pwd)+%workspace%+g" {fixes}
mnemonic = "ClangTidy",
progress_message = "Linting {}".format(source_file.short_path),
execution_requirements = kwargs["execution_requirements"],
use_default_shell_env = True,
)

# use result to conditionally fail the action
Expand Down
3 changes: 2 additions & 1 deletion private/local_workspace_status.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ build_files=$(find {workspace} \
| sort \
)
echo "$build_files" | xargs -I % cat % | md5sum
echo "$build_files" | xargs -I % cat % | {md5sum}
""".format(
workspace = root,
expression = rctx.attr.find_expr,
md5sum = "md5" if rctx.os.name == "mac os x" else "md5sum",
),
executable = True,
)
Expand Down

0 comments on commit 189b83e

Please sign in to comment.