Skip to content

Commit 7341024

Browse files
committed
support timezone in manifest and use when validating app-version
1 parent 69d0a49 commit 7341024

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ Builds can be deployed with `yolo deploy <environment>`.
208208

209209
This is a complete yolo.yml manifest file, showing default values where applicable.
210210

211-
Note that some keys are intentionally omitted from the stub generated by `yolo init`.
211+
Note that some keys below are intentionally omitted from the stub generated by `yolo init`.
212212

213213
```yaml
214214
name: codinglabs
215+
timezone: UTC
215216

216217
environments:
217218
production:
@@ -277,6 +278,31 @@ environments:
277278
- php artisan optimize
278279
```
279280
281+
### Continuous Integration
282+
283+
The app version can be specified as an option with `--app-version` to the `build` and `deploy` commands.
284+
285+
The recommended approach is to tag your GitHub releases with a date-based naming convention, and then forward the tag to
286+
your deploy action, similar to the following:
287+
288+
```yaml
289+
- name: Deploy
290+
run: php vendor/bin/yolo deploy production --app-version=${{ github.event.release.tag_name }}
291+
env:
292+
AWS_ACCESS_KEY_ID: ${{ secrets.PRODUCTION_AWS_ACCESS_KEY_ID }}
293+
AWS_SECRET_ACCESS_KEY: ${{ secrets.PRODUCTION_AWS_SECRET_ACCESS_KEY }}
294+
```
295+
296+
The current app version must start with `year.week`, for example `25.3` to represent the third week of 2025. After the
297+
year and week,
298+
use whatever convention you like; a common approach is to increment the third digit for each release, for example
299+
`25.3.1`,
300+
`25.3.2`, etc.
301+
302+
Because the app version is validated during the build and utilises the UTC timezone by default, you may wish to set the
303+
manifest `timezone` option to the timezone of your team to prevent validation errors at the start of the week if your
304+
timezone is ahead of UTC.
305+
280306
### Domains
281307

282308
Applications hosted with yolo can be served on any domain or subdomain that you own.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"illuminate/filesystem": "^10|^11|^12",
1919
"illuminate/support": "^10|^11|^12",
2020
"joetannenbaum/chewie": "^0.1.8",
21+
"nesbot/carbon": "^3.10",
2122
"symfony/console": "^7.1",
2223
"symfony/yaml": "^7.1",
2324
"vlucas/phpdotenv": "^5.6"

src/Commands/BuildCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Codinglabs\Yolo\Commands;
44

5+
use Carbon\Carbon;
56
use Codinglabs\Yolo\Steps;
7+
use Codinglabs\Yolo\Manifest;
68
use Symfony\Component\Console\Input\InputArgument;
79

810
use function Laravel\Prompts\error;
@@ -32,10 +34,11 @@ protected function configure(): void
3234

3335
public function handle(): void
3436
{
35-
$appVersion = $this->option('app-version') ?? date('y.W.N.Hi');
37+
$appVersion = $this->option('app-version') ?? Carbon::now(Manifest::timezone())->format('y.W.N.Hi');
38+
$expectedAppVersionPrefix = Carbon::now(Manifest::timezone())->format('y.W');
3639

37-
if (! str_starts_with($appVersion, date('y.W'))) {
38-
error(sprintf('App version must start with %s', date('y.W')));
40+
if (! str_starts_with($appVersion, $expectedAppVersionPrefix)) {
41+
error(sprintf('App version must start with %s', $expectedAppVersionPrefix));
3942

4043
return;
4144
}

src/Manifest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public static function put(string $key, mixed $value): false|int
6868
);
6969
}
7070

71+
public static function timezone(): string
72+
{
73+
return Arr::get(static::current(), 'timezone', 'UTC');
74+
}
75+
7176
public static function apex(): string
7277
{
7378
if (static::isMultitenanted()) {

src/Steps/Image/CreateAmiStep.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Codinglabs\Yolo\Steps\Image;
44

5+
use Carbon\Carbon;
56
use Codinglabs\Yolo\Aws;
67
use Codinglabs\Yolo\Helpers;
8+
use Codinglabs\Yolo\Manifest;
79
use Codinglabs\Yolo\Contracts\Step;
810
use Codinglabs\Yolo\Concerns\UsesEc2;
911

@@ -15,7 +17,7 @@ public function __invoke(): string
1517
{
1618
$ami = Aws::ec2()->createImage([
1719
'InstanceId' => Helpers::app('amiInstanceId'),
18-
'Name' => Helpers::keyedResourceName(date('y.W.N.Hi'), exclusive: false),
20+
'Name' => Helpers::keyedResourceName(Carbon::now(Manifest::timezone())->format('y.W.N.Hi'), exclusive: false),
1921
'TagSpecifications' => [
2022
[
2123
'ResourceType' => 'image',

0 commit comments

Comments
 (0)