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: add dockerfile linting #382

Merged
merged 155 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
dd3e505
FEAT: add dockerfile linter step
SMoraisAnsys Jan 3, 2024
f0ee1de
FEAT: add dockerfile linter dedicated action
SMoraisAnsys Jan 3, 2024
65d0e7c
REFACT: rename action file and how it works
SMoraisAnsys Jan 3, 2024
b931146
REFACT: rework code-style to use docker-style
SMoraisAnsys Jan 3, 2024
b21ca3c
CI: working-directory does not work with uses
SMoraisAnsys Jan 3, 2024
effa692
CI: fix workflow
SMoraisAnsys Jan 4, 2024
05b15cf
CI: add working-directory workaround
SMoraisAnsys Jan 4, 2024
0e2e4f1
MISC: clarify step message
SMoraisAnsys Jan 4, 2024
5086f10
MISC: clean up
SMoraisAnsys Jan 4, 2024
07112c9
FEAT: lint allowed dirs if they exist
SMoraisAnsys Jan 4, 2024
fbee6c4
BUGFIX: add version to uses
SMoraisAnsys Jan 4, 2024
0edfed7
REFACT: rework action to use working-directory
SMoraisAnsys Jan 4, 2024
8c6c137
WIP: test using pattern
SMoraisAnsys Jan 4, 2024
ce25ea6
WIP: test gh actions
SMoraisAnsys Jan 4, 2024
841d0e6
FEAT: add error level
SMoraisAnsys Jan 4, 2024
c72f16b
WIP: use directory path
SMoraisAnsys Jan 4, 2024
f80f5b6
WIP: ternary dockerfile path
SMoraisAnsys Jan 4, 2024
73fb703
WIP
SMoraisAnsys Jan 4, 2024
1fbf6d4
WIP
SMoraisAnsys Jan 4, 2024
f1eb842
WIP: specify path in devcontainer
SMoraisAnsys Jan 4, 2024
99b5ac6
WIP: add error-level to code-style
SMoraisAnsys Jan 4, 2024
b3be348
WIP: do not use recursive with .devcontainer
SMoraisAnsys Jan 4, 2024
1c97a3f
WIP: cleanup
SMoraisAnsys Jan 4, 2024
d30dd82
CI: fix doc
SMoraisAnsys Jan 4, 2024
75a1a0e
WIP: update doc
SMoraisAnsys Jan 4, 2024
502f897
MISC: cleanup docker-style version
SMoraisAnsys Jan 4, 2024
5067f3f
REFACT: remove deprecated set-output command
SMoraisAnsys Jan 15, 2024
9126b02
DOC: fix option typo
SMoraisAnsys Jan 15, 2024
d6b1f31
REFACT: rename CI variable
SMoraisAnsys Jan 17, 2024
36e8043
REFACT: rename CI variable
SMoraisAnsys Jan 17, 2024
6f0564b
Apply suggestions from code review
SMoraisAnsys Jan 17, 2024
198dfaf
REFACT: add logging and disable lint by default
SMoraisAnsys Jan 17, 2024
9a59c70
REFACT: update log message
SMoraisAnsys Jan 17, 2024
fb1a01e
WIP: test on fork
SMoraisAnsys Jan 17, 2024
a78e2b1
FIX: wrong sequence of steps
SMoraisAnsys Jan 17, 2024
a571a86
WIP: fixing step sequence
SMoraisAnsys Jan 17, 2024
cfb705c
WIP: fix step sequences
SMoraisAnsys Jan 17, 2024
32eeb57
WIP: fix step sequences
SMoraisAnsys Jan 17, 2024
c44d563
FIX: default deactivate lint
SMoraisAnsys Jan 17, 2024
564aea7
FIX: default deactivate lint
SMoraisAnsys Jan 18, 2024
d72dea3
FIX: default deactivate lint
SMoraisAnsys Jan 18, 2024
b3bbc52
FIX: default deactivate lint
SMoraisAnsys Jan 18, 2024
407d822
FIX: default deactivate lint
SMoraisAnsys Jan 18, 2024
59230d2
WIP
SMoraisAnsys Jan 18, 2024
638585e
WIP
SMoraisAnsys Jan 18, 2024
1effe29
WIP
SMoraisAnsys Jan 18, 2024
31ae520
Merge branch 'main' into feat/lint_dockerfile
RobPasMue Jan 18, 2024
a8bc58f
FIX: use action docker-style main version
SMoraisAnsys Jan 18, 2024
78016da
FIX: indentation warning
SMoraisAnsys Jan 18, 2024
c057efc
Apply suggestions from code review
SMoraisAnsys Jan 19, 2024
fbc2b44
REFACT: docker style action
SMoraisAnsys Jan 23, 2024
2bc8ba9
REFACT: code style action
SMoraisAnsys Jan 23, 2024
98c3da2
REFACT: docker style action
SMoraisAnsys Jan 23, 2024
5251518
REFACT: code style action
SMoraisAnsys Jan 23, 2024
07e6991
REFACT: update comment
SMoraisAnsys Jan 23, 2024
7f0caee
REFACT: code style action
SMoraisAnsys Jan 23, 2024
72236b6
REFACT: run hadolint-gh-action multiple times
SMoraisAnsys Feb 2, 2024
a745ce3
Merge branch 'main' into feat/lint_dockerfile
RobPasMue Feb 4, 2024
8a3941f
DOC: notify hadolint shell pragma
SMoraisAnsys Feb 6, 2024
66ef695
MISC: use ansys/action main in code-style
SMoraisAnsys Feb 6, 2024
06edd94
MISC: format
SMoraisAnsys Feb 6, 2024
3459276
DOC: update step name
SMoraisAnsys Feb 6, 2024
44691dc
REFACT: change no docker dir warning message
SMoraisAnsys Feb 8, 2024
bf8c413
FEAT: add dockerfile linter step
SMoraisAnsys Jan 3, 2024
2f558cb
FEAT: add dockerfile linter dedicated action
SMoraisAnsys Jan 3, 2024
456167b
REFACT: rename action file and how it works
SMoraisAnsys Jan 3, 2024
b0d0e30
REFACT: rework code-style to use docker-style
SMoraisAnsys Jan 3, 2024
e721887
CI: working-directory does not work with uses
SMoraisAnsys Jan 3, 2024
d69c2ce
CI: fix workflow
SMoraisAnsys Jan 4, 2024
10b134f
CI: add working-directory workaround
SMoraisAnsys Jan 4, 2024
5fdab83
MISC: clarify step message
SMoraisAnsys Jan 4, 2024
eb8e7fa
MISC: clean up
SMoraisAnsys Jan 4, 2024
3f3fc96
FEAT: lint allowed dirs if they exist
SMoraisAnsys Jan 4, 2024
26b3e4f
BUGFIX: add version to uses
SMoraisAnsys Jan 4, 2024
3b280be
REFACT: rework action to use working-directory
SMoraisAnsys Jan 4, 2024
1887fdf
WIP: test using pattern
SMoraisAnsys Jan 4, 2024
12eacfd
WIP: test gh actions
SMoraisAnsys Jan 4, 2024
d3898be
FEAT: add error level
SMoraisAnsys Jan 4, 2024
ebbf909
WIP: use directory path
SMoraisAnsys Jan 4, 2024
7306b10
WIP: ternary dockerfile path
SMoraisAnsys Jan 4, 2024
9adfeee
WIP
SMoraisAnsys Jan 4, 2024
e908a39
WIP
SMoraisAnsys Jan 4, 2024
f67be9c
WIP: specify path in devcontainer
SMoraisAnsys Jan 4, 2024
50a5f6a
WIP: add error-level to code-style
SMoraisAnsys Jan 4, 2024
ad0922e
WIP: do not use recursive with .devcontainer
SMoraisAnsys Jan 4, 2024
973a2e1
WIP: cleanup
SMoraisAnsys Jan 4, 2024
21db95d
CI: fix doc
SMoraisAnsys Jan 4, 2024
926075b
WIP: update doc
SMoraisAnsys Jan 4, 2024
7e4f029
MISC: cleanup docker-style version
SMoraisAnsys Jan 4, 2024
0aea58e
REFACT: remove deprecated set-output command
SMoraisAnsys Jan 15, 2024
bbb9097
DOC: fix option typo
SMoraisAnsys Jan 15, 2024
e7af924
REFACT: rename CI variable
SMoraisAnsys Jan 17, 2024
a14c25e
REFACT: rename CI variable
SMoraisAnsys Jan 17, 2024
d1df95d
Apply suggestions from code review
SMoraisAnsys Jan 17, 2024
572e819
REFACT: add logging and disable lint by default
SMoraisAnsys Jan 17, 2024
5562079
REFACT: update log message
SMoraisAnsys Jan 17, 2024
cb250d5
WIP: test on fork
SMoraisAnsys Jan 17, 2024
bfb4573
FIX: wrong sequence of steps
SMoraisAnsys Jan 17, 2024
d7f2858
WIP: fixing step sequence
SMoraisAnsys Jan 17, 2024
54fa138
WIP: fix step sequences
SMoraisAnsys Jan 17, 2024
b8587fc
WIP: fix step sequences
SMoraisAnsys Jan 17, 2024
6634568
FIX: default deactivate lint
SMoraisAnsys Jan 17, 2024
d98a7fb
FIX: default deactivate lint
SMoraisAnsys Jan 18, 2024
525d0f1
FIX: default deactivate lint
SMoraisAnsys Jan 18, 2024
7c8e26a
FIX: default deactivate lint
SMoraisAnsys Jan 18, 2024
12d6999
FIX: default deactivate lint
SMoraisAnsys Jan 18, 2024
a30ec9a
WIP
SMoraisAnsys Jan 18, 2024
3405305
WIP
SMoraisAnsys Jan 18, 2024
998b20b
WIP
SMoraisAnsys Jan 18, 2024
902346b
FIX: use action docker-style main version
SMoraisAnsys Jan 18, 2024
869a8ec
FIX: indentation warning
SMoraisAnsys Jan 18, 2024
354e4a1
Apply suggestions from code review
SMoraisAnsys Jan 19, 2024
3bd4bc4
REFACT: docker style action
SMoraisAnsys Jan 23, 2024
b6a0ae0
REFACT: code style action
SMoraisAnsys Jan 23, 2024
1de0ac6
REFACT: docker style action
SMoraisAnsys Jan 23, 2024
a028522
REFACT: code style action
SMoraisAnsys Jan 23, 2024
4857cdd
REFACT: update comment
SMoraisAnsys Jan 23, 2024
8234998
REFACT: code style action
SMoraisAnsys Jan 23, 2024
c5aae21
REFACT: run hadolint-gh-action multiple times
SMoraisAnsys Feb 2, 2024
cada3ff
DOC: notify hadolint shell pragma
SMoraisAnsys Feb 6, 2024
d938bce
MISC: use ansys/action main in code-style
SMoraisAnsys Feb 6, 2024
dda90fb
MISC: format
SMoraisAnsys Feb 6, 2024
93ae269
DOC: update step name
SMoraisAnsys Feb 6, 2024
26ecdda
REFACT: change no docker dir warning message
SMoraisAnsys Feb 8, 2024
35a7b63
Merge branch 'main' into feat/lint_dockerfile
SMoraisAnsys Feb 8, 2024
0d94eaf
Merge branch 'feat/lint_dockerfile' of github.com:ansys/actions into …
SMoraisAnsys Feb 9, 2024
47ff41c
Revert "MISC: use ansys/action main in code-style"
SMoraisAnsys Feb 9, 2024
78fd939
REFACT: allow multiple directory
SMoraisAnsys Feb 9, 2024
bf1b86c
FIX: step's if statement
SMoraisAnsys Feb 9, 2024
0ca43eb
MISC: fix typos
SMoraisAnsys Feb 9, 2024
4fe201a
WIP: track disappearing hadolint info
SMoraisAnsys Feb 9, 2024
3e7f360
WIP: track disappearing hadolint info
SMoraisAnsys Feb 9, 2024
356b405
WIP: track disappearing hadolint info
SMoraisAnsys Feb 9, 2024
1e3adc9
WIP: track disappearing hadolint info
SMoraisAnsys Feb 9, 2024
2ca5398
WIP: fix extra space
SMoraisAnsys Feb 9, 2024
22c3cf7
WIP: fixing wrong behavior
SMoraisAnsys Feb 9, 2024
6ba2126
WIP: fixing wrong behavior
SMoraisAnsys Feb 9, 2024
50ad930
WIP: fixing wrong behavior
SMoraisAnsys Feb 9, 2024
c16728f
WIP: fixing wrong behavior
SMoraisAnsys Feb 9, 2024
e9d7e00
WIP: fixing wrong behavior
SMoraisAnsys Feb 9, 2024
e6b9cf2
WIP: fixing wrong behavior
SMoraisAnsys Feb 9, 2024
70da484
WIP: fix no hadolint feedback
SMoraisAnsys Feb 9, 2024
6a6bc15
WIP: remove trailing space
SMoraisAnsys Feb 9, 2024
78bb3e1
FIX: log
SMoraisAnsys Feb 9, 2024
b8c7cf3
WIP: trimming space
SMoraisAnsys Feb 9, 2024
068a0bc
MISC: use major version
SMoraisAnsys Feb 9, 2024
0cf507e
FIX: code style points on main
SMoraisAnsys Feb 9, 2024
5a1bb38
FIX: multiple dir with recursive
SMoraisAnsys Feb 10, 2024
8647224
WIP: use specific branch to test
SMoraisAnsys Feb 10, 2024
20168f0
FIX: wrong input usage
SMoraisAnsys Feb 10, 2024
9910780
MISC: update warning
SMoraisAnsys Feb 10, 2024
848b5d4
Revert "WIP: use specific branch to test"
SMoraisAnsys Feb 10, 2024
375a125
Apply suggestions from code review
SMoraisAnsys Feb 12, 2024
d90d8a4
REFACT: format file
SMoraisAnsys Feb 12, 2024
0ff31ac
Merge branch 'main' into feat/lint_dockerfile
SMoraisAnsys Feb 12, 2024
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
112 changes: 112 additions & 0 deletions code-style/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ inputs:
default: true
type: boolean

docker-lint:
description: >
Extend the workflow to lint Dockerfile(s).
required: false
default: false
type: bool

docker-recursive:
description: >
Search for Dockerfile(s) recursively. Only applies to allowed directories, i.e. docker and .devcontainer.
required: false
default: false
type: bool

docker-error-level:
description: >
Fail docker-style action based on hadolint output (-1: never, 0: error, 1: warning, 2: info)
required: false
default: 2
type: int

runs:
using: "composite"
steps:
Expand All @@ -49,3 +70,94 @@ runs:
- name: "Run pre-commit"
shell: bash
run: pre-commit run --all-files --show-diff-on-failure

# ------------------------------------------------------------------------

# The following steps are applying docker-style action to allowed working dirs if they exist.
# Changes performed should coherent with the 'allowed_working_dirs' in the docker-style action.
- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Extend the workflow to lint Dockerfile(s) if option docker-lint is
set to true, exit otherwise.

- name: "Exit if docker-lint is false"
shell: bash
run: |
if [[ "${{ inputs.docker-lint }}" == "true" ]]; then
echo "RUN_DOCKER_LINT=true" >> $GITHUB_ENV
fi

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
if: env.RUN_DOCKER_LINT == 'true'
with:
level: "INFO"
message: >
Check that directory 'docker' exists at the root of the repository.
If it does not, then it means that the rest of the action should not
be performed.

- name: "Check if docker directory exists"
if: env.RUN_DOCKER_LINT == 'true'
shell: bash
run: |
if [ -d "${{ github.workspace }}/docker" ]; then
echo "HAS_DOCKER_DIR=true" >> $GITHUB_ENV
else
echo "HAS_DOCKER_DIR=false" >> $GITHUB_ENV
fi

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
if: env.HAS_DOCKER_DIR == 'true' && env.RUN_DOCKER_LINT == 'true'
with:
level: "INFO"
message: >
Lint directory '${{ github.workspace }}/docker'.

- name: "Run Dockerfile linting in docker directory"
if: env.HAS_DOCKER_DIR == 'true' && env.RUN_DOCKER_LINT == 'true'
uses: ansys/actions/docker-style@main
with:
directory: docker
recursive: ${{ inputs.docker-recursive }}
error-level: ${{ inputs.docker-error-level }}

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
if: env.RUN_DOCKER_LINT == 'true'
with:
level: "INFO"
message: >
Check if directory '.devcontainer' exists.

- name: "Check if .devcontainer directory exists"
if: env.RUN_DOCKER_LINT == 'true'
shell: bash
run: |
if [ -d "${{ github.workspace }}/.devcontainer" ]; then
echo "HAS_DEVCONTAINER_DIR=true" >> $GITHUB_ENV
else
echo "HAS_DEVCONTAINER_DIR=false" >> $GITHUB_ENV
fi

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
if: env.HAS_DEVCONTAINER_DIR == 'true' && env.RUN_DOCKER_LINT == 'true'
with:
level: "INFO"
message: >
Lint directory '${{ github.workspace }}/.devcontainer'.

- name: "Run Dockerfile linting in .devcontainer directory"
if: env.HAS_DEVCONTAINER_DIR == 'false' && env.RUN_DOCKER_LINT == 'true'
uses: ansys/actions/docker-style@main
with:
directory: .devcontainer
error-level: ${{ inputs.docker-error-level }}
10 changes: 10 additions & 0 deletions doc/source/style-actions/examples/docker-style-basic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
docker-style:
name: "Docker style"
runs-on: ubuntu-latest
steps:
- name: "Run PyAnsys docker style checks"
uses: ansys/actions/docker-style@{{ version }}
with:
directory: docker
recursive: true
error-level: 1
21 changes: 21 additions & 0 deletions doc/source/style-actions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ Doc style action
{% endfor %}


Docker style action
-------------------
.. jinja:: docker-style

{{ description }}

{{ inputs_table }}

Examples
++++++++

{% for filename, title in examples %}
.. dropdown:: {{ title }}
:animate: fade-in

.. literalinclude:: examples/{{ filename }}
:language: yaml

{% endfor %}


Commit style action
-------------------

Expand Down
138 changes: 138 additions & 0 deletions docker-style/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: >
Lint Dockerfile

description: >
Evaluate the quality of your project Dockerfile(s) by using `hadolint
<https://github.com/hadolint/hadolint/>`_. This action is expected to be used within a
matrix job to lint Dockerfile(s) from multiple directories. The action uses `hadolint-gh-action
<https://github.com/jbergstroem/hadolint-gh-action>`_ behind the scenes. If you want to evaluate multiple
Dockerfiles contained in various directories of the provided directory, use the recursive option.

This action emphasis the fact of having Dockerfile(s) contained inside the 'docker' directory in the
root of the project. Exception can be added as it is the case for the ''.devcontainer' directory.

.. warning::

This action only looks for docker files named Dockerfile.
A docker file like Dockerfile.linux will not be linted.
Two checks are performed and failing any of them results in the action failure:
- the root of the project must contain a 'docker' directory;
- the provided directory must be allowed, i.e. is either 'docker' or '.devcontainer'.

inputs:

# Required inputs

directory:
description: >
Directory from which to search for Dockerfile(s).
required: true
type: string

# Optional inputs

recursive:
description: >
Search for Dockerfile(s) recursively.
required: false
default: false
type: bool

error-level:
description: >
Fail action based on hadolint output (-1: never, 0: error, 1: warning, 2: info)
required: false
default: 2
type: int

runs:
using: "composite"
steps:

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Check that directory 'docker' exists at the root of the repository.
If it does not, then the rest of the action should not be performed.

- name: "Check if docker directory exists"
shell: bash
run: |
if [ -d "${{ github.workspace }}/docker" ]; then
echo "HAS_DOCKER_DIR=true" >> $GITHUB_ENV
else
echo "HAS_DOCKER_DIR=false" >> $GITHUB_ENV
fi

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
if: env.HAS_DOCKER_DIR == 'false'
with:
level: "WARNING"
message: >
Exit action as no 'docker' directory exists at the root of the
repository. Except in special cases, e.g. '.devcontainer', we
emphasize that docker files are expected to be in the 'docker'
directory at the root of the repository.

- name: "Exit workflow"
if: env.HAS_DOCKER_DIR == 'false'
shell: bash
run: exit 1

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
message: >
Check that '${{ inputs.directory }}' is among allowed directories, i.e.
'docker' and '.devcontainer'.

# Changes performed in allowed_working_dirs should be applied to the code-style action.
- name: "Check provided directory"
shell: bash
run: |
allowed_working_dirs=("docker" ".devcontainer")
is_allowed=false
for dir in "${allowed_working_dirs[@]}"
do
if [ "$dir" == "${{ inputs.directory }}" ] ; then
is_allowed=true
fi
done
echo "DIRECTORY_ALLOWED=$is_allowed" >> $GITHUB_ENV

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
if: env.DIRECTORY_ALLOWED == 'false'
with:
level: "ERROR"
message: >
Exit action because the provided directory isn't allowed.

- name: "Exit workflow"
if: env.DIRECTORY_ALLOWED == 'false'
shell: bash
run: exit 1

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
if: env.DIRECTORY_ALLOWED == 'true'
with:
level: "INFO"
message: >
Lint directory '${{ github.workspace }}/${{ inputs.directory }}'.

- name: "Run Hadolint"
if: env.DIRECTORY_ALLOWED == 'true'
uses: jbergstroem/hadolint-gh-action@v1
with:
dockerfile: ${{ inputs.recursive == 'true' && format('{0}/**/Dockerfile', inputs.directory) || format('{0}/Dockerfile', inputs.directory) }}
error_level: ${{ inputs.error-level }}
Loading