Skip to content

Instantly share code, notes, and snippets.

Last active March 2, 2023 23:23
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Update Npm and SonarQube on Git commit (using Husky)
"name": "demo-project",
"version": "0.0.3",
"husky": {
"hooks": {
"pre-commit": "npm --no-git-tag-version version patch && sh && git add ."
# must be unique in a given SonarQube instance
# --- optional properties ---
# defaults to project key
sonar.projectName=Demo Project
# defaults to 'not provided'
#!/usr/bin/env bash
echo "Updating the SonarQube properties..."
# Get the version from package.json
PACKAGE_VERSION=$(awk -F'"' '/"version": ".+"/{ print $4; exit; }' package.json)
echo "Extracted version: ${PACKAGE_VERSION}"
# Get the project name from package.json
PACKAGE_NAME=$(awk -F'"' '/"name": ".+"/{ print $4; exit; }' package.json)
echo "Extracted project: ${PACKAGE_NAME}"
# Get the Sonar properties file
SONAR_FILE=$(find ./ -iname sonar*.properties -type f)
echo "Sonar file found: ${SONAR_FILE}"
# Update the version
sed -i.bak "s#${REPLACE}#${WITH}#g" ${SONAR_FILE}
# Update the project name
sed -i.bak "s#${REPLACE}#${WITH}#g" ${SONAR_FILE}
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment