| name: Groundskeeper |
| description: Reusable workflow to run dart format and dart fix on a single package, and create a PR if there are changes. |
| |
| on: |
| workflow_call: |
| inputs: |
| sdk: |
| description: 'Dart SDK version or Flutter channel' |
| required: false |
| type: string |
| default: 'dev' |
| use-flutter: |
| description: 'Whether to use Flutter for this package' |
| required: false |
| type: boolean |
| default: false |
| directory: |
| description: 'The directory to tidy' |
| required: false |
| type: string |
| default: '.' |
| update-changelog: |
| description: 'Whether to update the changelog' |
| required: false |
| type: boolean |
| default: false |
| changelog-message: |
| description: 'The changelog message' |
| required: false |
| type: string |
| default: '' |
| run-format: |
| description: 'Run dart format' |
| required: false |
| type: boolean |
| default: true |
| run-fix: |
| description: 'Run dart fix --apply' |
| required: false |
| type: boolean |
| default: true |
| branch: |
| description: 'PR branch name' |
| required: false |
| type: string |
| default: 'auto-tidy' |
| title: |
| description: 'PR title' |
| required: false |
| type: string |
| default: 'Tidy: Automated dart format and fix' |
| body: |
| description: 'PR body' |
| required: false |
| type: string |
| default: 'This is an automated PR to apply `dart format` and `dart fix --apply`.' |
| |
| jobs: |
| tidy: |
| runs-on: ubuntu-latest |
| permissions: |
| contents: write |
| pull-requests: write |
| steps: |
| - name: Generate Dart Bot Token |
| id: generate-token |
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 |
| with: |
| client-id: ${{ vars.ECOSYSTEM_BOT_CLIENT_ID }} |
| private-key: ${{ secrets.ECOSYSTEM_BOT_PRIVATE_KEY }} |
| permission-contents: write |
| permission-pull-requests: write |
| |
| - name: Checkout caller repo |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| with: |
| token: ${{ steps.generate-token.outputs.token }} |
| persist-credentials: false |
| |
| - name: Checkout ecosystem (for tidy script) |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| with: |
| repository: dart-lang/ecosystem |
| path: .github/ecosystem-helper |
| persist-credentials: false |
| |
| - uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 |
| if: ${{ inputs.use-flutter }} |
| with: |
| channel: ${{ inputs.sdk }} |
| cache: true |
| |
| - uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260 |
| if: ${{ !inputs.use-flutter }} |
| with: |
| sdk: ${{ inputs.sdk }} |
| |
| - name: Resolve dependencies for firehose |
| working-directory: .github/ecosystem-helper/pkgs/firehose |
| run: dart pub get |
| |
| - name: Run Tidy Script |
| working-directory: ${{ inputs.directory }} |
| env: |
| RUN_FORMAT: ${{ inputs.run-format }} |
| RUN_FIX: ${{ inputs.run-fix }} |
| run: | |
| dart $GITHUB_WORKSPACE/.github/ecosystem-helper/pkgs/firehose/bin/groundskeeper.dart \ |
| --format="$RUN_FORMAT" \ |
| --fix="$RUN_FIX" |
| |
| - name: Check for changes |
| id: check_changes |
| working-directory: ${{ inputs.directory }} |
| run: | |
| if [ -n "$(git status --porcelain .)" ]; then |
| echo "changed=true" >> $GITHUB_OUTPUT |
| else |
| echo "changed=false" >> $GITHUB_OUTPUT |
| fi |
| |
| - name: Update changelog |
| if: ${{ inputs.update-changelog && steps.check_changes.outputs.changed == 'true' }} |
| working-directory: .github/ecosystem-helper/pkgs/repo_manage |
| env: |
| DIRECTORY: ${{ inputs.directory }} |
| CHANGELOG_MESSAGE: ${{ inputs.changelog-message }} |
| run: | |
| dart pub get |
| dart run bin/report.dart changelog --changelog "../../../../$DIRECTORY/CHANGELOG.md" "$CHANGELOG_MESSAGE" |
| |
| - name: Clean up helper |
| run: rm -rf .github/ecosystem-helper |
| |
| - name: Create Pull Request |
| if: steps.check_changes.outputs.changed == 'true' |
| uses: peter-evans/create-pull-request@653ba8b281fa5e1ee78ec20dda96cf9a79102c04 |
| with: |
| token: ${{ steps.generate-token.outputs.token }} |
| committer: dart-ecosystem-bot <dart-ecosystem-bot@google.com> |
| author: dart-ecosystem-bot <dart-ecosystem-bot@google.com> |
| commit-message: ${{ inputs.title }} |
| branch: ${{ inputs.branch }} |
| title: ${{ inputs.title }} |
| body: ${{ inputs.body }} |
| delete-branch: true |