diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 0a20e47e..e74815fe 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.7 +# Created with package:mono_repo v6.6.0 name: Dart CI on: push: @@ -37,7 +37,7 @@ jobs: name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - name: mono_repo self validate - run: dart pub global activate mono_repo 6.5.7 + run: dart pub global activate mono_repo 6.6.0 - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: @@ -133,7 +133,7 @@ jobs: if: "always() && steps.chopper_pub_upgrade.conclusion == 'success'" working-directory: chopper - name: Upload coverage to codecov.io - uses: codecov/codecov-action@main + uses: codecov/codecov-action@v3 with: files: chopper/coverage/lcov.info fail_ci_if_error: true @@ -148,7 +148,7 @@ jobs: if: "always() && steps.chopper_built_value_pub_upgrade.conclusion == 'success'" working-directory: chopper_built_value - name: Upload coverage to codecov.io - uses: codecov/codecov-action@main + uses: codecov/codecov-action@v3 with: files: chopper_built_value/coverage/lcov.info fail_ci_if_error: true @@ -163,7 +163,7 @@ jobs: if: "always() && steps.chopper_generator_pub_upgrade.conclusion == 'success'" working-directory: chopper_generator - name: Upload coverage to codecov.io - uses: codecov/codecov-action@main + uses: codecov/codecov-action@v3 with: files: chopper_generator/coverage/lcov.info fail_ci_if_error: true diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 32ee9bc4..6a17c681 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,9 +33,10 @@ jobs: - run: git checkout HEAD^ - name: Load base version id: load_base_version + working-directory: ${{ matrix.package }} run: | set -e - echo "BASE_VERSION_${{ matrix.package }}=$(awk '/^version: / {print $2}' ${{ matrix.package }}/pubspec.yaml)" >> $GITHUB_OUTPUT + echo "BASE_VERSION_${{ matrix.package }}=$(yq -r '.version' pubspec.yaml)" >> $GITHUB_OUTPUT publish: name: "Publish" needs: get_base_version @@ -53,26 +54,26 @@ jobs: uses: actions/checkout@v3 - name: Load this version id: load_this_version + working-directory: ${{ matrix.package }} run: | set -e - echo "THIS_VERSION=$(awk '/^version: / {print $2}' ${{ matrix.package }}/pubspec.yaml)" >> $GITHUB_ENV + echo "THIS_VERSION=$(yq -r '.version' pubspec.yaml)" >> $GITHUB_ENV - name: Compare versions id: compare_versions env: BASE_VERSION_chopper: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper }} BASE_VERSION_chopper_generator: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper_generator }} BASE_VERSION_chopper_built_value: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper_built_value }} + working-directory: tool run: | set -e - pushd tool || exit dart pub get echo "IS_VERSION_GREATER=$(dart run compare_versions.dart $THIS_VERSION $BASE_VERSION_${{ matrix.package }})" >> $GITHUB_ENV - popd || exit - name: Validate pub.dev topics id: validate_pub_dev_topics + working-directory: ${{ matrix.package }} run: | set -e - pushd ${{ matrix.package }} || exit pattern="^[a-z][a-z0-9-]*[a-z0-9]$" for topic in $(yq -r '.topics[]' pubspec.yaml); do if [[ ! $topic =~ $pattern ]]; then @@ -80,7 +81,16 @@ jobs: exit 1 fi done - popd || exit + - name: Create release-specific CHANGELOG + id: create_changelog + if: ${{ env.IS_VERSION_GREATER == 1 }} + working-directory: ${{ matrix.package }} + run: | + set -e + CHANGELOG_PATH=$RUNNER_TEMP/CHANGELOG.md + awk '/^##[[:space:]].*/ { if (count == 1) exit; count++; print } count == 1 && !/^##[[:space:]].*/ { print }' CHANGELOG.md | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > $CHANGELOG_PATH + echo -en "\n[https://pub.dev/packages/${{ matrix.package }}/versions/$THIS_VERSION](https://pub.dev/packages/${{ matrix.package }}/versions/$THIS_VERSION)" >> $CHANGELOG_PATH + echo "CHANGELOG_PATH=$CHANGELOG_PATH" >> $GITHUB_ENV - name: Set up pub credentials id: credentials if: ${{ env.IS_VERSION_GREATER == 1 }} @@ -91,12 +101,19 @@ jobs: - name: Publish id: publish if: ${{ env.IS_VERSION_GREATER == 1 }} + working-directory: ${{ matrix.package }} run: | set -e - pushd ${{ matrix.package }} || exit yq -i 'del(.dependency_overrides)' pubspec.yaml dart pub publish --force - popd || exit + - name: Github release + id: github_release + if: ${{ env.IS_VERSION_GREATER == 1 }} + uses: softprops/action-gh-release@v1 + with: + name: ${{ format('{0}-v{1}', matrix.package, env.THIS_VERSION) }} + tag_name: ${{ format('{0}-v{1}', matrix.package, env.THIS_VERSION) }} + body_path: ${{ env.CHANGELOG_PATH }} - name: Skip publish id: skip_publish if: ${{ env.IS_VERSION_GREATER == 0 }} @@ -106,3 +123,4 @@ jobs: if: ${{ always() }} run: | rm -rf $XDG_CONFIG_HOME/dart/pub-credentials.json + rm -rf $CHANGELOG_PATH diff --git a/.github/workflows/publish_dry_run.yml b/.github/workflows/publish_dry_run.yml index 6095578e..bbd60cc2 100644 --- a/.github/workflows/publish_dry_run.yml +++ b/.github/workflows/publish_dry_run.yml @@ -32,9 +32,10 @@ jobs: ref: ${{ github.event.pull_request.base.ref }} - name: Load base version id: load_base_version + working-directory: ${{ matrix.package }} run: | set -e - echo "BASE_VERSION_${{ matrix.package }}=$(awk '/^version: / {print $2}' ${{ matrix.package }}/pubspec.yaml)" >> $GITHUB_OUTPUT + echo "BASE_VERSION_${{ matrix.package }}=$(yq -r '.version' pubspec.yaml)" >> $GITHUB_OUTPUT publish_dry_run: name: "Publish DRY RUN" needs: get_base_version @@ -52,26 +53,26 @@ jobs: uses: actions/checkout@v3 - name: Load this version id: load_this_version + working-directory: ${{ matrix.package }} run: | set -e - echo "THIS_VERSION=$(awk '/^version: / {print $2}' ${{ matrix.package }}/pubspec.yaml)" >> $GITHUB_ENV + echo "THIS_VERSION=$(yq -r '.version' pubspec.yaml)" >> $GITHUB_ENV - name: Compare versions id: compare_versions env: BASE_VERSION_chopper: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper }} BASE_VERSION_chopper_generator: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper_generator }} BASE_VERSION_chopper_built_value: ${{ needs.get_base_version.outputs.BASE_VERSION_chopper_built_value }} + working-directory: tool run: | set -e - pushd tool || exit dart pub get echo "IS_VERSION_GREATER=$(dart run compare_versions.dart $THIS_VERSION $BASE_VERSION_${{ matrix.package }})" >> $GITHUB_ENV - popd || exit - name: Validate pub.dev topics id: validate_pub_dev_topics + working-directory: ${{ matrix.package }} run: | set -e - pushd ${{ matrix.package }} || exit pattern="^[a-z][a-z0-9-]*[a-z0-9]$" for topic in $(yq -r '.topics[]' pubspec.yaml); do if [[ ! $topic =~ $pattern ]]; then @@ -79,17 +80,30 @@ jobs: exit 1 fi done - popd || exit + - name: Create release-specific CHANGELOG + id: create_changelog + if: ${{ env.IS_VERSION_GREATER == 1 }} + working-directory: ${{ matrix.package }} + run: | + set -e + CHANGELOG_PATH=$RUNNER_TEMP/CHANGELOG.md + awk '/^##[[:space:]].*/ { if (count == 1) exit; count++; print } count == 1 && !/^##[[:space:]].*/ { print }' CHANGELOG.md | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > $CHANGELOG_PATH + echo -en "\n[https://pub.dev/packages/${{ matrix.package }}/versions/$THIS_VERSION](https://pub.dev/packages/${{ matrix.package }}/versions/$THIS_VERSION)" >> $CHANGELOG_PATH + echo "CHANGELOG_PATH=$CHANGELOG_PATH" >> $GITHUB_ENV - name: Publish (dry run) id: publish_dry_run if: ${{ env.IS_VERSION_GREATER == 1 }} + working-directory: ${{ matrix.package }} run: | set -e - pushd ${{ matrix.package }} || exit yq -i 'del(.dependency_overrides)' pubspec.yaml dart pub publish --dry-run - popd || exit - name: Skip publish (dry run) id: skip_publish_dry_run if: ${{ env.IS_VERSION_GREATER == 0 }} run: echo "Skipping publish (dry run) for ${{ matrix.package }} because the version is not greater than the one on pub.dev" + - name: Cleanup + id: cleanup + if: ${{ always() }} + run: | + rm -rf $CHANGELOG_PATH diff --git a/chopper/CHANGELOG.md b/chopper/CHANGELOG.md index a2753721..528eb8dd 100644 --- a/chopper/CHANGELOG.md +++ b/chopper/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.0.7 + +- Remove charset from http request headers when the body is in bytes ([#508](https://github.com/lejard-h/chopper/pull/508)) + ## 7.0.6 - The @ChopperApi annotation's baseUrl property can be used as a top level constant string variable ([#493](https://github.com/lejard-h/chopper/pull/493)) diff --git a/chopper/analysis_options.yaml b/chopper/analysis_options.yaml index 6f56a451..4fd79467 100644 --- a/chopper/analysis_options.yaml +++ b/chopper/analysis_options.yaml @@ -3,7 +3,6 @@ include: package:lints/recommended.yaml analyzer: exclude: - "**.g.dart" - - "**.chopper.dart" - "**.mocks.dart" - "example/**" diff --git a/chopper/example/definition.chopper.dart b/chopper/example/definition.chopper.dart index a2684115..577547fe 100644 --- a/chopper/example/definition.chopper.dart +++ b/chopper/example/definition.chopper.dart @@ -6,7 +6,7 @@ part of 'definition.dart'; // ChopperGenerator // ************************************************************************** -// ignore_for_file: always_put_control_body_on_new_line, always_specify_types, prefer_const_declarations, unnecessary_string_interpolations, unnecessary_brace_in_string_interps +// ignore_for_file: type=lint final class _$MyService extends MyService { _$MyService([ChopperClient? client]) { if (client == null) return; diff --git a/chopper/lib/src/request.dart b/chopper/lib/src/request.dart index 1441ef3d..0f134f7d 100644 --- a/chopper/lib/src/request.dart +++ b/chopper/lib/src/request.dart @@ -138,16 +138,23 @@ base class Request extends http.BaseRequest with EquatableMixin { @visibleForTesting http.Request toHttpRequest() { final http.Request request = http.Request(method, url) - ..followRedirects = followRedirects - ..headers.addAll(headers); + ..followRedirects = followRedirects; - if (body != null) { + if (body == null) { + request.headers.addAll(headers); + } else { if (body is String) { - request.body = body; + request + ..headers.addAll(headers) + ..body = body; } else if (body is List) { - request.bodyBytes = body; + request + ..bodyBytes = body + ..headers.addAll(headers); } else if (body is Map) { - request.bodyFields = body; + request + ..headers.addAll(headers) + ..bodyFields = body; } else { throw ArgumentError.value('$body', 'body'); } diff --git a/chopper/pubspec.yaml b/chopper/pubspec.yaml index 6ec0d139..f125ad3e 100644 --- a/chopper/pubspec.yaml +++ b/chopper/pubspec.yaml @@ -1,6 +1,6 @@ name: chopper description: Chopper is an http client generator using source_gen, inspired by Retrofit -version: 7.0.6 +version: 7.0.7 documentation: https://hadrien-lejard.gitbook.io/chopper repository: https://github.com/lejard-h/chopper diff --git a/chopper/test/base_test.dart b/chopper/test/base_test.dart index dee04012..f1e76dad 100644 --- a/chopper/test/base_test.dart +++ b/chopper/test/base_test.dart @@ -7,6 +7,7 @@ import 'package:chopper/chopper.dart'; import 'package:http/http.dart' as http; import 'package:http/testing.dart'; import 'package:test/test.dart'; +import 'package:transparent_image/transparent_image.dart'; import 'test_service.dart'; import 'test_service_variable.dart'; @@ -763,6 +764,25 @@ void main() { expect(request.bodyBytes, equals([1, 2, 3])); }); + test('BodyBytes does not have charset header', () { + final request = Request( + HttpMethod.Post, + Uri.parse('https://foo/'), + Uri.parse(''), + headers: { + 'authorization': 'Bearer fooBarBaz', + 'x-foo': 'bar', + }, + body: kTransparentImage, + ).toHttpRequest(); + + expect(request.headers['authorization'], equals('Bearer fooBarBaz')); + expect(request.headers['x-foo'], equals('bar')); + expect(request.headers['content-type'], isNull); + expect(request.headers['content-type'], isNot(contains('charset='))); + expect(request.bodyBytes, equals(kTransparentImage)); + }); + test('BodyFields', () { final request = Request( HttpMethod.Post, diff --git a/chopper/test/test_service.chopper.dart b/chopper/test/test_service.chopper.dart index 4df2dd03..f070c8a8 100644 --- a/chopper/test/test_service.chopper.dart +++ b/chopper/test/test_service.chopper.dart @@ -6,7 +6,7 @@ part of 'test_service.dart'; // ChopperGenerator // ************************************************************************** -// ignore_for_file: always_put_control_body_on_new_line, always_specify_types, prefer_const_declarations, unnecessary_string_interpolations, unnecessary_brace_in_string_interps +// ignore_for_file: type=lint final class _$HttpTestService extends HttpTestService { _$HttpTestService([ChopperClient? client]) { if (client == null) return; diff --git a/chopper/test/test_service_variable.chopper.dart b/chopper/test/test_service_variable.chopper.dart index 038868a7..1f709494 100644 --- a/chopper/test/test_service_variable.chopper.dart +++ b/chopper/test/test_service_variable.chopper.dart @@ -6,7 +6,7 @@ part of 'test_service_variable.dart'; // ChopperGenerator // ************************************************************************** -// ignore_for_file: always_put_control_body_on_new_line, always_specify_types, prefer_const_declarations, unnecessary_string_interpolations, unnecessary_brace_in_string_interps +// ignore_for_file: type=lint final class _$HttpTestServiceVariable extends HttpTestServiceVariable { _$HttpTestServiceVariable([ChopperClient? client]) { if (client == null) return; diff --git a/chopper_built_value/analysis_options.yaml b/chopper_built_value/analysis_options.yaml index 6f56a451..4fd79467 100644 --- a/chopper_built_value/analysis_options.yaml +++ b/chopper_built_value/analysis_options.yaml @@ -3,7 +3,6 @@ include: package:lints/recommended.yaml analyzer: exclude: - "**.g.dart" - - "**.chopper.dart" - "**.mocks.dart" - "example/**" diff --git a/chopper_generator/CHANGELOG.md b/chopper_generator/CHANGELOG.md index 0b7c9f39..0b373162 100644 --- a/chopper_generator/CHANGELOG.md +++ b/chopper_generator/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.0.5 + +- Correct static analysis suppression of *.chopper.dart files ([#507](https://github.com/lejard-h/chopper/pull/507)) + ## 7.0.4 - Ignore unnecessary_string_interpolations ([#501](https://github.com/lejard-h/chopper/pull/501)) diff --git a/chopper_generator/Makefile b/chopper_generator/Makefile index 444451d2..7552c051 100644 --- a/chopper_generator/Makefile +++ b/chopper_generator/Makefile @@ -41,6 +41,10 @@ install: @# Help: Install all the project's packages dart pub get +sure: + @# Help: Analyze the project's Dart code, check the formatting one or more Dart files and run unit tests for the current project. + make check_style && make tests + tests: @# Help: Run Dart unit and widget tests for the current project. dart test diff --git a/chopper_generator/analysis_options.yaml b/chopper_generator/analysis_options.yaml index 6f56a451..4fd79467 100644 --- a/chopper_generator/analysis_options.yaml +++ b/chopper_generator/analysis_options.yaml @@ -3,7 +3,6 @@ include: package:lints/recommended.yaml analyzer: exclude: - "**.g.dart" - - "**.chopper.dart" - "**.mocks.dart" - "example/**" diff --git a/chopper_generator/lib/src/generator.dart b/chopper_generator/lib/src/generator.dart index e194f52c..3a6b36ef 100644 --- a/chopper_generator/lib/src/generator.dart +++ b/chopper_generator/lib/src/generator.dart @@ -93,12 +93,7 @@ final class ChopperGenerator )); }); - const String ignore = '// ignore_for_file: ' - 'always_put_control_body_on_new_line, ' - 'always_specify_types, ' - 'prefer_const_declarations, ' - 'unnecessary_string_interpolations, ' - 'unnecessary_brace_in_string_interps'; + const String ignore = '// ignore_for_file: type=lint'; final DartEmitter emitter = DartEmitter(); return DartFormatter().format('$ignore\n${classBuilder.accept(emitter)}'); diff --git a/chopper_generator/pubspec.yaml b/chopper_generator/pubspec.yaml index 5cfb749d..6048de23 100644 --- a/chopper_generator/pubspec.yaml +++ b/chopper_generator/pubspec.yaml @@ -1,6 +1,6 @@ name: chopper_generator description: Chopper is an http client generator using source_gen, inspired by Retrofit -version: 7.0.4 +version: 7.0.5 documentation: https://hadrien-lejard.gitbook.io/chopper repository: https://github.com/lejard-h/chopper diff --git a/chopper_generator/test/test_service.chopper.dart b/chopper_generator/test/test_service.chopper.dart index 4df2dd03..f070c8a8 100644 --- a/chopper_generator/test/test_service.chopper.dart +++ b/chopper_generator/test/test_service.chopper.dart @@ -6,7 +6,7 @@ part of 'test_service.dart'; // ChopperGenerator // ************************************************************************** -// ignore_for_file: always_put_control_body_on_new_line, always_specify_types, prefer_const_declarations, unnecessary_string_interpolations, unnecessary_brace_in_string_interps +// ignore_for_file: type=lint final class _$HttpTestService extends HttpTestService { _$HttpTestService([ChopperClient? client]) { if (client == null) return; diff --git a/chopper_generator/test/test_service_variable.chopper.dart b/chopper_generator/test/test_service_variable.chopper.dart index 038868a7..1f709494 100644 --- a/chopper_generator/test/test_service_variable.chopper.dart +++ b/chopper_generator/test/test_service_variable.chopper.dart @@ -6,7 +6,7 @@ part of 'test_service_variable.dart'; // ChopperGenerator // ************************************************************************** -// ignore_for_file: always_put_control_body_on_new_line, always_specify_types, prefer_const_declarations, unnecessary_string_interpolations, unnecessary_brace_in_string_interps +// ignore_for_file: type=lint final class _$HttpTestServiceVariable extends HttpTestServiceVariable { _$HttpTestServiceVariable([ChopperClient? client]) { if (client == null) return; diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index 8ed20e77..1e603f80 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -3,7 +3,6 @@ include: package:lints/recommended.yaml analyzer: exclude: - "**.g.dart" - - "**.chopper.dart" - "**.mocks.dart" linter: diff --git a/example/lib/built_value_resource.chopper.dart b/example/lib/built_value_resource.chopper.dart index af0b742d..32264219 100644 --- a/example/lib/built_value_resource.chopper.dart +++ b/example/lib/built_value_resource.chopper.dart @@ -6,7 +6,7 @@ part of 'built_value_resource.dart'; // ChopperGenerator // ************************************************************************** -// ignore_for_file: always_put_control_body_on_new_line, always_specify_types, prefer_const_declarations, unnecessary_brace_in_string_interps +// ignore_for_file: type=lint final class _$MyService extends MyService { _$MyService([ChopperClient? client]) { if (client == null) return; diff --git a/example/lib/json_serializable.chopper.dart b/example/lib/json_serializable.chopper.dart index 1aa9352e..e6164985 100644 --- a/example/lib/json_serializable.chopper.dart +++ b/example/lib/json_serializable.chopper.dart @@ -6,7 +6,7 @@ part of 'json_serializable.dart'; // ChopperGenerator // ************************************************************************** -// ignore_for_file: always_put_control_body_on_new_line, always_specify_types, prefer_const_declarations, unnecessary_brace_in_string_interps +// ignore_for_file: type=lint final class _$MyService extends MyService { _$MyService([ChopperClient? client]) { if (client == null) return; diff --git a/tool/ci.sh b/tool/ci.sh index 9c1ac4c1..0af37047 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.7 +# Created with package:mono_repo v6.6.0 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")