0

OK, a question that seems to be harder (for me) then it appears at first. I develop sites with the symphony framework. But some of the sites are put on servers to which I have no direct access. So, in order to keep track if the latest version is put, I have added a value in the HTML header of the login page. Now I always manually update this value (in the TWIG). And now the question I'm struggling with:

Is it possible to "automate" that the latest value of the GIT commit is added automatically (and transparently, so meaning no effort is required)?
I've been thinking of adding a value to the .env file and trying to get this populated with the correct value, but to be honest I'm a bit struggling to see how I can make this work....

If there are other suggestions to keep a decent version tracking which is relatively transparent for the actual users of the site, then that is of course also welcome...

DarkBee
  • 16,592
  • 6
  • 46
  • 58
BertDB
  • 41
  • 7
  • Do you use GitHub Actions for pushing updates to these servers? If so you could automate the value via that, if not then manually will be the only way, afaik. – Bossman Dec 13 '22 at 11:13
  • No, unfortunately not. I just use it for the version history and the changes. I compile the "symfony" packages and then send them to the user-representative that extract these to a server with no internet connectivity (it's a company internal solution)... – BertDB Dec 13 '22 at 11:24
  • The only other way i can think of is to create a script that runs when you commit and increment a counter. [This](https://stackoverflow.com/questions/3442874/in-git-how-can-i-write-the-current-commit-hash-to-a-file-in-the-same-commit) might help and give you some ideas to add the version. Basically, on commit it could update a file in your project and then your twig template can always just read this file.. – Bossman Dec 13 '22 at 11:33
  • Do you mean the Symfony version? Or the Git commit hash? The Symfony version is available as `Symfony\Component\HttpKernel\Kernel::VERSION` but your own Kernel extends that so you can use `App\Kernel::VERSION` – craigh Dec 13 '22 at 12:56
  • The symfony version is rather static, so I mean either the GIT commit hash or the date I create the build or... Well anything that allows my to see weather or not the latest version was put, preferably without me having to do extra steps since I consistently forget to update the "manual" timestamp which is in it now... – BertDB Dec 13 '22 at 13:05

1 Answers1

0

You can think about and select from at least 2 strategies

Clean and smudge filters

In-file replacement, as it (done|expect to be) now

As explained in Keyword Expansion chapter in GitBook

In the .gitattributes file, you can set a filter for particular paths and then set up scripts that will process files just before they’re checked out and just before they’re staged

I.e have some "magic-string" expanding into anything you want to have in WorkTree and collapsed into original form before placing back into repo, thus - don't appear as content-changes in git's history

Also, for anything you want to have, output of git describe (or any other inique-id generator) may be good candidate, you have to have only at least one tag in repo

Export-subst

External file, appearing on git archive operation in an archive-target automagically with any custom content inside. Can be included into any twig-template or page

No script-coding for smudge|clean filters, only file(s) with git log’s formatting and keyword-expansion processing

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • I will look into the Export-subst solution further. According to what I've read this will indeed do the job. Thank you, Lazy Badger ! – BertDB Dec 17 '22 at 06:32