Skip to content

Commit

Permalink
ci: monorepo workflow setup (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Mar 6, 2023
1 parent 8824673 commit 613f57c
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 118 deletions.
65 changes: 65 additions & 0 deletions .github/actions/dart_package/action.yaml
Original file line number Diff line number Diff line change
@@ -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}}
34 changes: 34 additions & 0 deletions .github/actions/pana/action.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .github/actions/verify_version/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

Expand Down
142 changes: 142 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -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
58 changes: 0 additions & 58 deletions .github/workflows/shorebird_cli.yaml

This file was deleted.

Loading

0 comments on commit 613f57c

Please sign in to comment.