2

Recently we moved our Db models (Sequelize) to a sperate repository, and we publish it using Github packages.

When we moved it to a sperate repository we found that we need to install different versions based on the environment (production/staging/develop)
eg:

  • Production version requires v1.2,
  • staging requires v1.3, etc.

Since we would like to avoid manually going into each dependent service and update the required version, we wanted to manage that using the dist-tags.

For we'd have package.json pull package version tagged as "staging" and "production" according to the environment and we want to release a new version we would tag 1.3 for example as "production".

Unfortunately, dist-tags don't seem to be supported on the GitHub registry so we are looking for other approaches.

Any suggestions?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
ShaharMynd
  • 31
  • 2

1 Answers1

0

If possible (meaning if there are no sensitive infomation, especially for production parameters), you would version three separate files:

  • package.json.dev
  • package.json.stg
  • package.json.prd

The idea would then be to not version package.json (keep it private), but to generate it (with the right value in it), from one of those files, depending on the current execution environment.

For example, you could have separate branches per environment, with the right file in it.
The generation script will determine the name of the checked out branch with:

branch=$(git rev-parse --symbolic --abbrev-ref HEAD)

That means you could:

  • version only a template file package.json.tpl
  • version value files named after the branches: package.json.dev, package.json.stg: since they are different, there is no merge issue when merging or switching branches.

Finally, you would register (in a .gitattributes declaration) a content filter driver.

smudge (image from "Customizing Git - Git Attributes", from "Pro Git book")

The smudge script, associated to the template file (package.json.tpl), would generate (automatically, on git checkout) the actual package.json file by looking values in the right version.<branch> value file.
The generated actual package.json file remains ignored (by the .gitignore).

See a complete example at "git smudge/clean filter between branches".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250