diff --git a/.github/actions/publish-dart-package/action.yml b/.github/actions/publish-dart-package/action.yml deleted file mode 100644 index df91f00..0000000 --- a/.github/actions/publish-dart-package/action.yml +++ /dev/null @@ -1,136 +0,0 @@ -name: 'Publish Dart/Flutter Package' -description: 'Checks local vs remote package versions, optionally dry-runs or publishes to pub.dev' - -inputs: - credentialJson: - description: 'The JSON credentials for pub.dev (i.e. pub-credentials.json content).' - required: true - - flutter: - description: 'If true, use flutter commands (flutter pub get/test/publish). Otherwise use dart.' - default: 'false' - required: false - - skipTests: - description: 'If true, skip testing.' - default: 'false' - required: false - - dryRunOnly: - description: 'If true, do only a --dry-run publish and skip real publishing.' - default: 'false' - required: false - - relativePath: - description: 'Relative path to your package if not in the repository root, e.g. `packages/my_pkg`' - default: '' - required: false - -runs: - using: 'composite' - steps: - # 1) Switch directory if needed - - name: Switch Directory - if: ${{ inputs.relativePath != '' }} - run: | - echo "Switching directory to '${{ inputs.relativePath }}'" - cd ${{ inputs.relativePath }} - shell: bash - - # 2) Write pub credentials to ~/.config/dart - - name: Setup Credentials - run: | - mkdir -p ~/.config/dart - echo "${{ inputs.credentialJson }}" > ~/.config/dart/pub-credentials.json - shell: bash - - # 3) Install dependencies (flutter or dart) - - name: Install Dependencies - run: | - if [ "${{ inputs.flutter }}" = "true" ]; then - echo "Running 'flutter pub get'..." - flutter pub get - else - echo "Running 'dart pub get'..." - dart pub get - fi - shell: bash - - # 4) (Optional) Run tests - - name: Run Tests - if: ${{ inputs.skipTests != 'true' }} - run: | - if [ "${{ inputs.flutter }}" = "true" ]; then - echo "Running 'flutter test'..." - flutter test - else - echo "Running 'dart pub run test'..." - dart pub run test - fi - shell: bash - - # 5) Determine local version from pubspec.yaml - - name: Determine Local Version - id: local_version - run: | - VERSION=$(grep '^version:' pubspec.yaml | cut -d ' ' -f2 | tr -d '\r') - echo "Local package version: $VERSION" - echo "localVersion=$VERSION" >> $GITHUB_OUTPUT - shell: bash - - # 6) Determine remote version by global activate - - name: Determine Remote Version - id: remote_version - run: | - PKG_NAME=$(grep '^name:' pubspec.yaml | cut -d ' ' -f2 | tr -d '\r') - echo "Detected package name: $PKG_NAME" - - if [ "${{ inputs.flutter }}" = "true" ]; then - ACTIVATE_OUTPUT=$(flutter pub global activate $PKG_NAME || true) - else - ACTIVATE_OUTPUT=$(dart pub global activate $PKG_NAME || true) - fi - - REMOTE_VERSION=$(echo "$ACTIVATE_OUTPUT" | perl -n -e'/^Activated .* (.*)\./ && print $1') - if [ -z "$REMOTE_VERSION" ]; then - REMOTE_VERSION="NONE" - fi - - echo "Remote package version: $REMOTE_VERSION" - echo "remoteVersion=$REMOTE_VERSION" >> $GITHUB_OUTPUT - shell: bash - - # 7) Compare local vs. remote and run dry-run or publish - - name: Publish Logic - run: | - LOCAL_VERSION="${{ steps.local_version.outputs.localVersion }}" - REMOTE_VERSION="${{ steps.remote_version.outputs.remoteVersion }}" - echo "Local version: $LOCAL_VERSION" - echo "Remote version: $REMOTE_VERSION" - - # Perform dry-run - if [ "${{ inputs.flutter }}" = "true" ]; then - flutter pub publish --dry-run - else - dart pub publish --dry-run - fi - - # Skip if same version - if [ "$LOCAL_VERSION" = "$REMOTE_VERSION" ]; then - echo "Local and remote versions match. Skipping publish." - exit 0 - fi - - # Stop if dryRunOnly - if [ "${{ inputs.dryRunOnly }}" = "true" ]; then - echo "Dry-run only is true. Stopping now." - exit 0 - fi - - # Otherwise, do a forced publish (no interactive prompt) - if [ "${{ inputs.flutter }}" = "true" ]; then - flutter pub publish --force - else - dart pub publish --force - fi - shell: bash \ No newline at end of file diff --git a/.github/workflows/tag-and-deploy.yml b/.github/workflows/tag-and-deploy.yml index 84ab8d7..7d958ee 100644 --- a/.github/workflows/tag-and-deploy.yml +++ b/.github/workflows/tag-and-deploy.yml @@ -123,11 +123,10 @@ jobs: - uses: ./.github/actions/setup-flutter - name: Publish to pub.dev - uses: ./.github/actions/publish-dart-package + uses: k-paxian/dart-package-publisher@master with: credentialJson: ${{ secrets.CREDENTIAL_JSON }} flutter: true - dryRunOnly: false - name: Notify team of successful deployment uses: slackapi/slack-github-action@v1.26.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd1909c..ec4c6fe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - uses: ./.github/actions/setup-flutter - name: dry-run publishing to feel confident deployment will work after merging PR - uses: ./.github/actions/publish-dart-package + uses: k-paxian/dart-package-publisher@master with: credentialJson: ${{ secrets.CREDENTIAL_JSON }} dryRunOnly: true