diff --git a/.github/actions/dart_package/action.yaml b/.github/actions/dart_package/action.yaml new file mode 100644 index 000000000..6f0b3e392 --- /dev/null +++ b/.github/actions/dart_package/action.yaml @@ -0,0 +1,65 @@ +name: Dart Package Workflow + +inputs: + concurrency: + required: false + type: number + default: 4 + coverage_excludes: + required: false + type: string + default: "" + dart_sdk: + required: false + type: string + default: "stable" + working_directory: + required: false + type: string + default: "." + min_coverage: + required: false + type: number + default: 100 + analyze_directories: + required: false + type: string + default: "lib test" + report_on: + required: false + type: string + default: "lib" + platform: + required: false + type: string + default: "vm" + +runs: + using: "composite" + steps: + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{inputs.dart_sdk}} + + - working-directory: ${{ inputs.working_directory }} + shell: ${{ inputs.shell }} + run: dart pub get + + - working-directory: ${{ inputs.working_directory }} + shell: ${{ inputs.shell }} + run: dart format --set-exit-if-changed . + + - working-directory: ${{ inputs.working_directory }} + shell: ${{ inputs.shell }} + run: dart analyze --fatal-infos --fatal-warnings ${{inputs.analyze_directories}} + + - working-directory: ${{ inputs.working_directory }} + shell: ${{ inputs.shell }} + run: | + dart pub global activate coverage + dart test -j ${{inputs.concurrency}} --coverage=coverage --platform=${{inputs.platform}} && dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --packages=.dart_tool/package_config.json --report-on=${{inputs.report_on}} --check-ignore + - uses: VeryGoodOpenSource/very_good_coverage@v2 + with: + path: ${{inputs.working_directory}}/coverage/lcov.info + exclude: ${{inputs.coverage_excludes}} + min_coverage: ${{inputs.min_coverage}} diff --git a/.github/actions/pana/action.yaml b/.github/actions/pana/action.yaml new file mode 100644 index 000000000..5379129c7 --- /dev/null +++ b/.github/actions/pana/action.yaml @@ -0,0 +1,34 @@ +name: Pana Workflow + +inputs: + min_score: + required: false + type: number + default: 120 + pana_version: + required: false + type: string + working_directory: + required: false + type: string + default: "." + +runs: + using: "composite" + steps: + - uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + + - working-directory: ${{ inputs.working_directory }} + shell: ${{ inputs.shell }} + run: flutter pub global activate pana ${{inputs.pana_version}} + + - working-directory: ${{ inputs.working_directory }} + shell: ${{ inputs.shell }} + run: | + PANA=$(pana . --no-warning); PANA_SCORE=$(echo $PANA | sed -n "s/.*Points: \([0-9]*\)\/\([0-9]*\)./\1\/\2/p") + echo "Score: $PANA_SCORE" + IFS='/'; read -a SCORE_ARR <<< "$PANA_SCORE"; SCORE=SCORE_ARR[0]; + if (( $SCORE < ${{inputs.min_score}} )); then echo "The minimum score of ${{inputs.min_score}} was not met!"; exit 1; fi diff --git a/.github/actions/verify_version/action.yaml b/.github/actions/verify_version/action.yaml new file mode 100644 index 000000000..e9c68d084 --- /dev/null +++ b/.github/actions/verify_version/action.yaml @@ -0,0 +1,27 @@ +name: Verify Version Workflow + +inputs: + working_directory: + required: false + type: string + default: "." + +runs: + using: "composite" + + steps: + - name: 📚 Git Checkout + uses: actions/checkout@v3 + + - name: 🎯 Setup Dart + uses: dart-lang/setup-dart@v1 + + - name: 📦 Install Dependencies + shell: ${{ inputs.shell }} + run: dart pub get + working-directory: ${{ inputs.working_directory }} + + - name: 🔎 Verify version + shell: ${{ inputs.shell }} + run: dart run test --run-skipped -t version-verify + working-directory: ${{ inputs.working_directory }} diff --git a/.github/workflows/shorebird_code_push_api.yaml b/.github/workflows/deploy_shorebird_code_push_api.yaml similarity index 64% rename from .github/workflows/shorebird_code_push_api.yaml rename to .github/workflows/deploy_shorebird_code_push_api.yaml index 7fdbd69af..302b1949e 100644 --- a/.github/workflows/shorebird_code_push_api.yaml +++ b/.github/workflows/deploy_shorebird_code_push_api.yaml @@ -1,21 +1,15 @@ -name: shorebird_code_push_api +name: deploy_shorebird_code_push_api concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true on: - pull_request: - paths: - - ".github/workflows/shorebird_code_push_api.yaml" - - "packages/shorebird_code_push_api/lib/**" - - "packages/shorebird_code_push_api/test/**" - - "packages/shorebird_code_push_api/pubspec.yaml" push: branches: - main paths: - - ".github/workflows/shorebird_code_push_api.yaml" + - ".github/workflows/deploy_shorebird_code_push_api.yaml" - "packages/shorebird_code_push_api/lib/**" - "packages/shorebird_code_push_api/test/**" - "packages/shorebird_code_push_api/pubspec.yaml" @@ -26,30 +20,13 @@ env: REGION: us-central1 jobs: - semantic-pull-request: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1 - - build: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1 - with: - working_directory: packages/shorebird_code_push_api - - pana: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/pana.yml@v1 - with: - working_directory: packages/shorebird_code_push_api - deploy: - needs: build - defaults: run: working-directory: packages/shorebird_code_push_api runs-on: ubuntu-latest - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 000000000..e4d1f8f88 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,142 @@ +name: ci + +on: + pull_request: + branches: + - main + +jobs: + semantic_pull_request: + name: ✅ Semantic Pull Request + uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1 + + changes: + runs-on: ubuntu-latest + + permissions: + pull-requests: read + + outputs: + needs_build: ${{ steps.needs_build.outputs.changes }} + needs_pana: ${{ steps.needs_pana.outputs.changes }} + needs_verify: ${{ steps.needs_verify.outputs.changes }} + + name: 👀 Detect Changes + + steps: + - uses: dorny/paths-filter@v2 + name: Pana Detection + id: needs_pana + with: + filters: | + shorebird_cli: + - ./.github/actions/dart_package + - packages/shorebird_cli/** + shorebird_code_push_api: + - ./.github/actions/dart_package + - packages/shorebird_code_push_api/** + shorebird_code_push_api_client: + - ./.github/actions/dart_package + - packages/shorebird_code_push_api_client/** + + - uses: dorny/paths-filter@v2 + name: Build Detection + id: needs_build + with: + filters: | + shorebird_cli: + - ./.github/actions/dart_package + - packages/shorebird_cli/** + - packages/shorebird_code_push_api_client/** + shorebird_code_push_api: + - ./.github/actions/dart_package + - packages/shorebird_code_push_api/** + shorebird_code_push_api_client: + - ./.github/actions/dart_package + - packages/shorebird_code_push_api_client/** + + - uses: dorny/paths-filter@v2 + name: Verify Detection + id: needs_verify + with: + filters: | + shorebird_cli: + - ./.github/actions/dart_package + - packages/shorebird_cli/** + + pana_packages: + needs: changes + if: ${{ needs.changes.outputs.needs_pana != '[]' }} + + continue-on-error: true + + strategy: + matrix: + package: ${{ fromJSON(needs.changes.outputs.needs_pana) }} + + runs-on: ubuntu-latest + + name: 📊 Pana ${{ matrix.package }} + + steps: + - name: 📚 Git Checkout + uses: actions/checkout@v3 + + - name: 📊 Pana ${{ matrix.package }} + uses: ./.github/actions/pana + with: + working_directory: packages/${{ matrix.package }} + + build_packages: + needs: changes + if: ${{ needs.changes.outputs.needs_build != '[]' }} + + strategy: + matrix: + package: ${{ fromJSON(needs.changes.outputs.needs_build) }} + + runs-on: ubuntu-latest + + name: 🎯 Build ${{ matrix.package }} + + steps: + - name: 📚 Git Checkout + uses: actions/checkout@v3 + + - name: 🎯 Build ${{ matrix.package }} + uses: ./.github/actions/dart_package + with: + working_directory: packages/${{ matrix.package }} + + verify_packages: + needs: changes + if: ${{ needs.changes.outputs.needs_verify != '[]' }} + + strategy: + matrix: + package: ${{ fromJSON(needs.changes.outputs.needs_verify) }} + + runs-on: ubuntu-latest + + name: 🔎 Verify ${{ matrix.package }} + + steps: + - name: 📚 Git Checkout + uses: actions/checkout@v3 + + - name: 🔎 Verify ${{ matrix.package }} + uses: ./.github/actions/verify_version + with: + working_directory: packages/${{ matrix.package }} + + ci: + needs: + [semantic_pull_request, pana_packages, build_packages, verify_packages] + if: ${{ always() }} + + runs-on: ubuntu-latest + + steps: + - name: ⛔️ exit(1) on failure + if: ${{ contains(join(needs.*.result, ','), 'failure') }} + run: exit 1 diff --git a/.github/workflows/shorebird_cli.yaml b/.github/workflows/shorebird_cli.yaml deleted file mode 100644 index d67f08685..000000000 --- a/.github/workflows/shorebird_cli.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: shorebird_cli - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -on: - pull_request: - paths: - - ".github/workflows/shorebird_cli.yaml" - - "packages/shorebird_cli/lib/**" - - "packages/shorebird_cli/test/**" - - "packages/shorebird_cli/pubspec.yaml" - push: - branches: - - main - paths: - - ".github/workflows/shorebird_cli.yaml" - - "packages/shorebird_cli/lib/**" - - "packages/shorebird_cli/test/**" - - "packages/shorebird_cli/pubspec.yaml" - -jobs: - semantic-pull-request: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1 - - build: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1 - with: - working_directory: packages/shorebird_cli - - pana: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/pana.yml@v1 - with: - working_directory: packages/shorebird_cli - - verify-version: - defaults: - run: - working-directory: packages/shorebird_cli - - runs-on: ubuntu-latest - - steps: - - name: 📚 Git Checkout - uses: actions/checkout@v2 - - - name: 🎯 Setup Dart - uses: dart-lang/setup-dart@v1 - with: - sdk: "stable" - - - name: 📦 Install Dependencies - run: | - dart pub get - - - name: 🔎 Verify version - run: dart run test --run-skipped -t version-verify diff --git a/.github/workflows/shorebird_code_push_api_client.yaml b/.github/workflows/shorebird_code_push_api_client.yaml deleted file mode 100644 index 31018b264..000000000 --- a/.github/workflows/shorebird_code_push_api_client.yaml +++ /dev/null @@ -1,35 +0,0 @@ -name: shorebird_code_push_api_client - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -on: - pull_request: - paths: - - ".github/workflows/shorebird_code_push_api_client.yaml" - - "packages/shorebird_code_push_api_client/lib/**" - - "packages/shorebird_code_push_api_client/test/**" - - "packages/shorebird_code_push_api_client/pubspec.yaml" - push: - branches: - - main - paths: - - ".github/workflows/shorebird_code_push_api_client.yaml" - - "packages/shorebird_code_push_api_client/lib/**" - - "packages/shorebird_code_push_api_client/test/**" - - "packages/shorebird_code_push_api_client/pubspec.yaml" - -jobs: - semantic-pull-request: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1 - - build: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1 - with: - working_directory: packages/shorebird_code_push_api_client - - pana: - uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/pana.yml@v1 - with: - working_directory: packages/shorebird_code_push_api_client