Skip to content

Commit

Permalink
Merge pull request #1495 from bcgov/automate-make-release-target
Browse files Browse the repository at this point in the history
Automate make release target
  • Loading branch information
Sepehr-Sobhani authored Apr 26, 2024
2 parents cff8224 + 4c8e1b2 commit 889f674
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ help: ## Show this help.
.PHONY: release
release: ## Tag a release using release-it
release:
@yarn
@yarn release-it
## grab the release version from release-it, and pass it to the create_empty_migrations script
@RELEASE_VERSION=$$(yarn release-it --release-version | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+' | tr '.' '_'); \
echo "Navigating to bc_obps directory..."; \
cd bc_obps && poetry run python manage.py create_empty_migrations $$RELEASE_VERSION && cd ..; \
echo "Running yarn setup and release-it..."; \
yarn; \
yarn release-it

.PHONY: lint_chart
lint_chart: ## Checks the configured helm chart template definitions against the remote schema
Expand Down
23 changes: 23 additions & 0 deletions bc_obps/common/management/commands/create_empty_migrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.core.management.base import BaseCommand, CommandError
from django.core.management import call_command


class Command(BaseCommand):
help = 'Creates an empty migration file for each installed app.'

def add_arguments(self, parser):
parser.add_argument('migration_name', type=str, help='Name of the migration.')

def handle(self, *args, **options):
migration_name = options['migration_name']
if not migration_name:
raise CommandError("Migration name is required.")

# We need to add other apps here if we want to create empty migrations for them(like when they are in PROD)
for app_label in ['common', 'registration']:
try:
# This command creates an empty migration with the specified name
call_command('makemigrations', app_label, empty=True, name=f'V{migration_name}')
self.stdout.write(self.style.SUCCESS(f'Successfully created migration for {app_label}'))
except Exception as e:
self.stdout.write(self.style.ERROR(f'Failed to create migration for {app_label}: {str(e)}'))
10 changes: 6 additions & 4 deletions docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ To make this process easy, we use [`release-it`](https://github.com/release-it/r
When you're ready to make a release, apply the following steps:

1. create a `chore/release` branch
2. create a blank django migration with the release version with this command: `python manage.py makemigrations registration --name V<major>_<minor>_<patch> --empty`
3. run `make release` and follow the prompts
4. create a pull request
5. once the pull request is approved and merged, and all required checks on the merge commit have passed, update your local develop branch and fast-forward the `main` branch using:
2. run `make release` and follow the prompts - This will:
- Create empty migration files for each django app based on the release version
- bump the version number
- generate a change log
3. create a pull request
4. once the pull request is approved and merged, and all required checks on the merge commit have passed, update your local develop branch and fast-forward the `main` branch using:

```bash
- git checkout main
Expand Down

0 comments on commit 889f674

Please sign in to comment.