Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor hadolint version support #87

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
# If this file changes, any script should also fire.
changed:
runs-on: ubuntu-22.04
name: get changed files
outputs:
files: ${{ steps.all.outputs.all_changed_files }}
self_changed: ${{ steps.lint.outputs.any_changed }}
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/test-action.yml

This file was deleted.

41 changes: 32 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
name: test
on:
pull_request:
paths:
- "HADOLINT_VERSION"
- "**.sh"
- "test/*"
- .github/workflows/test.yml

jobs:
bash_unit:
name: bash_unit
name: bash tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3.0.2
- name: fetch hadolint version
run: echo "HADOLINT_VERSION=$(cat HADOLINT_VERSION)" >> "${GITHUB_ENV}"
- name: install hadolint
# yq is like jq for yaml
# https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md#tools
run: |
wget -q -O hadolint https://github.com/hadolint/hadolint/releases/download/v${{ env.HADOLINT_VERSION }}/hadolint-Linux-x86_64 && \
version="$(yq .inputs.version.default action.yml)" && \
echo "::debug::Downloading Hadolint ${{ env.version }}" && \
wget -q -O hadolint "https://github.com/hadolint/hadolint/releases/download/v${version}/hadolint-Linux-x86_64" && \
chmod +x hadolint && \
sudo mv hadolint /usr/local/bin/hadolint
- name: install bash_unit
Expand All @@ -32,3 +29,29 @@ jobs:
bash_unit -v
- name: run suite
run: bash_unit test/*.sh
gh-action-default:
name: action validates dockerfiles
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3.0.2
- uses: ./
with:
dockerfile: test/fixtures/Dockerfile-valid
gh-action-version:
name: action supports custom version
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3.0.2
- uses: ./
id: check
with:
dockerfile: test/fixtures/Dockerfile-valid
version: 2.9.0
env:
DEBUG: yes
- name: check hadolint version
run: |
if [[ ! "${{ steps.check.outputs.hadolint_version }}" == "2.9.0-no-git" ]]; then
echo "::error::Version mismatch: \"${{ steps.check.outputs.hadolint_version }}\" does not equal \"2.9.0-no-git\""
exit 1
fi
1 change: 0 additions & 1 deletion HADOLINT_VERSION

This file was deleted.

9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-22.04
name: "Hadolint"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: jbergstroem/hadolint-gh-action@v1
```

Expand All @@ -31,12 +31,17 @@ More usage examples [can be found in USAGE.md](USAGE.md).
| annotate | true | Annotate code inline in the github PR viewer (`true`/`false`) |
| output_format | | Set output format (choose between `tty`, `json`, `checkstyle`, `codeclimate`, `gitlab_codeclimate`, `sonarqube` or `sarif`) |
| hadolint_path | | Absolute path to hadolint binary. If unset, it is assumed to exist in `$PATH` |
| version | `2.10.0` | Use a specific version of Hadolint |

## Hadolint version

The variable `hadolint_version` will always contain what version the action is running.
The github action accepts an input - `version` - to switch/pin to a different version of hadolint.

The output variable `hadolint_version` will always contain what version the action is running.
This can be useful in debugging scenarios where things "break" from one day to the other due to the action being updated.

The shell scripts are developed against the latest version available (which is the default value for the input).

## Output

You can control the behavior of how hadolint presents its findings by configuring:
Expand Down
22 changes: 16 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,50 @@ inputs:
required: true
default: true
output_format:
description: Set output format (choose between `tty`, `json`, `checkstyle`, `codeclimate` or `gitlab_codeclimate`)
description: Output format (choose between `checkstyle`, `codeclimate`, `gitlab_codeclimate`, `json` or `tty`)
required: false
default:
hadolint_path:
description: Absolute path to hadolint binary. If unset, it is assumed to exist in `$PATH`
description: Absolute path to hadolint binary. Left unset means it can be found in `$PATH`
required: false
default:
version:
description: Use a specific version of Hadolint
default: 2.10.0
required: true

outputs:
hadolint_output:
description: Optional output from Hadolint, controlled with `output_format`
value: ${{ steps.run.outputs.hadolint_output }}
hadolint_version:
description: Hadolint version
description: Hadolint version in use
value: ${{ steps.run.outputs.hadolint_version }}

runs:
using: composite
steps:
- name: Download hadolint and make available in path
- name: Download hadolint and make it available in path
shell: bash
env:
version: ${{ inputs.version }}
run: |
VERSION=$(<${{ github.action_path }}/HADOLINT_VERSION)
echo "::debug::Downloading Hadolint ${version}"
mkdir ${{ github.action_path }}/bin
wget -q -O ${{ github.action_path }}/bin/hadolint \
"https://github.com/hadolint/hadolint/releases/download/v${VERSION}/hadolint-Linux-x86_64"
"https://github.com/hadolint/hadolint/releases/download/v${version}/hadolint-Linux-x86_64"
chmod +x ${{ github.action_path }}/bin/hadolint
echo "${{ github.action_path }}/bin" >> $GITHUB_PATH
- name: Run hadolint.sh
id: run
shell: bash
env:
dockerfile: ${{ inputs.dockerfile }}
config_file: ${{ inputs.config_file }}
error_level: ${{ inputs.error_level }}
annotate: ${{ inputs.annotate }}
output_format: ${{ inputs.output_format }}
version: ${{ inputs.version }}
run: ${{ github.action_path }}/hadolint.sh

branding:
Expand Down
2 changes: 1 addition & 1 deletion lib/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function run() {
fi
done

# Set version
# Export version
output_hadolint_version

validate_error_level "${ERRORLEVEL}" || exit_with_error "Provided error level is not supported. Valid values: -1, 0, 1, 2"
Expand Down