Skip to content

Commit

Permalink
fix: changed the jenkins file to leave the repo clean
Browse files Browse the repository at this point in the history
  • Loading branch information
alecszaharia committed Jun 23, 2023
1 parent 82ee9da commit b5d39ca
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
20 changes: 14 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ pipeline {
sh("""
if git rev-parse --git-dir > /dev/null 2>&1; then
echo "The repo is already cloned"
git reset --hard HEAD
git checkout .;
git fetch;
git clean -fd;
git reset --hard origin/${params.releaseBranch};
git fetch origin
git checkout master
git reset --hard origin/master
./jenkins/reset-repo.sh ./
git checkout -t origin/${params.releaseBranch}
else
git config --global user.email "[email protected]
git config --global user.name "Jenkins jenkinovici
git config --global user.name "Jenkins Jenkinovici
git clone [email protected]:ThemeFuse/Brizy.git ./
fi
""")
Expand Down Expand Up @@ -147,13 +147,21 @@ pipeline {
sh "rm '${zipFilePath}'"
sh "rm *.zip"
}

failure{
discordSend title: JOB_NAME, footer: discordFooter, link: env.BUILD_URL, result: currentBuild.currentResult, description: "Changelog: \n ${changelog}", webhookURL: env.DISCORD_WEBHOOK_URL
}

aborted{
discordSend title: JOB_NAME, footer: discordFooter, link: env.BUILD_URL, result: currentBuild.currentResult, description: "Changelog: \n ${changelog}", webhookURL: env.DISCORD_WEBHOOK_URL
}

always {

sshagent (credentials: ['ssh_with_passphrase_provided']) {
sh "./jenkins/reset-repo.sh ./"
}
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions jenkins/clean-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ cd $1
echo -e "\nInstall composer dependencies"
echo -e "-----------------------------------------------------------------------------"

rm -rf vendor
/usr/bin/composer install --no-dev || { exit 1; }

# delete all files that are not needed in the final build
echo -e "\nDelete all dev files"
echo -e "-----------------------------------------------------------------------------"
Expand Down
5 changes: 5 additions & 0 deletions jenkins/composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ echo -e "-----------------------------------------------------------------------
echo -e "\Clear composer cache"
echo -e "-----------------------------------------------------------------------------"
/usr/bin/composer clearcache

echo -e "\Install composer dependencies"
echo -e "-----------------------------------------------------------------------------"
rm -rf vendor
/usr/bin/composer install --no-dev || { exit 1; }
23 changes: 13 additions & 10 deletions jenkins/git-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@ RELEASE_BRANCH=$3
echo -e "\nPublishing the release in GIT"
echo -e "-----------------------------------------------------------------------------"
git add ./public/editor-build/$EDITOR_VERSION
git add ./public/editor-client/*
git add ./readme.txt
git add ./README.md
git add ./brizy.php
git commit -a -m "Build $BUILD_VERSION"
echo -e "\nPublishing the release branch: $RELEASE_BRANCH"
echo -e "-----------------------------------------------------------------------------"
git push origin $RELEASE_BRANCH

git checkout develop
git reset --hard origin/develop
git merge --no-ff -m "Merge [$RELEASE_BRANCH] in develop" $RELEASE_BRANCH
git push origin develop

echo -e "\nMerge the $RELEASE_BRANCH in master"
echo -e "-----------------------------------------------------------------------------"


git branch -d master
git checkout -t origin/master
git checkout master
git reset --hard origin/master
# shellcheck disable=SC2086
git merge --no-ff -m "Merge [$RELEASE_BRANCH] in master" $RELEASE_BRANCH
git push origin master

echo -e "\Creating the release tag: $BUILD_VERSION"
echo -e "-----------------------------------------------------------------------------"
Expand All @@ -35,6 +32,12 @@ git tag $BUILD_VERSION

echo -e "\nPublishing the master branch and tags"
echo -e "-----------------------------------------------------------------------------"
git push origin master --tags
git push origin --tags

git checkout develop
git reset --hard origin/develop
git merge --no-ff -m "Merge [$RELEASE_BRANCH] in develop" $RELEASE_BRANCH
git push origin develop



26 changes: 26 additions & 0 deletions jenkins/reset-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

REPO_PATH=$1
REPO_BRANCH=$2


cd $REPO_PATH

# fetch all changes
git fetch origin

# unstage all files
git reset
git clean -fd

# reset all local branches to original state
git checkout develop
git reset --hard origin/develop

git checkout master
git reset --hard origin/master

# delete all local branches except for master/main and develop
if [[ $(git branch | grep -v "master$\|develop$") ]]; then
git branch | grep -v "master$\|develop$" | xargs git branch -D
fi

0 comments on commit b5d39ca

Please sign in to comment.