Skip to content

Commit

Permalink
feat(aft): Version bump command (#2068)
Browse files Browse the repository at this point in the history
* chore(aft): Make base commands sync

There isn't any value with these being async since it's okay to block in this context. And sync makes everything easier to work with.

commit-id:6743d9d4

* feat(aft): Changelog/version commands

commit-id:0c17379d

* fix(aws_common): Logger initialization

Fixes an issue in logger initialization where the initial plugin is not registered to the root plugin.

commit-id:063fbfe0

* fix(aft): Versioning algorithm and performance

commit-id:c45852ad

* chore(aft): Clean up

commit-id:de10a06e

* chore(aft): Update README

commit-id:8261f867

* chore(aft): Update tests

Expand e2e tests to incude changelog/pubspec changes

commit-id:e9757240

* chore(aft): Update dependencies

commit-id:4509edf2

* chore(aft): Bump dependencies

commit-id:14f44d17

* chore(aft): Enforce changelog update includes commits

Changelog updates should only be made with a non-empty list of commits.

commit-id:4eccafce

* chore(aft): Add `promptYesNo` helper

commit-id:8544885f

* chore(aft): Refine `isExample`

Refine the definition of `isExample` to be more precise and not require workarounds.

commit-id:51cc0ac0

* chore(aft): Change `aft version` to `aft version-bump`

commit-id:0526b477

* chore(aft): Remove from mono_repo

The package libgit2dart, while it can be used in Dart-only packages tricks pub into thinking it has a dependency on Flutter. mono_repo cannot handle this discrepancy.

commit-id:ec27a8d2

* fix(aft): Publish constraints

Fixes constraints around publishing checks and which packages to consider for publishing.

commit-id:937ee042

* chore(aft): Publish command checks

Improves publish command checks by removing `pubspec_overrides` and not splitting the pre-publish and publish commands for a package.

* chore(aft): Add components and define version bump types

* chore(aft): Clean up `deps` command

Fix logging and merge `pub.dev` logic with `publish`

* chore(aft): Add placeholders for version bump commit

* chore(aft): Update logging settings

* test(aft): Update e2e tests

* More updates

* chore(aft): More cleanup

* chore(aft): Add propagation option

* chore(aft): Remove `changelog` command

* chore(aft): Clean up

* chore(aft): Update wording in `aft.yaml`

* chore(aft): Link packages before version bump

* chore(aft): Follow Dart SemVer strategy

Use build tag (`+`) for patch releases.

* chore(aft): Fix analysis errors

* fix(aft): Submodule `libgit2dart`

Adds workaround for dart-lang/pub#3563 which requires using Flutter's `dart` command if a package lists a Flutter SDK constraint even if the package does not depend on Flutter.

* fix(authenticator): ARB syntax

Remove unncessary commas

* chore(aft): Remove setup step

* chore(aft): Copy libgit2 from

Instead of trying to install it (since the latest version is not available in apt)

* chore(aft): Reset after patch

* chore(aft): Copy lib to /usr

* fix(aft): `dev_dependency` conflicts

When `dev_dependencies` contains versions of the published packages different than those on pub.dev (for example when using path deps or `any`), this causes issues during pre-publish verification.

By simply keeping these constraints up-to-date as well, we lose nothing (since they are overridden in local development via linking), but gain stronger confidence in the pre-publish step.

* chore(aft): Change workflow path for libgit2

* chore(aft): Fix tests in CI

* chore(aft): Bump dependency

Co-authored-by: Dillon Nys <dillon.andre.nys@gmail.com>
  • Loading branch information
dnys1 and dnys1 authored Jan 10, 2023
1 parent db69cce commit 29c785d
Show file tree
Hide file tree
Showing 50 changed files with 3,343 additions and 303 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ commands:
- run:
name: Install and set up aft
command: |
git submodule update --init
flutter pub global activate -spath packages/aft
aft bootstrap
activate_pana:
Expand Down
49 changes: 33 additions & 16 deletions .github/workflows/aft.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# Generated with aft. To update, run: `aft generate workflows`
name: aft
on:
push:
branches:
- main
- stable
- next
paths:
- 'packages/aft/**/*.dart'
pull_request:
paths:
- 'packages/aft/**/*.dart'
- 'packages/aft/**/*.yaml'
- 'packages/aft/lib/**/*'
- 'packages/aft/test/**/*'
- '.github/workflows/dart_vm.yaml'
- '.github/workflows/dart_native.yaml'
- '.github/workflows/aft.yaml'
schedule:
- cron: "0 0 * * 0" # Every Sunday at 00:00
defaults:
Expand All @@ -24,12 +19,34 @@ permissions: read-all

jobs:
test:
uses: ./.github/workflows/dart_vm.yaml
with:
working-directory: packages/aft
native_test:
if: ${{ github.event_name == 'push' }}
needs: test
uses: ./.github/workflows/dart_native.yaml
with:
working-directory: packages/aft
name: Test
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # 3.1.0
with:
submodules: true

# Needed for `git` but only ever used locally.
- name: Git Config
run: |
git config --global user.email "amplify-flutter@amazon.com"
git config --global user.name "Amplify Flutter"
- name: Setup Dart
uses: dart-lang/setup-dart@196f54580e9eee2797c57e85e289339f85e6779d # main
with:
sdk: stable

- name: Get Packages
working-directory: packages/aft
run: |
# Patch libgit2dart (see https://github.com/dart-lang/pub/issues/3563)
( cd external/libgit2dart; git apply ../libgit2dart.patch )
dart pub upgrade
mkdir linux
cp external/libgit2dart/linux/*.so linux
- name: Run Tests
working-directory: packages/aft
run: dart test
6 changes: 5 additions & 1 deletion .github/workflows/dart_dart2js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ jobs:
sdk: ${{ matrix.sdk }}

- name: Setup aft
run: dart pub global activate -spath packages/aft
run: |
# Patch libgit2dart (see https://github.com/dart-lang/pub/issues/3563)
( cd packages/aft/external/libgit2dart; git apply ../libgit2dart.patch )
dart pub global activate -spath packages/aft
( cd packages/aft/external/libgit2dart; git reset --hard HEAD )
- name: Setup Firefox
if: ${{ matrix.browser == 'firefox' }}
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/dart_ddc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ jobs:
sdk: ${{ matrix.sdk }}

- name: Setup aft
run: dart pub global activate -spath packages/aft
run: |
# Patch libgit2dart (see https://github.com/dart-lang/pub/issues/3563)
( cd packages/aft/external/libgit2dart; git apply ../libgit2dart.patch )
dart pub global activate -spath packages/aft
( cd packages/aft/external/libgit2dart; git reset --hard HEAD )
- name: Setup Firefox
if: ${{ matrix.browser == 'firefox' }}
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/dart_native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ jobs:
sdk: stable

- name: Setup aft
run: dart pub global activate -spath packages/aft
run: |
# Patch libgit2dart (see https://github.com/dart-lang/pub/issues/3563)
( cd packages/aft/external/libgit2dart; git apply ../libgit2dart.patch )
dart pub global activate -spath packages/aft
( cd packages/aft/external/libgit2dart; git reset --hard HEAD )
- name: Bootstrap
id: bootstrap
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/dart_vm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ jobs:
sdk: ${{ matrix.sdk }}

- name: Setup aft
run: dart pub global activate -spath packages/aft
run: |
# Patch libgit2dart (see https://github.com/dart-lang/pub/issues/3563)
( cd packages/aft/external/libgit2dart; git apply ../libgit2dart.patch )
dart pub global activate -spath packages/aft
( cd packages/aft/external/libgit2dart; git reset --hard HEAD )
- name: Bootstrap
id: bootstrap
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/flutter_vm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Git Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # 3.1.0

- name: Git Submodules
run: git submodule update --init

- name: Setup Flutter
uses: subosito/flutter-action@dbf1fa04f4d2e52c33185153d06cdb5443aa189d # 2.8.0
with:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/smoke_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791 # v2.5.0
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # 3.1.0

- name: Git Submodules
run: git submodule update --init

- name: Setup Dart
uses: dart-lang/setup-dart@196f54580e9eee2797c57e85e289339f85e6779d # main
Expand All @@ -34,6 +37,8 @@ jobs:

- name: Link Packages
run: |
# Patch libgit2dart (see https://github.com/dart-lang/pub/issues/3563)
( cd packages/aft/external/libgit2dart; git apply ../libgit2dart.patch )
dart pub global activate -spath packages/aft
aft link
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
path = packages/smithy/goldens/smithy
url = https://github.com/awslabs/smithy.git
branch = main
[submodule "packages/aft/external/libgit2dart"]
path = packages/aft/external/libgit2dart
url = https://github.com/SkinnyMind/libgit2dart.git
47 changes: 46 additions & 1 deletion aft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,51 @@ dependencies:
uuid: ">=3.0.6 <=3.0.7"
xml: ">=6.1.0 <=6.2.2"

# Packages to ignore in all repo operations
# Packages to ignore in all repo operations.
ignore:
- synthetic_package
- libgit2dart

# Strongly connected components which should have version bumps happen
# in unison, i.e. a version bump to one package cascades to all.
#
# By default, this happens only for minor version bumps. However, this
# can be modified on a per-component basis using the `propagate` flag.
components:
- name: Amplify Flutter
summary: amplify_flutter
packages:
- amplify_flutter
- amplify_flutter_ios
- amplify_flutter_android
- amplify_core
- amplify_datastore
- amplify_datastore_plugin_interface
- amplify_analytics_pinpoint
- amplify_api
- amplify_api_android
- amplify_api_ios
- amplify_auth_cognito
- amplify_auth_cognito_android
- amplify_auth_cognito_ios
- amplify_storage_s3
- name: Amplify Dart
summary: amplify_core
propagate: none
packages:
- amplify_auth_cognito_dart
- amplify_analytics_pinpoint_dart
- amplify_storage_s3_dart
- name: Amplify UI
packages:
- amplify_authenticator
- name: Smithy
summary: smithy
packages:
- smithy
- smithy_aws
- name: Worker Bee
summary: worker_bee
packages:
- worker_bee
- worker_bee_builder
21 changes: 21 additions & 0 deletions packages/aft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ A CLI tool for managing the Amplify Flutter repository.
- `get`: Runs `dart pub get`/`flutter pub get` for all packages
- `upgrade`: Runs `dart pub upgrade`/`flutter pub upgrade` for all packages
- `publish`: Runs `dart pub publish`/`flutter pub publish` for all packages which need publishing
- `version-bump`: Bumps version using git history

## Setup

To run some commands, `libgit2` is required and can be installed with the following commands:

```sh
$ brew install libgit2
```

```sh
$ sudo apt-get install libgit2-dev
```

To activate `aft`, run:

```sh
$ dart pub global activate -spath packages/aft
```

A full list of available commands and options can be found by running `aft --help`.
1 change: 1 addition & 0 deletions packages/aft/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ analyzer:
public_member_api_docs: ignore
exclude:
- '**/*.g.dart'
- external/
3 changes: 2 additions & 1 deletion packages/aft/bin/aft.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Future<void> main(List<String> args) async {
..addCommand(LinkCommand())
..addCommand(CleanCommand())
..addCommand(PubCommand())
..addCommand(BootstrapCommand());
..addCommand(BootstrapCommand())
..addCommand(VersionBumpCommand());
try {
await runner.run(args);
} on UsageException catch (e) {
Expand Down
36 changes: 36 additions & 0 deletions packages/aft/doc/versioning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Versioning Algorithm

The `aft version-bump` command uses Git history + [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) formatting to determine a suitable next version for a package along with the required changes for depending packages.

1. Let `packages` be the set of all packages in the repo which are publishable to `pub.dev`.
2. For every package `P` in `packages`:
1. Let `component` be the component of `P`, if any.
2. Let `baseRef` be the commit of the last release of `P`.
3. Let `headRef` be the releaseable commit of `P` (defaults to `HEAD`).
4. Let `history` be the list of git commits in the range `baseRef..headRef` which affected `P`, i.e. those commits which included changes to files in `P`.
5. Let `nextVersion = currentVersion`.
6. For each `commit` in `history`:
1. If `commit` is a version bump (i.e. `chore(version)`), ignore it.
2. If `commit` is a merge commit, update dependencies based on the packages changed by the commit.
1. The thinking here is that PRs should either be squashed into a single commit or merged as a set of independent commits capped off by a merge commit. The independent commits are isolated changes which are used to update changelogs and bump versions. The merge commit is then used solely for associating previous commits and updating constraints accordingly.
3. If `commit` is a breaking change (i.e. `feat(auth)!`), set `bumpType = breaking`.
1. else if `commit`'s type is `feat`, set `bumpType = nonBreaking`.
2. else, set `bumpType = patch`.
4. If `commit` is a noteworthy change (scope is one of `feat`, `fix`, `bug`, `perf`, or `revert` or it's a breaking change), set `includeInChangelog = true`.
5. Let `proposedVersion = currentVersion.bump(bumpType)`
6. Let `nextVersion = max(nextVersion, proposedVersion)`
7. If `nextVersion > currentVersion`:
1. Update `pubspec.yaml`, set `version = nextVersion`
2. If `includeInChangelog`:
1. Update `CHANGELOG.md` with an entry for `commit`.
3. If `bumpType == breaking`:
1. For every package `Q` which directly depends on `P`:
1. Bump the version of `Q` with `bumpType = patch` and `includeInChangelog = false`.
2. Update `Q`'s constraint on `P`.
4. If `bumpType == breaking` or `bumpType == nonBreaking` and `component != null`:
1. For every package `Q` in `component`:
1. Bump the version of `Q` with the same `bumpType` as `P` and `includeInChangelog = false`.
8. If `component` has a summary package:
1. Update `CHANGELOG.md` in the summary package with `commit`.
9. For every package `Q` which was affected by `commit`:
1. Update `Q`'s constraint on `P` using `nextVersion`.
1 change: 1 addition & 0 deletions packages/aft/external/libgit2dart
Submodule libgit2dart added at 34d492
29 changes: 29 additions & 0 deletions packages/aft/external/libgit2dart.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/pubspec.yaml b/pubspec.yaml
index 5acda72..2831e58 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -8,7 +8,6 @@ homepage: https://github.com/SkinnyMind/libgit2dart

environment:
sdk: ">=2.18.0 <3.0.0"
- flutter: ">=3.3.0"

dependencies:
args: ^2.3.0
@@ -23,16 +22,6 @@ dev_dependencies:
lints: ^2.0.0
test: ^1.20.0

-flutter:
- plugin:
- platforms:
- linux:
- pluginClass: Libgit2dartPlugin
- macos:
- pluginClass: Libgit2dartPlugin
- windows:
- pluginClass: Libgit2dartPlugin
-
ffigen:
output: "lib/src/bindings/libgit2_bindings.dart"
headers:
1 change: 1 addition & 0 deletions packages/aft/lib/aft.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export 'src/commands/link_command.dart';
export 'src/commands/list_packages_command.dart';
export 'src/commands/pub_command.dart';
export 'src/commands/publish_command.dart';
export 'src/commands/version_bump_command.dart';
export 'src/models.dart';
export 'src/pub/pub_runner.dart';
export 'src/util.dart';
Loading

0 comments on commit 29c785d

Please sign in to comment.