Skip to content

Instantly share code, notes, and snippets.

@giehlman
Last active May 10, 2022 17:39
Show Gist options
  • Save giehlman/b6eb3cdb6320a2f4696d854c2f6f9134 to your computer and use it in GitHub Desktop.
Save giehlman/b6eb3cdb6320a2f4696d854c2f6f9134 to your computer and use it in GitHub Desktop.
Takes the version in package.json and seds it in swagger.yaml
# Get the version from package.json
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
echo "Extracted version: ${PACKAGE_VERSION}"
# Find the swagger file
SWAGGER_FILE=$(find ./ -iname swagger.yaml -type f)
echo "Swagger file found: ${SWAGGER_FILE}"
# Now do the replacement in-place (MacOS/Unix compatible)
REPLACE='^ version: .*$'
WITH=" version: '${PACKAGE_VERSION}'"
sed -i.bak "s#${REPLACE}#${WITH}#g" ${SWAGGER_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment