Skip to content

Instantly share code, notes, and snippets.

@maurobaraldi
Created May 7, 2019 15:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maurobaraldi/cc1e68b8d1db4796ee6fb78e7ce03732 to your computer and use it in GitHub Desktop.
Save maurobaraldi/cc1e68b8d1db4796ee6fb78e7ce03732 to your computer and use it in GitHub Desktop.
pre-commit git hook to check if chart version is updated.
#!/bin/bash
ORIGIN=$(git log -n 1 --oneline --format=format:%H origin/master helm/pfapi/Chart.yaml)
LOCAL=$(git log -n 1 --oneline --format=format:%H HEAD helm/pfapi/Chart.yaml)
CHART=$(git status --porcelain | grep Chart.yaml)
if [ "$ORIGIN" = "$LOCAL" ]; then
if [[ -z "$CHART" ]]; then
echo -e "#######################################\n# Don't forget to update Charts.yaml. #\n#######################################"
fi
fi
@maurobaraldi
Copy link
Author

Description

The hook compare the Chart.yaml file from current branch to the master (in my case) and if the commits hash are equal, and the Chart.yaml isn't in changed files, alerts about change chart version.

Install

  • Open a file in <project_pat>/.git/hooks/pre-commit and paste this content in.
  • Change the path from Chart.yaml file to the file of your project.
  • Change the branch to your development flow (staging/sandbox/tests...).
  • Save file.
  • Set permissions to executable chmod +x <project_pat>/.git/hooks/pre-commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment