Skip to content

Commit

Permalink
ci: fix github actions by removing leading and trailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
danctorres committed Jan 5, 2025
1 parent 626b26b commit 2928c7b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/arduino_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:
sort -u affected_ino_files.txt -o affected_ino_files.txt
echo "Affected ino files:"
cat affected_ino_files.txt
echo "ino_files=$(cat affected_ino_files.txt | tr '\n' ' ')" >> $GITHUB_ENV
echo "ino_files=$(cat affected_ino_files.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Run arduino-lint
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/bazel_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ jobs:
while read file; do
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "Finding targets for: $file"
targets=$(bazelisk query --output=package "$file" || true)/...
targets=$(bazelisk query --output=package "$file")/...
echo "$targets" >> affected_targets.txt
fi
done < affected_files.txt
sort -u affected_targets.txt -o affected_targets.txt
echo "Affected targets:"
cat affected_targets.txt
echo "targets=$(cat affected_targets.txt | tr '\n' ' ')" >> $GITHUB_ENV
echo "targets=$(cat affected_targets.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Setup bazel cache
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/bazel_buildifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:
sort -u affected_bazel_files.txt -o affected_bazel_files.txt
echo "Affected Bazel files:"
cat affected_bazel_files.txt
echo "bazel_files=$(cat affected_bazel_files.txt | tr '\n' ' ')" >> $GITHUB_ENV
echo "bazel_files=$(cat affected_bazel_files.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Setup bazel cache
Expand Down
36 changes: 28 additions & 8 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
while read file; do
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "Finding targets for: $file"
targets=$(bazelisk query --output=package "$file" || true)/...
targets=$(bazelisk query --output=package "$file")/...
echo "$targets" >> affected_targets.txt
fi
done < affected_files.txt
Expand All @@ -44,11 +44,30 @@ jobs:
echo "Affected targets:"
cat affected_targets.txt
echo "targets=$(cat affected_targets.txt | tr '\n' ' ')" >> $GITHUB_ENV
echo "targets=$(cat affected_targets.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Setup bazel cache
- name: Find affected Bazel test targets
id: bazel_test_targets
if: env.targets != ''
run: |
> affected_test_targets.txt
while read target; do
echo "Finding test targets for: $target"
test_targets=$(bazelisk query "kind('cc_test', '$target')")
echo "$test_targets" >> affected_test_targets.txt
done < affected_targets.txt
sort -u affected_test_targets.txt -o affected_test_targets.txt
echo "Affected test targets:"
cat affected_test_targets.txt
echo "test_targets=$(cat affected_test_targets.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Setup bazel cache
if: ${{ env.test_targets && env.test_targets != '' }}
uses: actions/cache@v4
env:
cache-name: bazel-cache
Expand All @@ -61,11 +80,12 @@ jobs:
${{ runner.os }}-${{ env.cache-name }}-development
- name: Test affected targets
if: env.targets != ''
if: ${{ env.test_targets && env.test_targets != '' }}
run: |
echo "Building targets: $targets"
bazelisk test ${targets}
echo "Running test targets: $test_targets"
bazelisk test $test_targets
shell: bash

- name: No targets to test
if: env.targets == ''
run: echo "No affected Bazel targets found. Skipping test."
if: ${{ env.targets == '' || env.test_targets && env.test_targets == '' }}
run: echo "No affected Bazel test targets found. Skipping test."
3 changes: 2 additions & 1 deletion .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:
sort -u affected_cpp_files.txt -o affected_cpp_files.txt
echo "Affected cpp files:"
cat affected_cpp_files.txt
echo "cpp_files=$(cat affected_cpp_files.txt | tr '\n' ' ')" >> $GITHUB_ENV
echo "cpp_files=$(cat affected_cpp_files.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Run Clang-Format
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/clang_tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:
sort -u affected_cpp_files.txt -o affected_cpp_files.txt
echo "Affected cpp files:"
cat affected_cpp_files.txt
echo "cpp_files=$(cat affected_cpp_files.txt | tr '\n' ' ')" >> $GITHUB_ENV
echo "cpp_files=$(cat affected_cpp_files.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Generate Compile Commands
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
while read file; do
if [[ ("$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx) && "$file" != *test* ]]; then
echo "Finding targets for: $file"
targets=$(bazelisk query --output=package "$file" || true)/...
targets=$(bazelisk query --output=package "$file")/...
if [[ "$targets" != *test* ]]; then
echo "$targets" >> affected_targets.txt
fi
Expand All @@ -45,7 +45,8 @@ jobs:
sort -u affected_targets.txt -o affected_targets.txt
echo "Affected targets:"
cat affected_targets.txt
echo "targets=$(cat affected_targets.txt | tr '\n' ' ')" >> $GITHUB_ENV
echo "targets=$(cat affected_targets.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Find tests target of affected targets
Expand All @@ -54,21 +55,19 @@ jobs:
test_targets=""
for target in $targets; do
result=$(bazelisk cquery "kind('cc_test', deps('$target'))") || exit 1
result=$(bazelisk query "kind('cc_test', deps('$target'))") || exit 1
if [[ -n "$result" ]]; then
# Remove the part in parentheses (e.g., (f37096a))
formatted_result=$(echo "$result" | sed 's/ ([^)]*)//g')
# Prefix each line of the result with a `-`
formatted_result=$(echo "$formatted_result" | sed 's/^/-/')
formatted_result=$(echo "$result" | sed 's/^/-/')
test_targets+="$formatted_result"$'\n'
fi
done
echo "$test_targets" > test_targets.txt
single_line_test_targets=$(echo "$test_targets" | tr '\n' ' ' | sed 's/ $//')
echo "test_targets=-- $single_line_test_targets" >> $GITHUB_ENV
shell: bash

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:
sort -u affected_yaml_files.txt -o affected_yaml_files.txt
echo "Affected yaml files:"
cat affected_yaml_files.txt
echo "yaml_files=$(cat affected_yaml_files.txt | tr '\n' ' ')" >> $GITHUB_ENV
echo "yaml_files=$(cat affected_yaml_files.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash

- name: Lint YAML files
Expand Down

0 comments on commit 2928c7b

Please sign in to comment.