Skip to content

Commit

Permalink
+chore: Updare workflow scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
robmllze committed Oct 4, 2024
1 parent 5efe41c commit ac7e382
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/scripts/update_changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'dart:io';

void main(List<String> 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()) {
Expand All @@ -29,14 +29,14 @@ void main(List<String> 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},
),
);
}
Expand Down
52 changes: 41 additions & 11 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

- Released @ 10/2024 (UTC)
- docs: Update readme
- docs: Update changelog

## [0.1.2]

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac7e382

Please sign in to comment.