From f0cc1b536fd0bf5dd3e13bb9b4fb8eb46246a046 Mon Sep 17 00:00:00 2001 From: Nils Reichardt Date: Tue, 7 Mar 2023 18:05:30 +0100 Subject: [PATCH] Add CI for Sharezone CLI (#408) This PR adds a CI for our CLI because with #400 the CLI was excluded from our CI. I have not added the path for our CLI to our `app_ci.yml` because otherwise we would also trigger the integration test and the CI for our app, which is not needed when only modifying our CLI. This makes our CI faster and we don't need to use a `macos` machine for our `test` job here. A side effect is currently that we also run the analyze and test step for our CLI in our app CI. However, I think that is not a big problem (in the future we could add a `exclude-package` argument to the `sz analyze` and `sz test` command to prevent this). --- .github/workflows/cli_ci.yml | 107 ++++++++++++++++++++++++++ .github/workflows/cli_fallback_ci.yml | 46 +++++++++++ 2 files changed, 153 insertions(+) create mode 100644 .github/workflows/cli_ci.yml create mode 100644 .github/workflows/cli_fallback_ci.yml diff --git a/.github/workflows/cli_ci.yml b/.github/workflows/cli_ci.yml new file mode 100644 index 000000000..bf33cf4bf --- /dev/null +++ b/.github/workflows/cli_ci.yml @@ -0,0 +1,107 @@ +# Copyright (c) 2022 Sharezone UG (haftungsbeschränkt) +# Licensed under the EUPL-1.2-or-later. +# +# You may obtain a copy of the Licence at: +# https://joinup.ec.europa.eu/software/page/eupl +# +# SPDX-License-Identifier: EUPL-1.2 + +name: cli-ci + +concurrency: + group: cli-ci-${{ github.head_ref }} + # In order to conserve the use of GitHub Actions, we cancel the running action + # of the previous commit. This means that if you first commit "A" and then + # commit "B" to the pull request a few minutes later, the workflow for commit + # "A" will be cancelled. + cancel-in-progress: true + +on: + pull_request: + types: + - opened + - synchronize + - reopened + # It's important to trigger this workflow again when the pull is changing + # from a draft pull request to a ready for review pull request. + # + # Some jobs are skipped when the pull request is a draft. Therefore, we + # need to trigger these jobs again when the pull request is changing to + # ready for review. + - ready_for_review + paths: + - .fvm/fvm_config.json + - "cli/**" + - ".github/workflows/cli_ci.yml" + - "!**.md" + - "!**.mdx" + - "!**.gitignore" + +env: + CI_CD_DART_SCRIPTS_PACKAGE_PATH: "tools/sz_repo_cli/" + +jobs: + analyze: + runs-on: ubuntu-latest + # In draft PRs we might use TODOs temporarily. + # In this case the analyze pipeline would fail, thus we won't run it. + if: ${{ github.event.pull_request.draft == false }} + steps: + - uses: actions/checkout@v3 + + - name: Set Flutter version from FVM config file to environment variables + uses: kuhnroyal/flutter-fvm-config-action@v1 + + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ env.FLUTTER_VERSION }} + channel: ${{ env.FLUTTER_CHANNEL }} + # Use format expected by FVM. + # Else this won't be recognized as an installed version when setting + # '.../flutter' as the FVM Flutter version cache folder. + cache-path: "${{ runner.tool_cache }}/flutter/:version:" + + - name: Install FVM + run: | + flutter pub global activate fvm + fvm config --cache-path '${{ runner.tool_cache }}/flutter' + + - name: Activate sz_repo_cli package + run: fvm flutter pub global activate --source path "$CI_CD_DART_SCRIPTS_PACKAGE_PATH" + + # So we can just use "sz COMMAND" instead of "dart ../path/to/script.dart ..." + - run: echo $(realpath ./bin) >> $GITHUB_PATH + + - name: Run code analysis via "sz analyze" (formatting, issues, spacing ...) + run: sz analyze --max-concurrent-packages 3 --package-timeout-minutes 15 + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set Flutter version from FVM config file to environment variables + uses: kuhnroyal/flutter-fvm-config-action@v1 + + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ env.FLUTTER_VERSION }} + channel: ${{ env.FLUTTER_CHANNEL }} + # Use format expected by FVM. + # Else this won't be recognized as an installed version when setting + # '.../flutter' as the FVM Flutter version cache folder. + cache-path: "${{ runner.tool_cache }}/flutter/:version:" + + - name: Install FVM + run: | + flutter pub global activate fvm + fvm config --cache-path '${{ runner.tool_cache }}/flutter' + + - name: Activate sz_repo_cli package + run: fvm flutter pub global activate --source path "$CI_CD_DART_SCRIPTS_PACKAGE_PATH" + + # So we can just use "sz COMMAND" instead of "dart ../path/to/script.dart ..." + - run: echo $(pwd)/bin >> $GITHUB_PATH + + - name: Run tests via "sz test" + run: sz test -c 4 diff --git a/.github/workflows/cli_fallback_ci.yml b/.github/workflows/cli_fallback_ci.yml new file mode 100644 index 000000000..072d8ba46 --- /dev/null +++ b/.github/workflows/cli_fallback_ci.yml @@ -0,0 +1,46 @@ +# Copyright (c) 2022 Sharezone UG (haftungsbeschränkt) +# Licensed under the EUPL-1.2-or-later. +# +# You may obtain a copy of the Licence at: +# https://joinup.ec.europa.eu/software/page/eupl +# +# SPDX-License-Identifier: EUPL-1.2 + +# A workaround for GitHub Actions jobs that required and based on a path. +# +# Currently, it's not possible to set a GitHub Action to required which is +# based on path changes. The reason for this that the action is not executed +# when the action does not match the paths. Therefore, merging will be +# blocked. +# +# A workaround is to have a job which the same name. +# +# https://github.com/github/docs/commit/4364076e0fb56c2579ae90cd048939eaa2c18954 + +name: cli-fallback-ci + +on: + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + paths-ignore: + - ".fvm/fvm_config.json" + - "tools/sz_repo_cli/**" + - ".github/workflows/app_ci.yml" + - '!**.md' + - '!**.mdx' + - '!**.gitignore' + +jobs: + test: + runs-on: ubuntu-latest + steps: + - run: 'echo "No test required"' + + analyze: + runs-on: ubuntu-latest + steps: + - run: 'echo "No analyze required"'