From 189b83e52ab84c03eac8c2fb0cfcf837afd35000 Mon Sep 17 00:00:00 2001 From: Oliver Lee Date: Sun, 1 Sep 2024 17:45:34 -0500 Subject: [PATCH] fix `sed` opts on macOS (#25) Change-Id: I433f834e9ec28f85d42584c5f6c16bd645bf0afd --- .github/actions/setup-env/action.yml | 26 ++++++++++++++++++++++ .github/workflows/check.yml | 32 ++++++++++++++++++++++------ apply-fixes.bash | 8 ++++++- make_clang_tidy_aspect.bzl | 12 ++++++++++- private/local_workspace_status.bzl | 3 ++- 5 files changed, 71 insertions(+), 10 deletions(-) diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml index fd662da..ba079c0 100644 --- a/.github/actions/setup-env/action.yml +++ b/.github/actions/setup-env/action.yml @@ -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 @@ -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" + diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 39ca2db..5b6e913 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -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 @@ -52,7 +68,6 @@ jobs: clang: ${{ matrix.clang }} - name: run clang-tidy - shell: bash env: USE_BAZEL_VERION: ${{ matrix.bazel }} run: | @@ -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) }} diff --git a/apply-fixes.bash b/apply-fixes.bash index 6711303..5223917 100755 --- a/apply-fixes.bash +++ b/apply-fixes.bash @@ -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" diff --git a/make_clang_tidy_aspect.bzl b/make_clang_tidy_aspect.bzl index ddeb825..4fb3421 100644 --- a/make_clang_tidy_aspect.bzl +++ b/make_clang_tidy_aspect.bzl @@ -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} \ @@ -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, @@ -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 diff --git a/private/local_workspace_status.bzl b/private/local_workspace_status.bzl index 9d6e360..428e880 100644 --- a/private/local_workspace_status.bzl +++ b/private/local_workspace_status.bzl @@ -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, )