diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..7b8c840 --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,110 @@ +name: verify + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + name: ${{ matrix.os }}${{ matrix.label }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + channel: stable + flutter-version: "" + label: " / stable" + - os: macos-latest + channel: stable + flutter-version: "" + label: " / stable" + - os: windows-latest + channel: stable + flutter-version: "" + label: " / stable" + - os: ubuntu-latest + channel: beta + flutter-version: "" + label: " / beta" + - os: ubuntu-latest + channel: "" + flutter-version: "3.44.4" + label: " / pinned 3.44.4" + - os: windows-latest + channel: "" + flutter-version: "3.44.4" + label: " / pinned 3.44.4" + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + + - uses: ./ + with: + flutter-version: ${{ matrix.flutter-version }} + channel: ${{ matrix.channel }} + + - name: Verify Flutter matches the requested version + shell: bash + env: + EXPECTED_CHANNEL: ${{ matrix.channel }} + EXPECTED_VERSION: ${{ matrix.flutter-version }} + run: | + flutter --version 2>&1 | tee /tmp/flutter-version.txt + if [ -n "$EXPECTED_VERSION" ]; then + grep -q "Flutter ${EXPECTED_VERSION} " /tmp/flutter-version.txt || { echo "expected Flutter $EXPECTED_VERSION" >&2; exit 1; } + else + grep -q "channel ${EXPECTED_CHANNEL}" /tmp/flutter-version.txt || { echo "expected channel $EXPECTED_CHANNEL" >&2; exit 1; } + fi + + - name: Verify pub cache location and contents + shell: bash + run: | + echo "PUB_CACHE=$PUB_CACHE" + expected="$HOME/.pub-cache" + if [ "$RUNNER_OS" = "Windows" ]; then + expected="$LOCALAPPDATA/Pub/Cache" + fi + norm() { printf '%s' "$1" | tr '\\' '/' | tr '[:upper:]' '[:lower:]'; } + if [ "$(norm "$PUB_CACHE")" != "$(norm "$expected")" ]; then + echo "expected PUB_CACHE to be $expected" >&2 + exit 1 + fi + test -d "$PUB_CACHE" || { echo "PUB_CACHE directory missing" >&2; exit 1; } + test -d "$PUB_CACHE/hosted" || { echo "no hosted packages cached" >&2; exit 1; } + + - name: Verify pub get resolved http from the pub cache + shell: bash + run: | + test -f .dart_tool/package_config.json + PY=python3 + command -v python3 >/dev/null 2>&1 || PY=python + "$PY" - "$PUB_CACHE" <<'EOF' + import json, os, sys, urllib.parse + pub_cache = os.path.normcase(os.path.realpath(sys.argv[1])) + base = os.path.dirname(os.path.abspath(".dart_tool/package_config.json")) + with open(".dart_tool/package_config.json") as f: + packages = json.load(f)["packages"] + http = next((p for p in packages if p["name"] == "http"), None) + assert http is not None, "http package missing from package_config.json" + root = http["rootUri"] + if "://" in root: + root = urllib.parse.urlparse(root).path + if os.name == "nt" and root.startswith("/"): + root = root[1:] + if not os.path.isabs(root): + root = os.path.join(base, root) + root = os.path.normcase(os.path.realpath(root)) + assert root.startswith(pub_cache), f"{root} not under PUB_CACHE {pub_cache}" + print(f"http resolved under PUB_CACHE ({root})") + EOF diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05d0295 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.dart_tool/ +pubspec.lock diff --git a/README.md b/README.md index fb05260..943af2f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ One composite action for the three-step block every Flutter CI job repeats: install Flutter, restore the pub cache, run `flutter pub get`. Wraps [subosito/flutter-action](https://github.com/subosito/flutter-action) and [actions/cache](https://github.com/actions/cache), with both caches keyed on -`pubspec.lock`. +`pubspec.yaml`. ## Usage diff --git a/action.yml b/action.yml index c21af1e..f27e812 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: Setup Flutter with pub cache -description: Install Flutter, restore the pub cache keyed on pubspec.lock, and run flutter pub get, as a single step. +description: Install Flutter, restore the pub cache keyed on pubspec.yaml, and run flutter pub get, as a single step. branding: icon: download color: blue @@ -23,7 +23,7 @@ runs: flutter-version: ${{ inputs.flutter-version }} channel: ${{ inputs.channel }} cache: true - cache-key: flutter-${{ runner.os }}-${{ hashFiles('pubspec.lock') }} + cache-key: flutter-${{ runner.os }}-${{ hashFiles('pubspec.yaml') }} - name: Cache pub uses: actions/cache@v6 @@ -36,7 +36,7 @@ runs: # instead misses the real cache directory on Windows runners, where # Flutter writes pub packages to %LOCALAPPDATA%\Pub\Cache by default. path: ${{ env.PUB_CACHE }} - key: ${{ runner.os }}-pub-${{ hashFiles('pubspec.lock') }} + key: ${{ runner.os }}-pub-${{ hashFiles('pubspec.yaml') }} restore-keys: | ${{ runner.os }}-pub- diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..3e81818 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,10 @@ +name: setup_flutter_fixture +description: Minimal Flutter fixture used by CI to verify the setup-flutter composite action. +publish_to: none +version: 0.1.0 + +environment: + sdk: ^3.0.0 + +dependencies: + http: ^1.2.0