Skip to content
Open
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ steps:
- run: flutter --version
```

### Use a custom GitHub token

By default, the action authenticates GitHub API requests with `github.token`.
You can pass a different token if needed:

```yaml
steps:
- name: Clone repository
uses: actions/checkout@v6
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: master
token: ${{ secrets.MY_GITHUB_PAT }}
- run: flutter --version
```

### Apply a patch

Sometimes you find a bug in Flutter and fix it yourself (you're a rockstar!),
Expand Down
8 changes: 8 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ inputs:
description: Git clone source
required: false
default: "https://github.com/flutter/flutter.git"
token:
description: "GitHub token for authenticated GitHub API requests to avoid rate limiting"
required: false
default: ${{ github.token }}

outputs:
CHANNEL:
Expand Down Expand Up @@ -106,6 +110,8 @@ runs:
- name: Set action inputs
id: flutter-action
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
run: |
$GITHUB_ACTION_PATH/setup.sh -p \
-n '${{ inputs.flutter-version }}' \
Expand Down Expand Up @@ -137,6 +143,8 @@ runs:
- name: Run setup script
shell: bash
if: ${{ inputs.dry-run != 'true' && inputs.dry-run != true }}
env:
GITHUB_TOKEN: ${{ inputs.token }}
run: |
$GITHUB_ACTION_PATH/setup.sh \
-n '${{ steps.flutter-action.outputs.VERSION }}' \
Expand Down
9 changes: 8 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ ARCH=""
VERSION=""
VERSION_FILE=""
GIT_SOURCE=""
TOKEN="${GITHUB_TOKEN:-}"

while getopts 'tc:k:d:l:pa:n:f:g:' flag; do
case "$flag" in
Expand Down Expand Up @@ -224,7 +225,13 @@ fi

if [ ! -x "$CACHE_PATH/flutter/bin/flutter" ]; then
if [ "$CHANNEL" = "master" ] || [ "$CHANNEL" = "main" ]; then
git clone -b "$CHANNEL" "$GIT_SOURCE" "$CACHE_PATH/flutter"
if [ -n "$TOKEN" ]; then
GIT_EXTRAHEADER="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 | tr -d '\n')"
git -c "http.${GITHUB_SERVER_URL:-https://github.com}/.extraheader=$GIT_EXTRAHEADER" \
clone -b "$CHANNEL" "$GIT_SOURCE" "$CACHE_PATH/flutter"
else
git clone -b "$CHANNEL" "$GIT_SOURCE" "$CACHE_PATH/flutter"
fi
if [ "$VERSION" != "any" ]; then
git config --global --add safe.directory "$CACHE_PATH/flutter"
(cd "$CACHE_PATH/flutter" && git checkout "$VERSION")
Expand Down