mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Propose semver version script for #45
This commit is contained in:
		
							parent
							
								
									4f32d4e780
								
							
						
					
					
						commit
						3e6530c813
					
				
					 1 changed files with 31 additions and 0 deletions
				
			
		
							
								
								
									
										31
									
								
								contrib/semver/version.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								contrib/semver/version.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,31 @@
 | 
				
			||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Get the last tag
 | 
				
			||||||
 | 
					TAG=$(git describe --abbrev=0 --tags 2>/dev/null)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Get the number of commits from the last tag, or if not, from
 | 
				
			||||||
 | 
					# the first commit
 | 
				
			||||||
 | 
					COUNT=$( \
 | 
				
			||||||
 | 
					  git rev-list v$TAG..HEAD --count 2>/dev/null || \
 | 
				
			||||||
 | 
					  git rev-list HEAD --count 2>/dev/null \
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Check if it matches the vX.Y.Z format
 | 
				
			||||||
 | 
					grep "v[0-9]*\.[0-9]*\.[0-9]*" <<< $TAG &>/dev/null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# If it doesn't, abort
 | 
				
			||||||
 | 
					if [ $? -ne 0 ]; then
 | 
				
			||||||
 | 
					  printf 'v0.0.0-%d' "$COUNT"
 | 
				
			||||||
 | 
					  exit -1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Trim the "v" off the front
 | 
				
			||||||
 | 
					TAG=$(echo $TAG | cut -c 2-)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Split out into major, minor and patch numbers
 | 
				
			||||||
 | 
					MAJOR=$(echo $TAG | cut -d "." -f 1)
 | 
				
			||||||
 | 
					MINOR=$(echo $TAG | cut -d "." -f 2)
 | 
				
			||||||
 | 
					PATCH=$(echo $TAG | cut -d "." -f 3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Output in the desired format
 | 
				
			||||||
 | 
					printf 'v%d.%d.%d-%d' "$MAJOR" "$MINOR" "$PATCH" "$COUNT"
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue