diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 746b88f..d2a34e0 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -21,6 +21,11 @@ on: required: false type: string default: "." + linux-packages: + description: "Space-separated apt packages to install on Linux runners before builds" + required: false + type: string + default: "" secrets: token: description: "GitHub token with contents:write permission (defaults to github.token)" @@ -84,6 +89,7 @@ jobs: target: ${{ matrix.target }} flutter-version: ${{ inputs.flutter-version }} working-directory: ${{ inputs.working-directory }} + linux-packages: ${{ inputs.linux-packages }} - name: Upload binary to release uses: svenstaro/upload-release-action@29e53e917877a24fad85510ded594ab3c9ca12de # v2.11.5 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f07cb2a..b3ec7ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,11 @@ on: required: false type: boolean default: false + linux-packages: + description: "Space-separated apt packages to install on Linux runners before tests and builds" + required: false + type: string + default: "" permissions: contents: read @@ -119,6 +124,7 @@ jobs: with: flutter-version: ${{ inputs.flutter-version }} working-directory: ${{ inputs.working-directory }} + linux-packages: ${{ inputs.linux-packages }} - run: | args=("--concurrency=$CONCURRENCY") if [ "$COVERAGE" = "true" ]; then args+=(--coverage); fi @@ -210,6 +216,7 @@ jobs: flutter-version: ${{ inputs.flutter-version }} working-directory: ${{ inputs.working-directory }} build-mode: ${{ needs.setup-matrix.outputs.build-mode }} + linux-packages: ${{ inputs.linux-packages }} - name: Upload build artifact uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: diff --git a/.github/workflows/internal-test.yml b/.github/workflows/internal-test.yml index f8bf5d8..aa5522a 100644 --- a/.github/workflows/internal-test.yml +++ b/.github/workflows/internal-test.yml @@ -80,6 +80,20 @@ jobs: - name: Assert lower bound was installed run: flutter --version | grep -F "Flutter 3.47.1 " + test-setup-linux-packages: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./setup + with: + working-directory: "tests/fixtures" + linux-packages: "pkg-config libx11-dev libxi-dev" + - name: Assert extra packages were installed + run: pkg-config --exists x11 xi + test-matrix: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 550488b..5fcf9e9 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ Sets up Flutter, automatically resolves app metadata from `pubspec.yaml`, instal | `cache` | Cache Flutter SDK artifacts | No | `"true"` | | `working-directory` | Directory containing `pubspec.yaml` | No | `"."` | | `build-mode` | Build compilation mode: `debug`, `profile`, or `release` | No | `"release"` | +| `linux-packages` | Space-separated apt packages to install on top of the linux target's defaults (ignored for other targets) | No | `""` | #### Outputs @@ -105,6 +106,7 @@ Installs the Flutter SDK and runs `flutter pub get`. | `channel` | Flutter release channel | No | `"stable"` | | `cache` | Cache Flutter SDK artifacts | No | `"true"` | | `working-directory` | Directory containing `pubspec.yaml` | No | `"."` | +| `linux-packages` | Space-separated apt packages to install on Linux runners (skipped elsewhere) | No | `""` | #### Usage @@ -113,6 +115,19 @@ Installs the Flutter SDK and runs `flutter pub get`. - run: flutter analyze ``` +#### Linux packages + +Packages whose native code is compiled by Dart build hooks (native assets) build it during `flutter test` too, not only `flutter build`. On a bare Linux runner that fails on missing headers. Install them with `linux-packages`, e.g. for `window_manager` ≥ 0.6: + +```yaml +- uses: dotactions/flutter/setup@v0.1 + with: + linux-packages: "pkg-config clang libgtk-3-dev libx11-dev libxi-dev" +- run: flutter test +``` + +Names must be plain Debian package names (`a-z`, `0-9`, `.`, `+`, `-`), separated by spaces or newlines. Version pins (`pkg=1.0`), apt options and `.deb` paths are rejected. `ci.yml` and `cd.yml` pass the same input through to `setup` and `build`. + ### Verify Generated Files (`verify-generated`) Runs `dart run build_runner build --delete-conflicting-outputs` and fails if that modifies, adds or deletes any file under `working-directory`. This catches stale generated code (Freezed, json_serializable, ...) and generated files that were never committed. @@ -240,6 +255,7 @@ environment: | `concurrency-tests` | Number of concurrent test runners | No | `4` | | `coverage-report` | Post coverage PR comment and status | No | `false` | | `verify-generated` | Fail if `build_runner` output is stale or uncommitted | No | `false` | +| `linux-packages` | Extra apt packages for the test job and Linux builds ([details](#linux-packages)) | No | `""` | \* Provide either `targets` or both `pr-targets` and `push-targets`. An empty array (`'[]'`) skips the build job for that event, e.g. `pr-targets: '[]'` runs only analyze and tests on pull requests. @@ -315,6 +331,7 @@ environment: | `tag` | Target release tag (required unless triggered by a release or tag push) | No | `""` | | `flutter-version` | Flutter SDK version (empty reads `environment.flutter` from `pubspec.yaml`) | No | `""` | | `working-directory` | Directory containing `pubspec.yaml` | No | `"."` | +| `linux-packages` | Extra apt packages for Linux builds ([details](#linux-packages)) | No | `""` | #### Secrets diff --git a/build/action.yml b/build/action.yml index 738ae85..554ed71 100644 --- a/build/action.yml +++ b/build/action.yml @@ -25,6 +25,10 @@ inputs: description: "Build mode: debug, profile, or release" required: false default: "release" + linux-packages: + description: "Space-separated apt packages to install on Linux runners, on top of the ones the linux target always installs (ignored for other targets)" + required: false + default: "" outputs: artifact-name: @@ -64,9 +68,11 @@ runs: - name: Install Linux dependencies if: inputs.target == 'linux' shell: bash - run: | - sudo apt-get update -qq - sudo apt-get install -y -qq clang cmake ninja-build pkg-config libgtk-3-dev libblkid-dev liblzma-dev libglib2.0-dev + env: + LINUX_PACKAGES: >- + clang cmake ninja-build pkg-config libgtk-3-dev libblkid-dev liblzma-dev libglib2.0-dev + ${{ inputs.linux-packages }} + run: bash "${{ github.action_path }}/../setup/scripts/install-linux-packages.sh" - name: Install Dart dependencies shell: bash diff --git a/setup/action.yml b/setup/action.yml index 5822502..9211397 100644 --- a/setup/action.yml +++ b/setup/action.yml @@ -18,6 +18,10 @@ inputs: description: "Directory containing pubspec.yaml" required: false default: "." + linux-packages: + description: "Space-separated apt packages to install on Linux runners" + required: false + default: "" runs: using: "composite" @@ -37,6 +41,13 @@ runs: channel: ${{ inputs.channel }} cache: ${{ inputs.cache == 'true' }} + - name: Install Linux packages + if: inputs.linux-packages != '' && runner.os == 'Linux' + shell: bash + env: + LINUX_PACKAGES: ${{ inputs.linux-packages }} + run: bash "${{ github.action_path }}/scripts/install-linux-packages.sh" + - name: Install Dart dependencies shell: bash working-directory: ${{ inputs.working-directory }} diff --git a/setup/scripts/install-linux-packages.sh b/setup/scripts/install-linux-packages.sh new file mode 100644 index 0000000..434bb0a --- /dev/null +++ b/setup/scripts/install-linux-packages.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# Installs the whitespace-separated apt packages in LINUX_PACKAGES. +# Names come from consumer input and run under sudo, so each one must be a plain Debian +# package name: this blocks apt options (-o...), local .deb paths and shell metacharacters. +set -euo pipefail + +read -r -d '' -a pkgs <<< "${LINUX_PACKAGES:-}" || true +if [ "${#pkgs[@]}" -eq 0 ]; then exit 0; fi + +for pkg in "${pkgs[@]}"; do + if ! [[ "$pkg" =~ ^[a-z0-9][a-z0-9.+-]*$ ]]; then + echo "::error::invalid apt package name '$pkg': use plain Debian package names (a-z, 0-9, '.', '+', '-')" + exit 1 + fi +done + +sudo apt-get update -qq +sudo apt-get install -y -qq -- "${pkgs[@]}" diff --git a/tests/install-linux-packages.test.sh b/tests/install-linux-packages.test.sh new file mode 100644 index 0000000..ab7c826 --- /dev/null +++ b/tests/install-linux-packages.test.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# shellcheck source=.tooling/tests/lib.sh +source "$(dirname "$0")/../.tooling/tests/lib.sh" +only_on linux + +SCRIPT="$REPO_ROOT/setup/scripts/install-linux-packages.sh" +stub sudo + +# install +install() { + new_case + run "$SCRIPT" LINUX_PACKAGES="$3" + if [ "$2" = FAIL ]; then expect_fail "$1" "invalid apt package name"; else expect_ok "$1"; fi +} + +install "empty" ok "" +expect "empty skips apt" "" "$(stub_log)" +install "whitespace only" ok $' \n\t' +expect "whitespace only skips apt" "" "$(stub_log)" + +install "multiple names" ok $' libgtk-3-dev\n libx11-dev\tlibglib2.0-dev g++ ' +expect "installs every name after --" \ + $'sudo apt-get update -qq\nsudo apt-get install -y -qq -- libgtk-3-dev libx11-dev libglib2.0-dev g++' \ + "$(stub_log)" + +for bad in "-oDebug::pkgProblemResolver=1" "foo;bar" "\$(id)" "Foo" "../x.deb" "pkg=1.0"; do + install "rejects '$bad'" FAIL "ok-pkg $bad" + expect "rejects '$bad' before apt runs" "" "$(stub_log)" +done + +finish