refactor(publishing-workflow): move fethcing GitHub release notes steps into a dart script

pull/1919/head
Ellet 10 months ago
parent a7f4604b43
commit b117ef18ec
  1. 23
      .github/workflows/publish.yml
  2. 3
      pubspec.yaml
  3. 65
      scripts/create_version_content_from_github_release.dart
  4. 2
      scripts/update_package_version.dart

@ -74,28 +74,11 @@ jobs:
id: release_tag
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: 📑 Fetch release notes from Github API
id: fetch-release-notes-request
uses: fjogeleit/http-request-action@v1
with:
url: https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.release_tag.outputs.tag }}
method: 'GET'
customHeaders: '{"Authorization": "${{ secrets.GITHUB_TOKEN }}"}'
preventFailureOnNoResponse: 'false'
- name: Validate release notes response
run: |
releaseNotesResponse="${{ fromJson(steps.fetch-release-notes-request.outputs.response) }}"
if [[ -z "$releaseNotesResponse" || "$releaseNotesResponse" == "null" ]]; then
echo "Error: Release notes response is empty."
exit 1
fi
- name: 🖌 Create required version content file to use in the next step
run: echo "${{ fromJson(steps.fetch-release-notes-request.outputs.response).body }}" > ./build/versionContent.md
- name: 📑 Fetch release notes from Github API and create a required file by the next step
run: dart ./scripts/create_version_content_from_github_release.dart "${{ github.repository }}" "${{ steps.release_tag.outputs.tag }}" "${{ secrets.GITHUB_TOKEN }}"
- name: 📝 Update version and CHANGELOG for all the packages
run: dart ./scripts/update_package_version.dart ${{ steps.extract_version.outputs.VERSION }} '${{ fromJson(steps.fetch-release-notes-request.outputs.response).body }}'
run: dart ./scripts/update_package_version.dart ${{ steps.extract_version.outputs.VERSION }}
- name: 💾 Commit updated version and CHANGELOG
id: auto-commit-action

@ -70,9 +70,10 @@ dev_dependencies:
flutter_quill_test: ^9.3.4
test: ^1.24.3
# Both yaml_edit and yaml are only used for the scripts
# For scripts only
yaml_edit: ^2.2.1
yaml: ^3.1.2
http: ^1.2.1
flutter:
uses-material-design: true

@ -0,0 +1,65 @@
// ignore_for_file: avoid_print
import 'dart:convert';
import 'dart:io' show exit;
import 'package:http/http.dart' as http;
import 'update_package_version.dart';
// A script is used in CI that will fetch release notes using GitHub API
// and create a file from it that will be used by another script
//
// This script should run from root project folder instead of scripts folder
// or others.
const _usage =
'Usage: ./script <github-repository> <release-tag> <github-authorization> (optional)';
Future<void> main(List<String> args) async {
print('📑 Fetch release notes from Github API');
if (args.isEmpty) {
print('Missing required arguments ($args). $_usage');
exit(1);
}
if (args.length > 2) {
print('Too many arguments ($args). $_usage');
exit(1);
}
if (args.length < 2) {
print('Missing arguments ($args). $_usage');
exit(1);
}
final githubRepository = args[0];
final releaseTag = args[1];
final githubAuthorization = args.elementAtOrNull(2);
final response = await http.get(
Uri.parse(
'https://api.github.com/repos/$githubRepository/releases/tags/$releaseTag',
),
headers: {
if (githubAuthorization != null) 'Authorization': githubAuthorization,
},
);
if (response.statusCode != 200) {
print('Response status code is ${response.statusCode} which is not 200');
print('Response body: ${response.body}');
exit(1);
}
final responseBody = response.body;
print(' Validate release notes response');
if (responseBody.trim().isEmpty) {
print('Release notes response is empty.');
exit(1);
}
print('Response body: $responseBody');
final githubReleaseNotes =
(jsonDecode(responseBody) as Map<String, Object?>)['body'] as String?;
if (githubReleaseNotes == null) {
print('Release notes is null.');
exit(1);
}
await versionContentFile.writeAsString(githubReleaseNotes);
}

@ -20,6 +20,7 @@ final _packages = [
const _usage = 'Usage: ./script <version>';
const _versionContentFileName = 'versionContent.md';
final versionContentFile = File(path.join('build', _versionContentFileName));
/// 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
@ -50,7 +51,6 @@ Future<void> main(List<String> args) async {
print('The version is empty ($args). $_usage');
exit(1);
}
final versionContentFile = File(path.join('build', _versionContentFileName));
if (!(await versionContentFile.exists())) {
print(
'The file "$_versionContentFileName" in ${versionContentFile.path} does not exist.',

Loading…
Cancel
Save