| 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@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 | |
| 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@3d3c42e5aac5ba805825da76410c181273ba90b1 | |
| with: | |
| token: ${{ steps.generate-token.outputs.token }} | |
| persist-credentials: false | |
| - name: Checkout ecosystem (for tidy script) | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 | |
| 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 == 'dev' && 'master' || inputs.sdk }} | |
| cache: true | |
| - uses: dart-lang/setup-dart@6afc89df92d6eb3834022f73cd65adc8cdfcb92d | |
| 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 }} | |
| USE_FLUTTER: ${{ inputs.use-flutter }} | |
| run: | | |
| dart $GITHUB_WORKSPACE/.github/ecosystem-helper/pkgs/firehose/bin/groundskeeper.dart \ | |
| --format="$RUN_FORMAT" \ | |
| --fix="$RUN_FIX" \ | |
| --use-flutter="$USE_FLUTTER" | |
| - 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@bd09a93810788ce61d2d5fb7d6b221b9b4a4aab7 | |
| 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 |