Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Last active August 28, 2023 16:25
Show Gist options
  • Save AvocadoVenom/19cda1010a8350547cabcf1e06edd9af to your computer and use it in GitHub Desktop.
Save AvocadoVenom/19cda1010a8350547cabcf1e06edd9af to your computer and use it in GitHub Desktop.
# Considering that your app version is stored in VERSION.md file
#
# Example: ./gitlab-changelog.sh
# Example: ./gitlab-changelog.sh <YOUR-GITLAB-PROJECT-ACCESS-TOKEN>
#!/bin/bash
app_version=$(cat VERSION.md)
branch=dev
link=https://gitlab.com/<project-path>/-/blob/${branch}/CHANGELOG.md
# You can retrieve env variables from script arguments (here 1st argument)
GITLAB_PROJECT_ACCESS_TOKEN=$1
# Or parse .env file
GITLAB_PROJECT_CHANGELOG_API=$(cat ./.env \
| grep GITLAB_PROJECT_CHANGELOG_API \
| head -1 \
| awk -F= '{ print $2 }')
if [ -z "${GITLAB_PROJECT_CHANGELOG_API}" ]; then echo "Cannot find GITLAB_PROJECT_CHANGELOG_API env variable"; exit -1; fi
response=$(curl --write-out '%{http_code}' --request POST --header "PRIVATE-TOKEN: ${GITLAB_PROJECT_ACCESS_TOKEN}" --data "version=${app_version}&branch=${branch}" "${GITLAB_PROJECT_CHANGELOG_API}")
if [ $response == 200 ]
then echo "Updated changelog: ${link}"
else echo "An error occurred when requesting GitLab API"
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment