Created
February 5, 2023 04:11
-
-
Save matthewdeanmartin/b15d9e479d0222ca531f0f0026892dcd to your computer and use it in GitHub Desktop.
Run shell check on gitlab ci yml code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
import subprocess | |
# Load the YAML file | |
with open('file.yml', 'r') as stream: | |
data = yaml.safe_load(stream) | |
# Extract the bash lines from before_script, script, and after_script | |
bash_lines = [] | |
for key in ['before_script', 'script', 'after_script']: | |
if key in data['package']: | |
bash_lines += data['package'][key] | |
# Pass the bash lines to shellcheck | |
for line in bash_lines: | |
result = subprocess.run(['shellcheck', '-s', 'bash', '-e', 'SC2148', '-x', line], capture_output=True) | |
print(result.stdout.decode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment