Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/internal-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }}
Expand Down
18 changes: 18 additions & 0 deletions setup/scripts/install-linux-packages.sh
Original file line number Diff line number Diff line change
@@ -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[@]}"
31 changes: 31 additions & 0 deletions tests/install-linux-packages.test.sh
Original file line number Diff line number Diff line change
@@ -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 <name> <ok|FAIL> <LINUX_PACKAGES value>
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
Loading