|
| 1 | +name: Hadolint |
| 2 | +run-name: Hadolint (Triggered by ${{ github.event_name }} by @${{ github.actor }}) |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +jobs: |
| 7 | + scan: |
| 8 | + runs-on: [self-hosted, linux, docker] |
| 9 | + steps: |
| 10 | + - name: Cleanup workspace |
| 11 | + run: sudo rm -rf ..?* .[!.]* * |
| 12 | + |
| 13 | + - name: Checkout dispatcher source |
| 14 | + uses: actions/checkout@v3 |
| 15 | + with: |
| 16 | + path: source |
| 17 | + |
| 18 | + - name: Pull docker image |
| 19 | + run: docker pull hadolint/hadolint |
| 20 | + |
| 21 | + - name: Lint |
| 22 | + run: | |
| 23 | + mkdir artifact |
| 24 | + echo "Hadolint Report" > artifact/hadolint.txt |
| 25 | + walk_dir () { |
| 26 | + shopt -s nullglob dotglob |
| 27 | + |
| 28 | + for pathname in "$1"/*; do |
| 29 | + retVal=0 |
| 30 | + if [ -d "$pathname" ]; then |
| 31 | + walk_dir "$pathname" || retVal=$? |
| 32 | + if [ $retVal -ne 0 ]; then |
| 33 | + RC=$retVal |
| 34 | + fi |
| 35 | + else |
| 36 | + case "$pathname" in |
| 37 | + *Dockerfile*|*dockerfile*) |
| 38 | + echo "Checking $pathname" |
| 39 | + echo "" >> artifact/hadolint.txt |
| 40 | + echo " $pathname" >> artifact/hadolint.txt |
| 41 | + echo "----------" >> artifact/hadolint.txt |
| 42 | + docker run --rm \ |
| 43 | + -i --attach stderr --attach stdout \ |
| 44 | + -v $(pwd)/source:/source \ |
| 45 | + -w /source \ |
| 46 | + hadolint/hadolint < $pathname 2>&1 >> artifact/hadolint.txt || retVal=$? |
| 47 | + if [ $retVal -ne 0 ]; then |
| 48 | + RC=$retVal |
| 49 | + fi |
| 50 | + esac |
| 51 | + fi |
| 52 | + done |
| 53 | + return $RC |
| 54 | + } |
| 55 | + walk_dir "$(pwd)/source" |
| 56 | + |
| 57 | + - name: Summarize |
| 58 | + if: (failure()) |
| 59 | + run: | |
| 60 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 61 | + cat artifact/hadolint.txt >> $GITHUB_STEP_SUMMARY |
| 62 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 63 | +
|
| 64 | + - name: Report |
| 65 | + if: (success() || failure()) |
| 66 | + run: | |
| 67 | + cat artifact/hadolint.txt |
| 68 | +
|
| 69 | + - name: Record Artifacts |
| 70 | + uses: actions/upload-artifact@v3 |
| 71 | + if: (success() || failure()) |
| 72 | + with: |
| 73 | + name: hadolint |
| 74 | + path: artifact/* |
| 75 | + |
| 76 | + - name: Cleanup workspace |
| 77 | + if: always() && runner.os == 'Linux' |
| 78 | + run: sudo rm -rf ..?* .[!.]* * |
0 commit comments