diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0ef32fb0..a2829561 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,9 @@ jobs: publish: permissions: id-token: write - contents: write # For uploading to the release assets + # Give the default GITHUB_TOKEN write permission to commit and push the changed files to the repository. + # Also required for uploading files to the Release assets + contents: write runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -42,6 +44,24 @@ jobs: # - name: Update the authorization requests to "https://pub.dev" to use the environment variable "PUB_TOKEN". # run: dart pub token add https://pub.dev --env-var PUB_TOKEN + # TODO: We might automate updating the CHANGELOG.md for all the packages too (update Development notes too if you did) + # Before publishing the new packages, update the version for all the packages first + + # Extract version from the tag (handles optional 'v' prefix) + - name: Extract version + id: extract_version + run: | + version=$(echo ${GITHUB_REF} | sed 's/^refs\/tags\/\(.*\)$/\1/') + echo ::set-output name=VERSION::${version} + + - name: Update the version & CHANGELOG for all the packages + run: ./scripts/regenerate_versions.dart ${{ steps.extract_version.outputs.VERSION }} + + - name: Commit the changes of the updated version & CHANGELOG for all the packages + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "chore(version): update to version ${{ steps.extract_version.outputs.VERSION }}" + - name: Publish flutter_quill run: flutter pub publish --force diff --git a/doc/development_notes.md b/doc/development_notes.md index 23d60db8..4e9d649f 100644 --- a/doc/development_notes.md +++ b/doc/development_notes.md @@ -1,9 +1,8 @@ # Development notes - When updating the translations or localizations in the app, please take a look at the [Translation](./translation.md) page as it has important notes in order to work, if you also add a feature that adds new localizations then you need to the instructions of it in order for the translations to take effect -- Only update the `version.dart` and `CHANGELOG.md` at the root folder of the repo, then run the script: +- We use the same package version and `CHANGELOG.md` for all the packages, for more [details](https://github.com/singerdmx/flutter-quill/pull/1878), the process is automated. We have a script that will do the followings: + 1. Copy the contents of the root `CHANGELOG.md` file into all the `CHANGELOG.md` of the packages (overwrite), you need to mention the changes of all the packages in the `CHANGELOG.md` of the root folder as it will be copied, we still have to mention the new changes in the `CHANGELOG.md` and update it as it's not automated yet. + 2. The script require the new version as an argument, you don't need to run the script manually, when a maintainer create a new tag and publish a new GitHub release, the publish workflow will extract the new version from the tag name, run the script (pass the extracted version as an argument), commit the changes and push them into the repository, the script will update the `version` property for all the packages so the `flutter pub publish` will use the new version for each package correctly. - ```console - dart ./scripts/regenerate_versions.dart - ``` - You must mention the changes of the other packages in the repo in the root `CHANGELOG.md` only and the script will replace the `CHANGELOG.md` in the other packages with the root one, and change the version in `pubspec.yaml` with the one in `version.dart` in the root folder \ No newline at end of file + the script will be used the CI and no need to run it manually \ No newline at end of file diff --git a/scripts/regenerate_versions.dart b/scripts/regenerate_versions.dart index 8b06a832..357914f4 100644 --- a/scripts/regenerate_versions.dart +++ b/scripts/regenerate_versions.dart @@ -1,18 +1,12 @@ // ignore_for_file: avoid_print -import 'dart:io' show File; +import 'dart:io' show File, exit; import 'package:yaml_edit/yaml_edit.dart'; -import '../version.dart'; - /// The list of the packages that which will be used to update the `CHANGELOG.md` -/// and the `README.md`, always make `'./'` at the top -/// -/// since we should not update the `CHANGELOG.md` of -/// the `flutter_quill` since it used -/// in all the packages -final packages = [ +/// and `README.md` files for all the packages +final _packages = [ './', './dart_quill_delta', './flutter_quill_extensions', @@ -21,36 +15,51 @@ final packages = [ './quill_pdf_converter', ]; -/// A script that should run in the root folder of the repo and not inside -/// the scripts folder +/// A script that should run in the root folder and not inside any other folder +/// it has one task, which update the version for `pubspec.yaml` and `CHANGELOG.md` for all the packages +/// since we have only one CHANGELOG.md file and version, previously we had different `CHANGELOG.md` and `pubspec.yaml` package version +/// for each package /// -/// it will update the versions and changelogs, the versions will be all the same -/// from the `version.dart` and the changelogs will be use the same one from the -/// root folder of `flutter_quill` +/// the new version should be passed in the [args], the script accept only one argument Future main(List args) async { - for (final packagePath in packages) { - await updatePubspecYamlFile('$packagePath/pubspec.yaml'); - if (packagePath != packages.first) { + if (args.isEmpty) { + print('Missing required version argument. Usage: ./script '); + exit(1); + } + if (args.length > 1) { + print('Too many arguments. Usage: ./script '); + exit(1); + } + final newVersion = args[0]; + if (newVersion.isEmpty) { + print('The new version is empty. Usage: ./script '); + exit(1); + } + for (final packagePath in _packages) { + await updatePubspecYamlFile('$packagePath/pubspec.yaml', + newVersion: newVersion); + if (packagePath != _packages.first) { updateChangelogMD('$packagePath/CHANGELOG.md'); } } } -/// Read the `version` variable from `version.dart` -/// and update the package version -/// in `pubspec.yaml` from the [pubspecYamlPath] -Future updatePubspecYamlFile(String pubspecYamlPath) async { +/// Update the [pubspecYamlPath] file to update the `version` property from [newVersion] +Future updatePubspecYamlFile( + String pubspecYamlPath, { + required String newVersion, +}) async { final file = File(pubspecYamlPath); final yaml = await file.readAsString(); - final yamlEditor = YamlEditor(yaml)..update(['version'], version); + final yamlEditor = YamlEditor(yaml)..update(['version'], newVersion); await file.writeAsString(yamlEditor.toString()); print(yamlEditor.toString()); } -/// Copy the text from the root `CHANGELOG.md` and paste it to the one -/// from the [changeLogPath] -Future updateChangelogMD(String changeLogPath) async { - final changeLog = await File('./CHANGELOG.md').readAsString(); - final currentFile = File(changeLogPath); - await currentFile.writeAsString(changeLog); +/// Read the contents of the root `CHANGELOG.md` file and copy it +/// to the [changeLogFilePath] +Future updateChangelogMD(String changeLogFilePath) async { + final rootChangeLogFileContent = await File('./CHANGELOG.md').readAsString(); + final changeLogFile = File(changeLogFilePath); + await changeLogFile.writeAsString(rootChangeLogFileContent); } diff --git a/version.dart b/version.dart deleted file mode 100644 index 97dc4203..00000000 --- a/version.dart +++ /dev/null @@ -1 +0,0 @@ -const version = '9.3.13';