Git Product home page Git Product logo

garamond's Introduction

garamond

Clojars Project

garamond is a clojure utility for maintaining git tag versions and for modifying pom.xml files.

garamond is meant to be run from a tools.deps alias. It has two main uses:

  1. Maintaining a version number for a library based on git tags
  2. Postprocessing the tools.deps clojure -Spom output to update it with the project's correct artifact ID, group ID, and version number.

Installation

To use garamond, install it as an alias in your deps.edn:

 :aliases
 {...

  :garamond
  {:main-opts ["-m" "garamond.main"]
   :extra-deps {com.workframe/garamond {:mvn/version "0.4.0"}}}

 ...}

Now you can run it from the command-line via:

clojure -A:garamond

Note that garamond works on git tags; before you run it you should ensure you have at least one "annotated" git tag in your repo. You can create one via git tag --annotate -m "First version tag" v0.1.0.

garamond follows the common github convention of using tag names prepended by v as in v1.2.3. You can use the --prefix flag to modify the tags it produces. When reading tags to determine the current version, garamond relies on git describe and ignores everything before the first number.

leiningen

leiningen users can also set up an alias in project.clj to access garamond:

(defproject ...
  :aliases {"garamond" ^:pass-through-help ["trampoline" "run" "-m" "garamond.main"]})

With this in place, you can run lein garamond. Note that garamond does not have any particular hooks into leiningen internals, but it should be compatible with plugins such as lein-v (see below).

Usage

clojure -A:garamond --help will show the available options:

% clojure -A:garamond --help
garamond is a utility for printing and incrementing versions based on git tags,
and for updating pom.xml files generated by clojure -Spom with these versions.

Usage: clojure -m garamond.main [options] [increment-type]

Options:
  -h, --help                     Print usage and exit
  -d, --debug                    Print more debugging logs
      --prefix PREFIX            Use this prefix in front of versions for tags
  -p, --pom                      Generate or update the pom.xml file
  -t, --tag                      Create a new git tag based on the given version
  -m, --message MESSAGE          Commit message for git tag
  -g, --group-id GROUP-ID        Update the pom.xml file with this <groupId> value
  -a, --artifact-id ARTIFACT-ID  Update the pom.xml file with this <artifactId> value
  -u, --scm-url URL              Update the pom.xml's <scm> tag with this <url> value
      --force-version VERSION    Use this version number instead of relying on git describe

With no increment type, garamond will print the current version number and exit.

The prefix string ('v' in the tag 'v1.2.3') will be preserved in the new tag, or
it can be overridden via the -p option.

Increment types:
  major              1.2.4 -> 2.0.0
  minor              1.2.4 -> 1.3.0
  patch              1.2.4 -> 1.2.5
  major-rc           2.7.9 -> 3.0.0-rc.0, 4.0.0-rc.3 -> 4.0.0-rc.4
  minor-rc           2.7.9 -> 2.8.0-rc.0, 4.3.0-rc.0 -> 4.3.0-rc.1
  major-release      4.0.0-rc.4 -> 4.0.0, 3.2.9 -> 4.0.0
  minor-release      8.1.0-rc.4 -> 8.2.0, 5.9.4 -> 5.10.0

See https://github.com/workframers/garamond for more information.
  • clojure -A:garamond: Display the current version based on git tags
  • clojure -A:garamond major: Increment the major version
  • clojure -A:garamond minor --tag: Increment the minor version and create a new tag
  • clojure -A:garamond --pom: Run clojure -Spom and modify the generated pom file to reflect the current version number along with the group-id and artifact-id given.
  • clojure -A:garamond patch --tag --pom: Increment the patch level of the version tag, generate a new pom.xml with the new version, and create a git tag based on that commit.

Versioning rules

garabond uses zafarkhaja/jsemver under the hood to handle manipulating version numbers, and its public interface mostly just delegates to methods there.

Accordingly, you can use clojure -A:garamond major to bump the major version number, patch to increment the patchlevel, and minor to update the minor version level.

garabond does have some commands which operate somewhat differently from the jsemver defaults, centered around "release candidate" versions:

clojure -A:garamond increment major-rc

Create a "release candidate". If the current version does not have an -rc.x suffix, bump the major version and add a new -rc.0 suffix. If it already has a suffix, increment the rc number. So v1.2.3 would become v2.0.0-rc.0, and v3.0.0-rc.2 would become v3.0.0-rc.3.

clojure -A:garamond increment minor-rc

This is similar to the above, but if an rc suffix does not exist, the minor number is incremented instead of the major one, so v2.4.7 becomes v2.5.0-rc.0 and v2.8.0-rc.1 becomes v2.8.0-rc.2.

clojure -A:garamond increment major-release

This performs a release, which will either remove the -rc.x suffix from a version if it has one, or increment the major version if it does not: v3.1.2 becomes v4.0.0 and v5.0.0-rc.3 becomes v5.0.0.

clojure -A:garamond increment minor-release

This does the same thing as major-release, but affects the minor version: v2.3.7 becomes v2.4.0 and v5.6.0-rc.0 becomes v5.6.0.

pom.xml modification

Running clojure -A:garamond --pom will invoke tools.deps to generate a pom.xml file, as in clojure -Spom. It will then post-process the generated file to make some modifications:

  • The <groupId> and <artifactId> tags are updated with values from command-line arguments
  • The <version> tag is modified with the current version. If you asked garamond to increment the version, the new version will be used; if you manually specified a version on the command line via --force-version v2.3.4, that value will be used.
  • An <scm> tag will be created, if it doesn't exist; if it does exist its values will be updated.

The <scm> tag is created largely so clojars and cljdoc can link back to your project's home page (see here). garamond uses the current git SHA as the <tag> value and the value of git remote show origin as the <connection>. You need to specify the <url> tag on the command-line as --scm-url.

Like clojure -Spom, garamond will leave the bits of your pom.xml which it isn't modifying alone.

Note: garamond currently generates pom.xml files using only the project-level deps.edn file. It should probably also include the system-level one, eg /usr/local/lib/clojure/dep.edn or what have you. This is planned as a future enhancement.

Deploying tools.deps library jars to clojars

It is possible to deploy jars to clojars using a combination of garamond to manage versions and update the pom file, Juxt's pack project to package the jar, and deps-deploy to handle actually pushing the jar to clojars. garamond itself is deployed this way; see its .circleci/config.yml and deps.edn files for details.

Background and rationale

The basic goal of this project is to automate all the pre-pack/pack.alpha stuff in this article about deploying library jars with deps, and to make it possible to do so without needing to check in partly machine-generated artifacts (eg, pom.xml) into the git repository itself.

Secondarily it aims to serve as an analogue to lein-v in the tools.deps universe.

Similar projects

The lein-v and lein-git-version projects do some similar stuff in a leiningen context.

About the name

Garamond is the name of a publishing company in Umberto Eco's 1988 novel Foucault's Pendulum, and is only tangentially related the typeface of the same name.

TODO

  • Load in system deps.edn when generating pom.xml
  • Properly handle cases where there are no tags in the repo
  • Support tag signing
  • Tests for the pom generation stuff
  • Maybe? support generated version.edn / version.clj file as lein-v

garamond's People

Contributors

imrekoszo avatar jjfine avatar timgilbert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

garamond's Issues

Request: new release

Do you have plans to release a recent revision of garamond on Clojars? I'm having a problem that I believe could be fixed if garamond used a more recent version of tools.deps.alpha. You already committed the necessary bump to tools.deps.alpha, so I think all I'd need is a release of the current version of the code.

Thanks for your work on this surprisingly challenging part of a library author's life!

garamond does not process system-installed deps.edn

Right now the --pom deps are generated just based on the current project's pom.xml, and not /usr/local/lib/clojure/deps.edn. This is probably incorrect and will probably not include the clojure dependency itself. We can probably use clojure.tools.deps.alpha.reader/clojure-env to get the proper location, although the extra JVM invocation stings.

Tag created despite message that it won't be created

ERROR [garamond/main.clj:97] Current repository is dirty, will not create a tag. Please commit your changes and retry.
Created new git tag v0.1.1 from patch increment of v0.1.0

Got this when running the following in the cljdoc repo:

clj -Sdeps '{:dept {garamond {:mvn/version "RELEASE"}}}' -m garamond.main --artifact-id cljdoc --group-id cljdoc --scm-url "https://github.com/cljdoc/cljdoc" --tag patch

At that time the repository had some changes to tracked files (i.e. it was dirty).

tools.deps api changese

Just wanted to drop a note that the newest version of tools.deps.alpha contains some api changes (moving towards getting out of alpha). So when you bump to tools.deps.alpha >= 0.9.745, you'll need to change your use of clojure.tools.deps.alpha.reader/slurp-deps - that is now in clojure.tools.deps.alpha.

Supply version as CLI arg

Hey @timgilbert, thanks for your work on Garamond!

I have two small questions/comments:

While it's nice to have the major, minor, patch semantics built in I was wondering if it would also be possible to specify the version string as a command line argument? I'd particularly like a versioning scheme that is like 0.0.123 where 123 is the number of commits in the current branch.

Note that garamond works on git tags; before you run it you should ensure you have at least one "annotated" git tag in your repo. You can create one via git tag --annotate -m "First version tag" v0.1.0.

There's this section in the README and I think it might be a little easy to miss for someone just skimming/looking at code. Maybe consider adding an emoji or boldening some of that to make it stand out more.

Resource paths being skipped

With a :paths key like this I'm getting a message that most paths will be skipped:

 :paths ["src" "resources" "resources-compiled"
         "modules/shared-utils/src"
         "modules/shared-utils/resources"]
Skipping paths: resources resources-compiled modules/shared-utils/src modules/shared-utils/resources

resulting in the following pom.xml section:

  <build>
    <sourceDirectory>src</sourceDirectory>
  </build>

I think this message originates from clj -Spom but I also never understood why it would purposefully override what a user specified in the configuration and hoped that Garamond would handle this, i.e. ensure that all :paths are included in the POM.

๐ŸŒฑ It seems that this is mostly irrelevant when building a jar using pack.alpha or similar but it's still fairly confusing, especially if people aren't too familiar with Maven stuff.

Fails on version 0.0

19-10-24 16:56:35 bianca2 ERROR [garamond.version:13] - Can't parse version string from '0.0': nil

I'm guessing it's because I don't have a patch segment, but I don't really want/need one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.