diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7d507ca..7c0ae08 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,9 +1,4 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Dart +name: Dart CI on: push: @@ -18,25 +13,28 @@ jobs: steps: - uses: actions/checkout@v4 - # Note: This workflow uses the latest stable version of the Dart SDK. - # You can specify other versions if desired, see documentation here: - # https://github.com/dart-lang/setup-dart/blob/main/README.md - # - uses: dart-lang/setup-dart@v1 - - uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603 + - uses: subosito/flutter-action@v2 + with: + channel: stable + + - name: Read package version + id: version + run: | + VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}') + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "📦 Package version: $VERSION" - name: Install dependencies - run: dart pub get + run: flutter pub get - # Uncomment this step to verify the use of 'dart format' on each commit. - # - name: Verify formatting - # run: dart format --output=none --set-exit-if-changed . + - name: Verify formatting + # Non-blocking: flags style drift without failing the build. + # Remove continue-on-error once existing formatting issues are resolved. + run: dart format --output=none --set-exit-if-changed . + continue-on-error: true - # Consider passing '--fatal-infos' for slightly stricter analysis. - name: Analyze project source - run: dart analyze + run: flutter analyze - # Your project will need to have tests in test/ and a dependency on - # package:test for this step to succeed. Note that Flutter projects will - # want to change this to 'flutter test'. - name: Run tests - run: dart test + run: flutter test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..a8e7d94 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,44 @@ +name: Publish to pub.dev + +on: + push: + tags: + - 'v[0-9]+\.[0-9]+\.[0-9]+*' + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + id-token: write + + steps: + - uses: actions/checkout@v4 + + - uses: subosito/flutter-action@v2 + with: + channel: stable + + - name: Read package version + id: version + run: | + VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}') + TAG="${GITHUB_REF#refs/tags/v}" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "📦 Package version: $VERSION | Git tag: $TAG" + if [ "$VERSION" != "$TAG" ]; then + echo "❌ pubspec.yaml version ($VERSION) does not match git tag ($TAG)" + exit 1 + fi + + - name: Install dependencies + run: flutter pub get + + - name: Analyze project source + run: flutter analyze + + - name: Run tests + run: flutter test + + - name: Publish package + run: dart pub publish --force diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..e18df51 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# release.sh — bump version, update CHANGELOG, commit, tag, and push. +# +# Usage: +# ./scripts/release.sh "" +# +# Example: +# ./scripts/release.sh 1.0.8 "fix: resolve null pointer on iOS" + +set -euo pipefail + +NEW_VERSION="${1:-}" +CHANGELOG_ENTRY="${2:-}" + +# ── Validation ────────────────────────────────────────────────────────────── +if [[ -z "$NEW_VERSION" || -z "$CHANGELOG_ENTRY" ]]; then + echo "Usage: $0 \"\"" + echo "Example: $0 1.0.8 \"fix: resolve null pointer on iOS\"" + exit 1 +fi + +if ! echo "$NEW_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(\+[0-9]+)?$'; then + echo "❌ Invalid version format: $NEW_VERSION (expected e.g. 1.0.8 or 1.0.8+1)" + exit 1 +fi + +PUBSPEC="pubspec.yaml" +CHANGELOG="CHANGELOG.md" + +CURRENT_VERSION=$(grep '^version:' "$PUBSPEC" | awk '{print $2}') +echo "Current version : $CURRENT_VERSION" +echo "New version : $NEW_VERSION" + +# ── Check working tree is clean ─────────────────────────────────────────── +if [[ -n "$(git status --porcelain)" ]]; then + echo "❌ Working tree is not clean. Commit or stash changes first." + exit 1 +fi + +# ── Install dependencies and run checks ────────────────────────────────── +echo "" +echo "🔍 Installing dependencies..." +flutter pub get + +echo "🔍 Analyzing source..." +flutter analyze + +echo "🔍 Running tests..." +flutter test + +echo "🔍 Checking publish readiness..." +dart pub publish --dry-run + +# ── Bump version in pubspec.yaml ───────────────────────────────────────── +echo "" +echo "✏️ Bumping version in $PUBSPEC..." +if sed --version 2>/dev/null | grep -q GNU; then + sed -i "s/^version: .*$/version: ${NEW_VERSION}/" "$PUBSPEC" +else + sed -i.bak "s/^version: .*$/version: ${NEW_VERSION}/" "$PUBSPEC" + rm -f "${PUBSPEC}.bak" +fi + +# ── Prepend entry to CHANGELOG.md ──────────────────────────────────────── +echo "✏️ Updating $CHANGELOG..." +TMPFILE=$(mktemp) +{ + echo "## $NEW_VERSION" + echo "- $CHANGELOG_ENTRY" + echo "" + cat "$CHANGELOG" +} > "$TMPFILE" +mv "$TMPFILE" "$CHANGELOG" + +# ── Commit, tag, push ──────────────────────────────────────────────────── +echo "" +echo "📝 Committing changes..." +git add "$PUBSPEC" "$CHANGELOG" +git commit -m "chore: release v$NEW_VERSION" + +echo "🏷️ Creating tag v$NEW_VERSION..." +git tag "v$NEW_VERSION" + +echo "🚀 Pushing commit and tag..." +git push +git push origin "v$NEW_VERSION" + +echo "" +echo "✅ Released v$NEW_VERSION — the publish workflow will now run on GitHub Actions."