Skip to content

Commit

Permalink
Merge branch 'dev' into fix-script
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Jan 9, 2024
2 parents ca2e009 + 21e24cd commit 661864b
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 95 deletions.
86 changes: 51 additions & 35 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ node("docker") {
identifier = 'v2-jf'
nodeVersion = 'v8.17.0'

masterBranch = 'v2'
devBranch = 'dev'
if (BRANCH?.trim() == 'v1') {
masterBranch = 'v1'
devBranch = 'dev-v1'
}

releaseVersion = ''

repo = 'jfrog-cli'
sh 'rm -rf temp'
sh 'mkdir temp'
Expand Down Expand Up @@ -54,17 +63,13 @@ node("docker") {
"""
}

stage('synchronize branches') {
masterBranch = 'v2'
devBranch = 'dev'
if (BRANCH?.trim() == 'v1') {
masterBranch = 'v1'
devBranch = 'dev-v1'
}
synchronizeBranches(masterBranch, devBranch)
stage('Sync branches') {
setReleaseVersion()
validateReleaseVersion()
synchronizeBranches()
}

stage('install npm') {
stage('Install npm') {
installNpm(nodeVersion)
}

Expand All @@ -80,6 +85,11 @@ node("docker") {
}
}

def getCliVersion(exePath) {
version = sh(script: "$exePath -v | tr -d 'jfrog version' | tr -d '\n'", returnStdout: true)
return version
}

def runRelease(architectures) {
stage('Build JFrog CLI') {
sh "echo Running release for executable name: '$cliExecutableName'"
Expand All @@ -95,14 +105,13 @@ def runRelease(architectures) {
}

sh "mv $jfrogCliRepoDir/$cliExecutableName $builderDir"
// Extract CLI version
version = sh(script: "$builderPath -v | tr -d 'jfrog version' | tr -d '\n'", returnStdout: true)

version = getCliVersion(builderPath)
print "CLI version: $version"
}
configRepo21()

try {
validateReleaseVersion()
if (identifier != "v2") {
stage("Audit") {
dir("$jfrogCliRepoDir") {
Expand Down Expand Up @@ -164,32 +173,39 @@ def runRelease(architectures) {
}
}

def synchronizeBranches(masterBranch, devBranch) {
def setReleaseVersion() {
dir("$cliWorkspace/$repo") {
sh "git checkout $devBranch"
sh "build/build.sh"
releaseVersion = getCliVersion("./jf")
}
}

def synchronizeBranches() {
dir("$cliWorkspace/$repo") {
releaseTag = "v$RELEASE_VERSION"
withCredentials([string(credentialsId: 'ecosystem-github-automation', variable: 'GITHUB_ACCESS_TOKEN')]) {
stage("Merge to $masterBranch") {
sh """#!/bin/bash
git merge origin/$devBranch --no-edit
git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git"
"""
}
stage("Merge to $devBranch") {
sh """#!/bin/bash
git checkout $devBranch
git merge origin/$masterBranch --no-edit
git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git"
git checkout $masterBranch
"""
}
print "Merge to $masterBranch"
sh """#!/bin/bash
git checkout $masterBranch
git merge origin/$devBranch --no-edit
git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git"
"""

print "Merge to $devBranch"
sh """#!/bin/bash
git checkout $devBranch
git merge origin/$masterBranch --no-edit
git push "https://$GITHUB_ACCESS_TOKEN@github.com/jfrog/jfrog-cli.git"
git checkout $masterBranch
"""
}
}
}

def createTag() {
stage('Create a tag and a GitHub release') {
dir("$jfrogCliRepoDir") {
releaseTag = "v$RELEASE_VERSION"
releaseTag = "v$releaseVersion"
withCredentials([string(credentialsId: 'ecosystem-github-automation', variable: 'GITHUB_ACCESS_TOKEN')]) {
sh """#!/bin/bash
git tag $releaseTag
Expand All @@ -201,16 +217,16 @@ def createTag() {
}

def validateReleaseVersion() {
if (RELEASE_VERSION=="") {
error "RELEASE_VERSION parameter is mandatory on this execution mode"
if (releaseVersion=="") {
error "releaseVersion parameter is empty"
}
if (RELEASE_VERSION.startsWith("v")) {
error "RELEASE_VERSION parameter should not start with a preceding \"v\""
if (releaseVersion.startsWith("v")) {
error "releaseVersion parameter should not start with a preceding \"v\""
}
// Verify version stands in semantic versioning.
def pattern = /^2\.(\d+)\.(\d+)$/
if (!(RELEASE_VERSION =~ pattern)) {
error "RELEASE_VERSION is not a valid version"
if (!(releaseVersion =~ pattern)) {
error "releaseVersion is not a valid version"
}
}

Expand Down
3 changes: 3 additions & 0 deletions artifactory/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,9 @@ func gitLfsCleanCmd(c *cli.Context) error {
}

func curlCmd(c *cli.Context) error {
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
return err
}
if c.NArg() < 1 {
return cliutils.WrongNumberOfArgumentsHandler(c)
}
Expand Down
111 changes: 111 additions & 0 deletions build/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash

# Function to get fromVersion from a file
populateFromVersion() {
build/build.sh
fromVersion=$(./jf -v | tr -d 'jfrog version' | tr -d '\n')
}

# Function to validate arguments
validateArg() {
# Check if both arguments are provided
if [ $# -ne 1 ]; then
echo "Error: Please provide exactly one argument - the version to bump."
exit 1
fi
}

validateVersions() {
# Extract arguments
fromVersion=$1
toVersion=$2

# Check if arguments are non-empty
if [ -z "$fromVersion" ] || [ -z "$toVersion" ]; then
echo "Error: Both fromVersion and toVersion must have non-empty values."
exit 1
fi

# Check if arguments are not identical
if [ "$fromVersion" = "$toVersion" ]; then
echo "Error: fromVersion and toVersion must have different values."
exit 1
fi

echo Bumping version from $fromVersion to $toVersion
}

createBranch() {
branchName=bump-ver-from-$fromVersion-to-$toVersion
git remote add upstream https://github.com/jfrog/jfrog-cli.git
git checkout dev
git fetch upstream dev
git pull upstream dev
git push
git checkout -b $branchName
}

# Function to replace version in file
replaceVersion() {
local filePath=$1
local line=$2
local fromVersion=$3
local toVersion=$4

# Check if the file exists
if [ ! -e "$filePath" ]; then
echo "Error: File '$filePath' not found."
exit 1
fi

# Use awk to replace the value if the line is found
awk -v line="$line" -v from="$fromVersion" -v to="$toVersion" '
index($0, line) {
gsub(from, to);
found=1;
}
{ print }
END {
if (found != 1) {
print "Error: The specified line ('" line "') does not exist in the file ('" filePath "').";
exit 1;
}
}
' "$filePath" > "$filePath.tmp" && mv "$filePath.tmp" "$filePath"

# Validate if the file was modified using git
if git diff --exit-code "$filePath" > /dev/null; then
echo "Error: File '$filePath' was not modified."
exit 1
fi

git add "$filePath"
}

## Validate the argument was received.
validateArg

## Read the script argument into the toVersion variable
toVersion=$1

## Call the function to populate the fromVersion argument from the current version of the local JFrog CLI binary
populateFromVersion

## Call the function to validate arguments
validateVersions "$fromVersion" "$toVersion"

## Create a new branch
createBranch

## Add calls to the function to replace version in file with specified filePath values
replaceVersion "utils/cliutils/cli_consts.go" "CliVersion = \"$fromVersion\"" "$fromVersion" "$toVersion"
replaceVersion "build/npm/v2/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion"
replaceVersion "build/npm/v2/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion"
replaceVersion "build/npm/v2-jf/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion"
replaceVersion "build/npm/v2-jf/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion"

## Print success message if validation and replacement pass
echo "Version bumped successfully."

## Push the new branch, with the version bump
git push --set-upstream origin $branchName
2 changes: 1 addition & 1 deletion build/npm/v2-jf/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/npm/v2-jf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog-cli-v2-jf",
"version": "2.52.8",
"version": "2.52.9",
"description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸",
"homepage": "https://github.com/jfrog/jfrog-cli",
"preferGlobal": true,
Expand Down
2 changes: 1 addition & 1 deletion build/npm/v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/npm/v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog-cli-v2",
"version": "2.52.8",
"version": "2.52.9",
"description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸",
"homepage": "https://github.com/jfrog/jfrog-cli",
"preferGlobal": true,
Expand Down
Loading

0 comments on commit 661864b

Please sign in to comment.