Skip to content

Commit

Permalink
Mijn-8376 release proces (#1265)
Browse files Browse the repository at this point in the history
* Add Tag bases version release, remove npm version

* Enable branch publishing

* Remove comment
  • Loading branch information
timvanoostrom authored Apr 26, 2024
1 parent 2e0c999 commit 6a711b6
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ ENV MA_OTAP_ENV=$MA_OTAP_ENV
ARG MA_BUILD_ID=-1
ENV MA_BUILD_ID=$MA_BUILD_ID

ARG MA_RELEASE_VERSION_TAG=-1
ENV MA_RELEASE_VERSION_TAG=$MA_RELEASE_VERSION_TAG

ARG MA_GIT_SHA=-1
ENV MA_GIT_SHA=$MA_GIT_SHA

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "mijn-amsterdam-frontend",
"version": "4.100.0",
"repository": {
"type": "git",
"url": "[email protected]:Amsterdam/mijn-amsterdam-frontend.git"
Expand Down
53 changes: 34 additions & 19 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
#!/bin/bash

set -e

BRANCH="production-release"

git fetch origin && \
git fetch origin -t && \
git checkout -b release-branch origin/main && \
git checkout -b "$BRANCH" origin/main && \

echo "Fetched origin, created release-branch."

NEW_TAG_D="-1"
NEW_TAG=$NEW_TAG_D

if [ $# -eq 0 ]; then
echo "No arguments provided"
exit 1
fi

for cmd in "$@"
do
case $cmd in
"--major")
echo "Incrementing Major Version#"
npm --no-git-tag-version --allow-same-version version major
echo "Incrementing Major Version"
NEW_TAG=$(sh ./semver.sh -v major)
;;
"--minor")
echo "Incrementing Minor Version#"
npm --no-git-tag-version --allow-same-version version minor
echo "Incrementing Minor Version"
NEW_TAG=$(sh ./semver.sh -v minor)
;;
"--bug")
echo "Incrementing Bug Version#"
npm --no-git-tag-version --allow-same-version version patch
"--patch")
echo "Incrementing Patch Version"
NEW_TAG=$(sh ./semver.sh -v patch)
;;
*)
echo "No version specified"
;;
esac
done

NEWVERSION=$(grep '"version"' package.json | cut -d '"' -f 4)

NEWTAG="release-v$NEWVERSION"
BRANCH="production-${NEWTAG}"
if [ $NEW_TAG == $NEW_TAG_D ]; then
exit 1
fi

echo "Adding Tag: $NEWTAG";
RELEASE_BRANCH="${BRANCH}-v${NEW_TAG}" && \

git branch -m "$BRANCH" && \
echo "Creating branch $RELEASE_BRANCH" && \
git branch -m "$RELEASE_BRANCH" && \

git add package.json package-lock.json && \
git commit -m "Bump! $NEWTAG" && \
git tag -a "$NEWTAG" -m "Production ${NEWTAG}" && \
git push origin --follow-tags "$BRANCH" && \
echo "New tag $NEW_TAG" && \
git tag -a "$NEW_TAG" -m "Production ${NEW_TAG}" && \

echo "Don't forget to merge to main and Approve the deploy to the production environment!"
echo "Pushing branch $RELEASE_BRANCH" && \
git push origin --follow-tags "$RELEASE_BRANCH" && \

exit 0
67 changes: 67 additions & 0 deletions scripts/semver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

VERSION=""

#get parameters
while getopts v: flag
do
case "${flag}" in
v) VERSION=${OPTARG};;
esac
done

#get highest tag number, and add 1.0.0 if doesn't exist
CURRENT_VERSION=`git describe --abbrev=0 --tags 2>/dev/null`

if [[ $CURRENT_VERSION == '' ]]
then
CURRENT_VERSION='1.0.0'
fi
# echo "Current Version: $CURRENT_VERSION"



#replace . with space so can split into an array
CURRENT_VERSION_PARTS=(${CURRENT_VERSION//./ })

#get number parts
VNUM1=${CURRENT_VERSION_PARTS[0]}
VNUM2=${CURRENT_VERSION_PARTS[1]}
VNUM3=${CURRENT_VERSION_PARTS[2]}

if [[ $VERSION == 'major' ]]
then
VNUM1=$((VNUM1+1))
VNUM2=0 # Reset minor
VNUM3=0 # Reset patch
elif [[ $VERSION == 'minor' ]]
then
VNUM2=$((VNUM2+1))
VNUM3=0 # Reset patch
elif [[ $VERSION == 'patch' ]]
then
VNUM3=$((VNUM3+1))
else
echo "No version type (https://semver.org/) or incorrect type specified, try: -v [major, minor, patch]"
exit 1
fi


#create new tag
NEW_TAG="$VNUM1.$VNUM2.$VNUM3"
# echo "($VERSION) updating $CURRENT_VERSION to $NEW_TAG"

#get current hash and see if it already has a tag
GIT_COMMIT=`git rev-parse HEAD`
NEEDS_TAG=`git describe --contains $GIT_COMMIT 2>/dev/null`

#only tag if no tag already
#to publish, need to be logged in to npm, and with clean working directory: `npm login; git stash`
if [ -z "$NEEDS_TAG" ]; then
echo $NEW_TAG
else
echo "Already a tag on this commit"
exit 1
fi

exit 0
2 changes: 1 addition & 1 deletion src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const BFF_REQUEST_CACHE_ENABLED =
? String(process.env.BFF_REQUEST_CACHE_ENABLED).toLowerCase() === 'true'
: true;

export const RELEASE_VERSION = `mijnamsterdam-bff@${process.env.npm_package_version}`;
export const RELEASE_VERSION = `mijnamsterdam-bff@${process.env.MA_RELEASE_VERSION_TAG ?? 'notset'}`;

// Urls used in the BFF api
// Microservices (Tussen Api) base url
Expand Down
4 changes: 3 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default defineConfig({
define: {
MA_OTAP_ENV: JSON.stringify(process.env.MA_OTAP_ENV || 'development'),
MA_APP_MODE: JSON.stringify(process.env.MA_APP_MODE || 'production'),
MA_APP_VERSION: JSON.stringify(process.env.npm_package_version || '-1'),
MA_APP_VERSION: JSON.stringify(
process.env.MA_RELEASE_VERSION_TAG || 'notset'
),
MA_BUILD_ID: JSON.stringify(process.env.MA_BUILD_ID || '-1'),
MA_GIT_SHA: JSON.stringify(process.env.MA_GIT_SHA || '-1'),
MA_TEST_ACCOUNTS: JSON.stringify(process.env.MA_TEST_ACCOUNTS || ''),
Expand Down

0 comments on commit 6a711b6

Please sign in to comment.