From ac7e382b7edb70213c098679823648fd17c1b468 Mon Sep 17 00:00:00 2001 From: robmllze <86869208+robmllze@users.noreply.github.com> Date: Fri, 4 Oct 2024 19:31:33 +1000 Subject: [PATCH] +chore: Updare workflow scripts --- .github/scripts/update_changelog.dart | 6 ++-- .github/workflows/prepare.yml | 52 +++++++++++++++++++++------ .github/workflows/publish.yml | 2 +- CHANGELOG.md | 1 - pubspec.yaml | 2 +- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/.github/scripts/update_changelog.dart b/.github/scripts/update_changelog.dart index d6e632a..e213ba2 100644 --- a/.github/scripts/update_changelog.dart +++ b/.github/scripts/update_changelog.dart @@ -16,7 +16,7 @@ import 'dart:io'; void main(List args) { final version = args.isNotEmpty ? args[0] : '0.1.0'; - final newReleaseNotes = args.length > 1 ? args[1] : 'Initial commit'; + final comitMesssage = args.length > 1 ? args[1].replaceFirst('+', '') : ''; final changelogPath = 'CHANGELOG.md'; final file = File(changelogPath); if (!file.existsSync()) { @@ -29,14 +29,14 @@ void main(List args) { final versionExist = sections.where((e) => e.version == version).isNotEmpty; if (versionExist) { sections.where((e) => e.version == version).forEach((e) { - e.addUpdate(newReleaseNotes); + e.addUpdate(comitMesssage); }); } else { sections.add( _VersionSection( version: version, releasedAt: DateTime.now().toUtc(), - updates: {newReleaseNotes}, + updates: {comitMesssage}, ), ); } diff --git a/.github/workflows/prepare.yml b/.github/workflows/prepare.yml index 9ff1285..3bfa73e 100644 --- a/.github/workflows/prepare.yml +++ b/.github/workflows/prepare.yml @@ -25,40 +25,70 @@ jobs: prepare: runs-on: ubuntu-latest steps: + # Checkout the code from the repository - name: Checkout code uses: actions/checkout@v3 + # Get the latest commit message + - name: Get commit messages + id: get_commits + run: | + COMMIT_MESSAGES=$(git log --format=%B -n 1 HEAD) + echo "::set-output name=COMMIT_MESSAGES::${COMMIT_MESSAGES}" + + # Check if the commit message starts with '+' + - name: Check commit message + id: check_message + run: | + if echo "${{ steps.get_commits.outputs.COMMIT_MESSAGES }}" | grep -q "^+"; then + echo "::set-output name=PROCEED::true" + else + echo "::set-output name=PROCEED::false" + fi + + # Debug environment variables + - name: Debug environment variables + run: | + echo "PROCEED=${{ steps.check_message.outputs.PROCEED }}" + echo "COMMIT_MESSAGES=${{ steps.get_commits.outputs.COMMIT_MESSAGES }}" + + # Set up Dart if the commit message check passed - name: Set up Dart + if: ${{ steps.check_message.outputs.PROCEED == 'true' }} uses: dart-lang/setup-dart@v1.2 + # Format Dart code if the commit message check passed - name: Format Dart code + if: ${{ steps.check_message.outputs.PROCEED == 'true' }} run: dart format . + # Apply Dart fixes if the commit message check passed - name: Apply Dart fixes + if: ${{ steps.check_message.outputs.PROCEED == 'true' }} run: dart fix --apply + # Extract the version from pubspec.yaml if the commit message check passed - name: Extract version from pubspec.yaml + if: ${{ steps.check_message.outputs.PROCEED == 'true' }} id: get_version run: | VERSION=$(grep "version:" pubspec.yaml | sed 's/version: //') - echo "Extracted version: $VERSION" - echo "::set-output name=extracted_version::$VERSION" - - - name: Get commit messages - id: get_commits - run: | - COMMIT_MESSAGES=$(git log --format=%B -n 1 HEAD) - echo "::set-output name=messages::${COMMIT_MESSAGES}" + echo "Version extracted from pubspec.yaml: $VERSION" + echo "::set-output name=PUBSPEC_VERSION::${VERSION}" + # Update CHANGELOG.md if the commit message check passed - name: Update CHANGELOG.md + if: ${{ steps.check_message.outputs.PROCEED == 'true' }} run: | - RELEASE_NOTES="${{ steps.get_commits.outputs.messages }}" - dart run .github/scripts/update_changelog.dart "${{ steps.get_version.outputs.extracted_version }}" "$RELEASE_NOTES" + RELEASE_NOTES="${{ steps.get_commits.outputs.COMMIT_MESSAGES }}" + dart run .github/scripts/update_changelog.dart "${{ steps.get_version.outputs.PUBSPEC_VERSION }}" "$RELEASE_NOTES" + # Commit and push changes if the commit message check passed - name: Commit and push changes + if: ${{ steps.check_message.outputs.PROCEED == 'true' }} run: | git config user.name github-actions git config user.email github-actions@github.com git add . - git commit -m "Prepare version ${{ steps.get_version.outputs.extracted_version }}" + git commit -m "Prepare version ${{ steps.get_version.outputs.PUBSPEC_VERSION }}" git push \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e9df656..c203cd2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,5 +24,5 @@ on: jobs: publish: permissions: - id-token: write # Required for authentication using OIDC + id-token: write uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b8e8e..76ab716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ - Released @ 10/2024 (UTC) - docs: Update readme -- docs: Update changelog ## [0.1.2] diff --git a/pubspec.yaml b/pubspec.yaml index e530a58..02c4974 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ name: df_bijective_uuid_mapper description: A package providing bijective UUID mapping for secure and efficienct lookups. -version: 0.1.2 +version: 0.1.3 repository: https://github.com/robmllze/df_bijective_uuid_mapper funding: - https://www.buymeacoffee.com/robmllze