Skip to content

Instantly share code, notes, and snippets.

@matthewdeanmartin
Created February 5, 2023 04:11
Show Gist options
  • Save matthewdeanmartin/b15d9e479d0222ca531f0f0026892dcd to your computer and use it in GitHub Desktop.
Save matthewdeanmartin/b15d9e479d0222ca531f0f0026892dcd to your computer and use it in GitHub Desktop.
Run shell check on gitlab ci yml code
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