Skip to content

Commit

Permalink
🔖 release chopper v7.0.7 and chopper_generator v7.0.5 (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Oct 7, 2023
1 parent 9a3b540 commit 9b6fc0d
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 47 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
34 changes: 26 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,34 +54,43 @@ 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
echo "Invalid topic: $topic"
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 }}
Expand All @@ -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 }}
Expand All @@ -106,3 +123,4 @@ jobs:
if: ${{ always() }}
run: |
rm -rf $XDG_CONFIG_HOME/dart/pub-credentials.json
rm -rf $CHANGELOG_PATH
30 changes: 22 additions & 8 deletions .github/workflows/publish_dry_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,44 +53,57 @@ 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
echo "Invalid topic: $topic"
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
4 changes: 4 additions & 0 deletions chopper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
1 change: 0 additions & 1 deletion chopper/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include: package:lints/recommended.yaml
analyzer:
exclude:
- "**.g.dart"
- "**.chopper.dart"
- "**.mocks.dart"
- "example/**"

Expand Down
2 changes: 1 addition & 1 deletion chopper/example/definition.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions chopper/lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>) {
request.bodyBytes = body;
request
..bodyBytes = body
..headers.addAll(headers);
} else if (body is Map<String, String>) {
request.bodyFields = body;
request
..headers.addAll(headers)
..bodyFields = body;
} else {
throw ArgumentError.value('$body', 'body');
}
Expand Down
2 changes: 1 addition & 1 deletion chopper/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
20 changes: 20 additions & 0 deletions chopper/test/base_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion chopper/test/test_service.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chopper/test/test_service_variable.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion chopper_built_value/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include: package:lints/recommended.yaml
analyzer:
exclude:
- "**.g.dart"
- "**.chopper.dart"
- "**.mocks.dart"
- "example/**"

Expand Down
4 changes: 4 additions & 0 deletions chopper_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
4 changes: 4 additions & 0 deletions chopper_generator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion chopper_generator/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include: package:lints/recommended.yaml
analyzer:
exclude:
- "**.g.dart"
- "**.chopper.dart"
- "**.mocks.dart"
- "example/**"

Expand Down
7 changes: 1 addition & 6 deletions chopper_generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)}');
Expand Down
2 changes: 1 addition & 1 deletion chopper_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion chopper_generator/test/test_service.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9b6fc0d

Please sign in to comment.