All Projects → passsy → gradle-GitVersioner

passsy / gradle-GitVersioner

Licence: Apache-2.0 license
generates a project version for the given git project to distinguish between builds

Projects that are alternatives of or similar to gradle-GitVersioner

clearml-server-helm
ClearML Server for Kubernetes Clusters Using Helm
Stars: ✭ 18 (-77.5%)
Mutual labels:  version-control
OctoPrint-GitFiles
With this plugin, you can use a github/gitlab repository for keeping your OctoPrint Files collection up-to-date.
Stars: ✭ 28 (-65%)
Mutual labels:  version-control
autorevision
A script for extracting version information useful in release/build scripting.
Stars: ✭ 73 (-8.75%)
Mutual labels:  revision
Bash-Git
D-Lab's 3 hour introduction to basic Bash commands and using version control with Git and Github.
Stars: ✭ 126 (+57.5%)
Mutual labels:  version-control
gg
Git with less typing
Stars: ✭ 55 (-31.25%)
Mutual labels:  version-control
pro.fessional.wings
WingsBoot=BKB+飞鞋+SpringBoot。其核心价值是:①使团队快速实现业务目标;②快速偿还技术债务;③安全的面向程序和业务重构。
Stars: ✭ 78 (-2.5%)
Mutual labels:  version-control
Tutorials
🗒 codebar's tutorials
Stars: ✭ 231 (+188.75%)
Mutual labels:  version-control
versionaire
Provides an immutable, thread-safe, and semantic version type.
Stars: ✭ 71 (-11.25%)
Mutual labels:  version-control
blendgit
manage versions of Blender documents using Git
Stars: ✭ 93 (+16.25%)
Mutual labels:  version-control
nb-clean
Clean Jupyter notebooks of outputs, metadata, and empty cells, with Git integration
Stars: ✭ 72 (-10%)
Mutual labels:  version-control
christian-git
A wrapper for Git to sanctify your version control workflow. ✝️
Stars: ✭ 84 (+5%)
Mutual labels:  version-control
10-days-of-git-and-github
asabeneh.github.io/10-days-of-git-and-github/
Stars: ✭ 786 (+882.5%)
Mutual labels:  version-control
powerbi-vcs
WIP (properly) version control and collaborate on your *.pbi{tx} files
Stars: ✭ 78 (-2.5%)
Mutual labels:  version-control
git-rdm
A research data management plugin for the Git version control system.
Stars: ✭ 34 (-57.5%)
Mutual labels:  version-control
python-aos-lesson
Python for Atmosphere and Ocean Scientists
Stars: ✭ 78 (-2.5%)
Mutual labels:  version-control
togepi
A version control system built using Python and DropBox API
Stars: ✭ 23 (-71.25%)
Mutual labels:  version-control
re
"What Are You Syncing About?" – Ninjadev's submission for Revision 2017
Stars: ✭ 69 (-13.75%)
Mutual labels:  revision
Exact
An open source online platform for collaborative image labeling of almost everything
Stars: ✭ 47 (-41.25%)
Mutual labels:  version-control
breezy
A Distributed Version Control System with a Friendly UI
Stars: ✭ 76 (-5%)
Mutual labels:  version-control
AutoVer
Configurable automatic or real time backup and personal versioning system
Stars: ✭ 65 (-18.75%)
Mutual labels:  version-control

Git Versioner for gradle

Deprecated

DON'T USE THIS SCRIPT! It contains bugs and can't be updated (due to the fact hundreds of projects pull it directly from master). Please use

About

Version numbers are hard. It was easier with SVN where the revision number got increased for every commit. Revision 342 was clearly older than revision 401. This is not possible in git because branching is so common (and that's a good thing). 342 commits could mean multiple commits on different branches. Not even the latest common commit in history is clear. This projects aims to bring the SVN simplicity and more back to git for your gradle (android) project.

####Read the story behind on medium

Idea

Just count the commits of the main branch (master or develop in most cases) as the base revision. The commits on the feature branch are counted too, but are shown separately.

This technique is often used and far better than just a SHA1 of the latest commit. But I think it gives too much insights of the project. Once a client knows commit count == version number they start asking why the commit count is so high/low for the latest release.

That's why this versioner adds the project age (initial commit to latest commit) as seconds part to the revision. By default, one year equals 1000. This means that the revision count increases every 8.67 hours. When you started your project half a year ago and you have 325 commits the revision is something around 825.

When working on a feature branch this versioner adds a two char identifier of the branch name and the commit count since branching. When you are building and you have uncommited files it adds the count of the uncommited files and "-SNAPSHOT"

Reading the Version

Normal build number

1083

1083: number of commits + time component. this revision is in the master branch.

On a feature branch

1083-dm4

-dm4: 4 commits since branching from revision 1083. First two [a-z] chars of the base64 encoded branch name. Clients don't have to know about your information and typos in branch names. But you have to be able to distinguish between different builds of different branches.

Build with local changes

1083-dm4(6)-SNAPSHOT

(6)-SNAPSHOT: 6 uncommited but changed files. Hopefully nothing a client will ever see. But you know that your version is a work in progress version with some local changes

Get it

Configure the plugin in you top level build.gradle. This makes total sense because it's the revision of the top level project and not of a single module.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    // ...
}

// Optional: configure the versioner
ext.gitVersioner = [
        defaultBranch           : "develop",  // default "master"
        stableBranches          : ["master", "someOtherBranch"], // default [], the feature branch postfix (-dm4(6)) will not be appended on stable branches, all commits are included into the version number calculation
        yearFactor              : 1200, 	  // default "1000", increasing every 8.57h
        snapshotEnabled         : false,      // default false, the "-SNAPSHOT" postfix
        localChangesCountEnabled: false,       // default false, the (<commitCount>) before -SNAPSHOT
        shortName: { gitVersion ->            // optional closure to build a short name
          // allows you to add your own short name logic
          // All properties from gitVersion are available
          // can be used for CI `System.getenv("BUILD_NUMBER")`

          // i.e. use short sha1
          return gitVersion.commit.subSequence(0, 7)
        }
]
// import the script which runs the version generation
apply from: 'https://raw.githubusercontent.com/passsy/gradle-GitVersioner/master/git-versioner.gradle'

// variable `gitVersionName` can be used everywhere to get the revision name
println("versionName: $gitVersionName") // output: "versionName: 1083-dm4(6)-SNAPSHOT"

Consider using this cache plugin for offline support.

All inforamtion is not only available as a single String. You can create your own pattern using the ext.gitVersion Object

// get granular information with variable `gitVersion` of type `GitVersion`
println("version: ${gitVersion.version}") // output "version: 1083"

// see all available attributes
class GitVersion {
    String name;
    int version;
    String branchName;
    String shortBranch;
    int branchVersion;
    int localChanges;
    String commit;
}

Android

Display the version in your android app

app build.gradle

android {
    defaultConfig {
        ...

        buildConfigField 'String', 'REVISION', "\"$gitVersionName\""
    }
}

in your Activity

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    	Toast.makeText(this, BuildConfig.REVISION, Toast.LENGTH_SHORT).show();
    }

License

Copyright 2016 Pascal Welsch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].