Last active
August 28, 2023 16:25
-
-
Save AvocadoVenom/19cda1010a8350547cabcf1e06edd9af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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