From 0cb988b06fb47a65c7049e48efdec3b48da11619 Mon Sep 17 00:00:00 2001 From: armantorkzaban Date: Thu, 8 Sep 2022 13:31:17 +0200 Subject: [PATCH] githubt/workflows --- .github/workflows/dart-pub-publish-on-pr.yaml | 35 +++++++++++ .github/workflows/dart-pub-publish.yml | 53 +++++++++++++++++ .github/workflows/dart-unit-tests-on-pr.yml | 43 ++++++++++++++ .github/workflows/dart-unit-tests.yml | 41 +++++++++++++ .../workflows/pr-code-coverage-reporting.yml | 58 +++++++++++++++++++ 5 files changed, 230 insertions(+) create mode 100644 .github/workflows/dart-pub-publish-on-pr.yaml create mode 100644 .github/workflows/dart-pub-publish.yml create mode 100644 .github/workflows/dart-unit-tests-on-pr.yml create mode 100644 .github/workflows/dart-unit-tests.yml create mode 100644 .github/workflows/pr-code-coverage-reporting.yml diff --git a/.github/workflows/dart-pub-publish-on-pr.yaml b/.github/workflows/dart-pub-publish-on-pr.yaml new file mode 100644 index 0000000..a7cee2b --- /dev/null +++ b/.github/workflows/dart-pub-publish-on-pr.yaml @@ -0,0 +1,35 @@ +name: Dart pub publish --dry-run, Publishing Preview for PRs +on: + pull_request: + branches: + - releases +jobs: + preview-publish: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: dart-lang/setup-dart@v1 + with: + sdk: stable + + - name: Print Dart SDK version + run: dart --version + + - name: Install dependencies + run: dart pub get + + - name: Verify formatting + run: dart format --output=none --set-exit-if-changed . + + - name: Analyze project source + run: dart analyze + if: always() + + - name: Run build_runner + run: dart run build_runner build --delete-conflicting-outputs + if: always() + + - name: Preview publish package (dry-run) + run: dart pub publish --dry-run diff --git a/.github/workflows/dart-pub-publish.yml b/.github/workflows/dart-pub-publish.yml new file mode 100644 index 0000000..45a51e4 --- /dev/null +++ b/.github/workflows/dart-pub-publish.yml @@ -0,0 +1,53 @@ +name: Publish package to pub.dev +on: + push: + branches: + - releases +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: dart-lang/setup-dart@v1 + with: + sdk: stable + + - name: Print Dart SDK version + run: dart --version + + - name: Install dependencies + run: dart pub get + + - name: Verify formatting + run: dart format --output=none --set-exit-if-changed . + + - name: Analyze project source + run: dart analyze + if: always() + + - name: Run build_runner + run: dart run build_runner build --delete-conflicting-outputs + if: always() + + - name: Setup credentials + env: + OAUTH_ACCESS_TOKEN: ${{ secrets.OAUTH_ACCESS_TOKEN }} + OAUTH_REFRESH_TOKEN: ${{ secrets.OAUTH_REFRESH_TOKEN }} + OAUTH_EXPIRATION: ${{ secrets.OAUTH_EXPIRATION }} + run: | + mkdir -p ~/.pub-cache + cat < ~/.pub-cache/credentials.json + { + "accessToken":"${OAUTH_ACCESS_TOKEN}", + "refreshToken":"${OAUTH_REFRESH_TOKEN}", + "tokenEndpoint":"https://accounts.google.com/o/oauth2/token", + "scopes": [ "openid", "https://www.googleapis.com/auth/userinfo.email" ], + "expiration": ${OAUTH_EXPIRATION} + } + EOF + + - name: Publish package + run: dart pub publish --force + if: always() diff --git a/.github/workflows/dart-unit-tests-on-pr.yml b/.github/workflows/dart-unit-tests-on-pr.yml new file mode 100644 index 0000000..10e4a4f --- /dev/null +++ b/.github/workflows/dart-unit-tests-on-pr.yml @@ -0,0 +1,43 @@ +name: Dart Unit Tests for PRs + +on: + pull_request: + branches: ["**"] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: dart-lang/setup-dart@v1 + with: + sdk: stable + + - name: Print Dart SDK version + run: dart --version + + - name: Install dependencies + run: dart pub get + + - name: Verify formatting + run: dart format --output=none --set-exit-if-changed . + + - name: Analyze project source + run: dart analyze + if: always() + + - name: Run build_runner + run: dart run build_runner build --delete-conflicting-outputs + if: always() + + - name: Run tests with coverage enabled + run: dart test --coverage=./coverage + if: always() + + - name: Archive raw coverage artifacts + if: always() + uses: actions/upload-artifact@v2 + with: + name: raw-coverage + path: ./coverage diff --git a/.github/workflows/dart-unit-tests.yml b/.github/workflows/dart-unit-tests.yml new file mode 100644 index 0000000..47784bb --- /dev/null +++ b/.github/workflows/dart-unit-tests.yml @@ -0,0 +1,41 @@ +name: Dart Unit Tests + +on: + push: + branches: [main] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + sdk: [stable] + steps: + - uses: actions/checkout@v2 + + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ matrix.sdk }} + + - name: Print Dart SDK version + run: dart --version + + - name: Install dependencies + run: dart pub get + + - name: Verify formatting + run: dart format --output=none --set-exit-if-changed . + + - name: Analyze project source + run: dart analyze + if: always() + + - name: Run build_runner + run: dart run build_runner build --delete-conflicting-outputs + if: always() + + - name: Run tests + run: dart test + if: always() diff --git a/.github/workflows/pr-code-coverage-reporting.yml b/.github/workflows/pr-code-coverage-reporting.yml new file mode 100644 index 0000000..a632247 --- /dev/null +++ b/.github/workflows/pr-code-coverage-reporting.yml @@ -0,0 +1,58 @@ +name: Pull Request Code Coverage Reporting +on: + workflow_run: + workflows: ["Dart Unit Tests for PRs"] + types: [completed] + +jobs: + coverage-reporting: + if: > + ${{ github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: dart-lang/setup-dart@v1 + with: + sdk: stable + + - name: Print Dart SDK version + run: dart --version + + - name: Install dependencies + run: dart pub get + + - name: Download raw coverage from tests workflow + uses: dawidd6/action-download-artifact@v2.16.0 + with: + workflow: dart-unit-tests-on-pr.yml + run_id: ${{ github.event.workflow_run.id }} + name: raw-coverage + path: ./coverage + + - name: Convert to LCOV report + run: | + dart pub global activate coverage + dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o ./coverage/lcov.info -i ./coverage + + - name: Generate HTML coverage report + run: | + sudo apt install lcov + genhtml -o ./coverage/report ./coverage/lcov.info + + - name: Comment on PR with coverage + continue-on-error: true + uses: romeovs/lcov-reporter-action@v0.2.21 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + lcov-file: ./coverage/lcov.info + + - name: Archive coverage report + if: always() + uses: actions/upload-artifact@v2 + with: + name: coverage-report + path: | + ./coverage/report + ./coverage/lcov.info