deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Detect old .dep/releases file to find out next release (and delete old file)

Open jamieburchell opened this issue 3 years ago • 5 comments

Just a suggestion for a smoother upgrade path - why not detect the presence of an already existing .dep/releases file to determine the last release number from v6.x and then clean up afterwards by deleting it?

I'm assuming the .dep/releases file is safe to remove after upgrading to v7?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

jamieburchell avatar Jan 26 '22 18:01 jamieburchell

It's possible to write such migration code, but instead, I wrote migration documentation. Why? Because it's easier. =)

I work on Deployer only on my spare time, and only because of my supporters on https://github.com/sponsors/antonmedv, so...

I have a big backlog of other important stuff to do too, like finally releasing v7. If you would like to write such code yourself? +tests of cause, it pretty complex actually. Might be lots of hidden underwater rocks.

antonmedv avatar Jan 26 '22 21:01 antonmedv

Completely understand, it was just a feature suggestion. I love Deployer by the way.

jamieburchell avatar Jan 26 '22 21:01 jamieburchell

I have created simple task for this, without tests, so use it with caution.

<?php declare(strict_types = 1);

namespace Deployer;

task('deploy:custom:deployer-migration', function (): void {
	$v6FileExists = test('[ -f {{deploy_path}}/.dep/releases ]');
	$v7FileExists = test('[ -f {{deploy_path}}/.dep/latest_release ]');

	if ($v6FileExists && !$v7FileExists) {
		$releasesLastRow = run('tail -n 1 {{deploy_path}}/.dep/releases');

		[, $lastReleaseNumber] = explode(',', $releasesLastRow);

		run(sprintf('echo %s > {{deploy_path}}/.dep/latest_release', $lastReleaseNumber));
		run(sprintf('rm -f {{deploy_path}}/.dep/releases'));

		writeln(sprintf('Migrated deployer v6.x releases file to v7.x latest_release file.'));
	}
});

roman-vohnik avatar Apr 13 '22 09:04 roman-vohnik

And need to create .dep/releases_log with at least one row to have correctly set up previous_release in recipe/deploy/release.php

sanasport-it avatar Apr 14 '22 06:04 sanasport-it

I created a small PHP script to convert the release files: https://gist.github.com/retiolum/1fa9a7511bc5095b33dc8c09224306a9

ntzrbtr avatar Dec 15 '22 10:12 ntzrbtr