Browse Source

Add shell check (#7125)

Motivated by @mateuszrzeszutek's
https://github.com/signalfx/splunk-otel-java/pull/992
Trask Stalnaker 2 years ago
parent
commit
6bc43450df

+ 5 - 5
.github/scripts/deadlock-detector.sh

@@ -6,14 +6,14 @@ do
   file="/tmp/deadlock-detector-$(date +"%Y-%m-%d-%H-%M-%S").txt"
   for pid in $(jps | grep -v Jps | awk '{ print $1 }')
   do
-    jcmd $pid VM.command_line >> $file
-    jcmd $pid Thread.print >> $file
-    if jcmd $pid Thread.print | grep -q SimpleLogger
+    jcmd "$pid" VM.command_line >> "$file"
+    jcmd "$pid" Thread.print >> "$file"
+    if jcmd "$pid" Thread.print | grep -q SimpleLogger
     then
       # check once more to eliminate most of the sporadic finds
-      if jcmd $pid Thread.print | grep -q SimpleLogger
+      if jcmd "$pid" Thread.print | grep -q SimpleLogger
       then
-        jcmd $pid GC.heap_dump /tmp/deadlock-detector-$pid.hprof
+        jcmd "$pid" GC.heap_dump "/tmp/deadlock-detector-$pid.hprof"
       fi
     fi
   done

+ 2 - 1
.github/scripts/diff-suppression-keys-with-docs.sh

@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/bash -e
 
 # this script reports some false positives, but is helpful in comparing the keys listed
 # in suppressing-instrumentation.md with the keys listed in the source files
@@ -9,6 +9,7 @@ curl https://raw.githubusercontent.com/open-telemetry/opentelemetry.io/main/cont
 
 comm -3 \
   <(
+    # shellcheck disable=SC2016 # "Expressions don't expand in single quotes"
     sed -n '/----------------------/,${p;/^$/q}' agent-config.md \
       | sed '1d;$d' \
       | cut -d '|' -f 3 \

+ 1 - 1
.github/scripts/draft-change-log-entries.sh

@@ -43,5 +43,5 @@ echo
 echo "### 🧰 Tooling"
 echo
 
-git log --reverse --pretty=format:"- %s" $range \
+git log --reverse --pretty=format:"- %s" "$range" \
   | sed -E 's,\(#([0-9]+)\)$,\n  ([#\1](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/\1)),'

+ 4 - 5
.github/scripts/generate-release-contributors.sh

@@ -1,8 +1,5 @@
 #!/bin/bash -e
 
-# shellcheck disable=SC2016
-# shellcheck disable=SC2086
-
 # this should be run on the release branch
 
 # NOTE if you need to run this script locally, you will need to first:
@@ -13,11 +10,12 @@
 from_version=$1
 
 # get the date of the first commit that was not in the from_version
-from=$(git log --reverse --pretty=format:"%cI" $from_version..HEAD | head -1)
+from=$(git log --reverse --pretty=format:"%cI" "$from_version..HEAD" | head -1)
 
 # get the last commit on main that was included in the release
 to=$(git merge-base origin/main HEAD | xargs git log -1 --pretty=format:"%cI")
 
+# shellcheck disable=SC2016 # "Expressions don't expand in single quotes"
 contributors1=$(gh api graphql --paginate -F q="repo:$GITHUB_REPOSITORY is:pr base:main is:merged merged:$from..$to" -f query='
 query($q: String!, $endCursor: String) {
   search(query: $q, type: ISSUE, first: 100, after: $endCursor) {
@@ -55,6 +53,7 @@ query($q: String!, $endCursor: String) {
 
 # this query captures authors of issues which have had PRs in the current range reference the issue
 # but not necessarily through closingIssuesReferences (e.g. addressing just a part of an issue)
+# shellcheck disable=SC2016 # "Expressions don't expand in single quotes"
 contributors2=$(gh api graphql --paginate -F q="repo:$GITHUB_REPOSITORY is:pr base:main is:merged merged:$from..$to" -f query='
 query($q: String!, $endCursor: String) {
   search(query: $q, type: ISSUE, first: 100, after: $endCursor) {
@@ -79,7 +78,7 @@ query($q: String!, $endCursor: String) {
   | sed 's/^\["//' \
   | sed 's/".*//')
 
-echo $contributors1 $contributors2 \
+echo "$contributors1" "$contributors2" \
   | sed 's/ /\n/g' \
   | sort -uf \
   | grep -v linux-foundation-easycla \

+ 3 - 0
.github/workflows/build-daily.yml

@@ -24,6 +24,9 @@ jobs:
   muzzle:
     uses: ./.github/workflows/reusable-muzzle.yml
 
+  shell-script-check:
+    uses: ./.github/workflows/reusable-shell-script-check.yml
+
   markdown-link-check:
     uses: ./.github/workflows/reusable-markdown-link-check.yml
 

+ 9 - 1
.github/workflows/build-pull-request.yml

@@ -29,9 +29,17 @@ jobs:
     with:
       cache-read-only: true
 
+  # this is not a required check to avoid blocking pull requests if new shell checks are added
+  shell-script-check:
+    # release branches are excluded to avoid unnecessary maintenance if new shell checks are added
+    if: ${{ !startsWith(github.ref_name, 'release/') }}
+    uses: ./.github/workflows/reusable-shell-script-check.yml
+
   # this is not a required check to avoid blocking pull requests if external links break
   markdown-link-check:
-    # release branches are excluded to avoid unnecessary maintenance
+    # release branches are excluded to avoid unnecessary maintenance if external links break
+    # (and also because the README.md javaagent download link has to be updated on release branches
+    #  before the release download has been published)
     if: ${{ !startsWith(github.ref_name, 'release/') }}
     uses: ./.github/workflows/reusable-markdown-link-check.yml
 

+ 5 - 0
.github/workflows/build.yml

@@ -33,6 +33,11 @@ jobs:
     if: ${{ !startsWith(github.ref_name, 'release/') }}
     uses: ./.github/workflows/reusable-muzzle.yml
 
+  shell-script-check:
+    # release branches are excluded to avoid unnecessary maintenance if new shell checks are added
+    if: ${{ !startsWith(github.ref_name, 'release/') }}
+    uses: ./.github/workflows/reusable-shell-script-check.yml
+
   markdown-link-check:
     # release branches are excluded to avoid unnecessary maintenance if external links break
     # (and also because the README.md javaagent download link has to be updated on release branches

+ 16 - 0
.github/workflows/reusable-shell-script-check.yml

@@ -0,0 +1,16 @@
+name: Reusable - Shell script check
+
+on:
+  workflow_call:
+
+jobs:
+  shell-script-check:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+
+      - name: Install shell check
+        run: wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv
+
+      - name: Run shellcheck
+        run: find -name '*.sh' | xargs shellcheck-stable/shellcheck --format=gcc

+ 1 - 1
smoke-tests/src/test/resources/crashearlyjdk8/start.sh

@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/bash -e
 
 echo "started"
 while :

+ 1 - 1
smoke-tests/src/test/resources/crashearlyjdk8/test.sh

@@ -1,4 +1,4 @@
-#/bin/sh
+#!/bin/bash -e
 
 echo "compiling"
 javac CrashEarlyJdk8.java