Skip to content

Commit

Permalink
Add inputs setFlutterRootPath, setPubCachePath and addPubCacheBinToPath.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrishikesh-kadam committed Dec 21, 2021
1 parent 11f96cd commit 0290f5e
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 6 deletions.
97 changes: 96 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ on:
branches: [ main ]
workflow_dispatch:
schedule:
# 12 PM IST / 6:30 GMT every Sunday and Wednesday.
# 12:00 PM IST / 6:30 AM GMT every Sunday and Wednesday.
# GitHub will remove any cache entries that have not been accessed in over 7 days.
- cron: '30 6 * * 0,3'

defaults:
run:
shell: bash

jobs:
test-setup-flutter:
runs-on: ${{ matrix.runner }}
Expand All @@ -22,3 +26,94 @@ jobs:
- uses: actions/checkout@v2
- name: Setup Flutter
uses: ./
- run: flutter --version
shell: pwsh
- run: flutter --version
if: runner.os == 'Windows'
shell: cmd
- run: flutter --version
if: runner.os == 'Windows'
shell: powershell

test-setup-flutter-with-setPubCachePath:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner: [ ubuntu-latest, macos-latest ]
pubCachePath: [ '~/.pub-cache-new' ]
include:
- runner: windows-latest
pubCachePath: '$env:LOCALAPPDATA\NewPub\Cache'
steps:
- uses: actions/checkout@v2
- if: runner.os != 'Windows'
run: mkdir ${{ matrix.pubCachePath }}
- if: runner.os == 'Windows'
shell: pwsh
run: mkdir ${{ matrix.pubCachePath }}
- name: Setup Flutter
uses: ./
with:
setPubCachePath: ${{ matrix.pubCachePath }}
- run: |
set -x
flutter create myapp
cd myapp
flutter pub get
ls $PUB_CACHE/hosted/pub.dartlang.org
test-setup-flutter-with-addPubCacheBinToPath:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- uses: actions/checkout@v2
- name: Setup Flutter
uses: ./
with:
setFlutterRootPath: 'true'
addPubCacheBinToPath: 'true'
- run: dart pub global activate devtools
- if: runner.os != 'Windows'
run: devtools --help
- if: runner.os == 'Windows'
shell: pwsh
run: devtools --help
- run: |
DEFAULT_PUB_CACHE=$(./src/get-pub-cache-path.sh)
echo "::debug::DEFAULT_PUB_CACHE=$DEFAULT_PUB_CACHE"
ls $DEFAULT_PUB_CACHE/global_packages
test-setup-flutter-with-all:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner: [ ubuntu-latest, macos-latest ]
pubCachePath: [ '~/.pub-cache-new' ]
include:
- runner: windows-latest
pubCachePath: '$env:LOCALAPPDATA\NewPub\Cache'
steps:
- uses: actions/checkout@v2
- if: runner.os != 'Windows'
run: mkdir ${{ matrix.pubCachePath }}
- if: runner.os == 'Windows'
shell: pwsh
run: mkdir ${{ matrix.pubCachePath }}
- name: Setup Flutter
uses: ./
with:
setFlutterRootPath: 'true'
setPubCachePath: ${{ matrix.pubCachePath }}
addPubCacheBinToPath: 'true'
- run: dart pub global activate devtools
- if: runner.os != 'Windows'
run: devtools --help
- if: runner.os == 'Windows'
shell: pwsh
run: devtools --help
- run: ls $PUB_CACHE/global_packages
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.1.0] - 2021-12-22
### Added
- Inputs setFlutterRootPath, setPubCachePath and addPubCacheBinToPath.

## [1.0.0] - 2021-12-10
Initial release
65 changes: 62 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,73 @@ steps:
- run: # Run your flutter or dart command here
```
With specific reference -
ref: <br/>
&nbsp; &nbsp; description: 'channel (stable, beta or master), version(2.8.0) or any git reference(2.8.0-3.3.pre).' <br/>
&nbsp; &nbsp; required: false <br/>
&nbsp; &nbsp; default: 'stable' <br/>
```yml
steps:
- uses: actions/checkout@v2
- name: Setup Flutter
uses: hrishikesh-kadam/setup-flutter@v1
with:
ref: beta # or 2.8 or 2.8.0-3.3.pre,
- run: # Run your flutter or dart command here
ref: beta # or 2.8.0 or 2.8.0-3.3.pre,
```
setFlutterRootPath: <br/>
&nbsp; &nbsp; description: 'Set FLUTTER_ROOT to path where Flutter is installed.' <br/>
&nbsp; &nbsp; required: false <br/>
&nbsp; &nbsp; default: 'false' <br/>
```yml
steps:
- uses: actions/checkout@v2
- name: Setup Flutter
uses: hrishikesh-kadam/setup-flutter@v1
with:
setFlutterRootPath: 'true'
```
setPubCachePath: <br/>
&nbsp; &nbsp; description: 'Set PUB_CACHE to desired path, where pub saves dependencies.' <br/>
&nbsp; &nbsp; required: false <br/>
&nbsp; &nbsp; default: '' <br/>
```yml
my-job:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner: [ ubuntu-latest, macos-latest ]
pubCachePath: [ '~/.pub-cache-new' ]
include:
- runner: windows-latest
pubCachePath: '$env:LOCALAPPDATA\NewPub\Cache'
steps:
- uses: actions/checkout@v2
- name: Setup Flutter
uses: hrishikesh-kadam/setup-flutter@v1
with:
setPubCachePath: ${{ matrix.pubCachePath }}
```
addPubCacheBinToPath: <br/>
&nbsp; &nbsp; description: 'Add PUB_CACHE bin to PATH.\n <br/>
&nbsp; &nbsp; &nbsp; &nbsp; Note: On Windows, activated global packages can be run by without specifying <br/>
&nbsp; &nbsp; &nbsp; &nbsp; `dart pub global run` only on pwsh, cmd and powershell.' <br/>
&nbsp; &nbsp; required: false <br/>
&nbsp; &nbsp; default: 'false' <br/>

```yml
steps:
- uses: actions/checkout@v2
- name: Setup Flutter
uses: hrishikesh-kadam/setup-flutter@v1
with:
addPubCacheBinToPath: 'true'
- run: |
dart pub global activate devtools
devtools --help
```
51 changes: 49 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ author: 'Hrishikesh Kadam <[email protected]>'
description: 'Composite GitHub Action to setup and cache the Flutter SDK.'
inputs:
ref:
description: 'channel (stable, beta or master), version(2.8) or any git reference(2.8.0-3.3.pre)'
description: 'channel (stable, beta or master), version(2.8.0) or any git reference(2.8.0-3.3.pre).'
required: false
default: 'stable'
setFlutterRootPath:
description: 'Set FLUTTER_ROOT to path where Flutter is installed.'
required: false
default: 'false'
setPubCachePath:
description: 'Set PUB_CACHE to desired path, where pub saves dependencies.'
required: false
default: ''
addPubCacheBinToPath:
description: 'Add PUB_CACHE bin to PATH.\n
Note: On Windows, activated global packages can be run by without specifying
`dart pub global run` only on pwsh, cmd and powershell.'
required: false
default: 'false'

runs:
using: 'composite'
Expand All @@ -14,24 +28,57 @@ runs:
run: |
echo "FLUTTER_REF_HEAD=$(git ls-remote https://github.com/flutter/flutter ${{ inputs.ref }} | cut -f 1)" >> $GITHUB_ENV
shell: bash

- name: Check if Flutter is cached
id: cache-flutter
uses: actions/cache@v2
with:
path: ${{ runner.tool_cache }}/flutter
key: flutter-${{ runner.os }}-${{ inputs.ref }}-${{ env.FLUTTER_REF_HEAD }}

- name: Clone Flutter repository if not cached
if: steps.cache-flutter.outputs.cache-hit != 'true'
run: |
git clone --branch ${{ inputs.ref }} --depth 1 \
https://github.com/flutter/flutter $RUNNER_TOOL_CACHE/flutter
shell: bash

- name: Set FLUTTER_ROOT on Linux or macOS
if: inputs.setFlutterRootPath == 'true' && runner.os != 'Windows'
run: echo "FLUTTER_ROOT=$RUNNER_TOOL_CACHE/flutter" >> $GITHUB_ENV
shell: bash

- name: Set FLUTTER_ROOT on Windows
if: inputs.setFlutterRootPath == 'true' && runner.os == 'Windows'
run: echo "FLUTTER_ROOT=$env:RUNNER_TOOL_CACHE\flutter" | Out-File -FilePath $env:GITHUB_ENV -Append
shell: pwsh

- name: Add Flutter to PATH
run: echo "$RUNNER_TOOL_CACHE/flutter/bin" >> $GITHUB_PATH
shell: bash

- name: Set PUB_CACHE on Linux or macOS
if: inputs.setPubCachePath != '' && runner.os != 'Windows'
run: |
PUB_CACHE=${{ inputs.setPubCachePath }}
echo "PUB_CACHE=$PUB_CACHE" >> $GITHUB_ENV
shell: bash

- name: Set PUB_CACHE on Windows
if: inputs.setPubCachePath != '' && runner.os == 'Windows'
run: |
$env:PUB_CACHE="${{ inputs.setPubCachePath }}"
echo "PUB_CACHE=$env:PUB_CACHE" | Out-File -FilePath $env:GITHUB_ENV -Append
shell: pwsh

- name: Add PUB_CACHE bin to PATH
if: inputs.addPubCacheBinToPath == 'true'
run: ./src/add-pub-cache-bin-to-path.sh
shell: bash

- run: flutter --version
shell: bash

branding:
icon: 'heart'
color: 'purple'
color: 'blue'
18 changes: 18 additions & 0 deletions src/add-pub-cache-bin-to-path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

if [[ -n $PUB_CACHE ]]; then
if [[ $RUNNER_OS == 'Windows' ]]; then
PUB_CACHE_BIN="$PUB_CACHE\bin"
else
PUB_CACHE_BIN=$PUB_CACHE/bin
fi
else
if [[ $RUNNER_OS == 'Windows' ]]; then
PUB_CACHE_BIN="$LOCALAPPDATA\Pub\Cache\bin"
else
PUB_CACHE_BIN=$HOME/.pub-cache/bin
fi
fi

echo "::debug::Adding $PUB_CACHE_BIN to \$GITHUB_PATH"
echo "$PUB_CACHE_BIN" >> $GITHUB_PATH
11 changes: 11 additions & 0 deletions src/get-pub-cache-path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

if [[ -n $PUB_CACHE ]]; then
echo "$PUB_CACHE"
else
if [[ $RUNNER_OS == 'Windows' ]]; then
echo "$LOCALAPPDATA\Pub\Cache"
else
echo "$HOME/.pub-cache"
fi
fi

0 comments on commit 0290f5e

Please sign in to comment.