Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
socheatsok78 committed May 30, 2024
1 parent e75c766 commit 8d23a19
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Flutter Version Management CLI

on:
push:
branches: [main, v*]
pull_request:
branches: [main, v*]
schedule:
# https://crontab.guru/#40_10_*_*_*
- cron: '40 10 * * *'
workflow_dispatch:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest # Apple M1 Silicon
- macos-13 # Intel Mac
- windows-latest
version:
- latest
- 3.1.5
steps:
- uses: actions/checkout@v4

- uses: ./
with:
version: ${{ matrix.version }}

- name: Setup Flutter SDK
run: fvm use stable
- name: Dart version
run: dart --version
- name: Flutter version
run: flutter --version
- name: Flutter doctor
run: flutter doctor

- name: Run hello world
run: |
echo "main() { print('hello world'); }" > hello.dart
dart hello.dart
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
home/
runner/
.setup-flutter/

# Created by https://www.toptal.com/developers/gitignore/api/osx
# Edit at https://www.toptal.com/developers/gitignore?templates=osx

### OSX ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# End of https://www.toptal.com/developers/gitignore/api/osx
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Flutter Actions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# About
Setup Flutter Version Management: A simple CLI to manage Flutter SDK versions.
https://github.com/leoafarias/fvm

## Inputs

The action takes the following inputs:
* `version`: The version of FVM to install. Default: `latest`.

## Usage

Install the latest FVM:

```yml
name: Flutter

on:
push:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Flutter Version Management CLI
uses: flutter-actions/setup-fvm@v1
with:
version: latest

- name: Install Flutter SDK
run: fvm use stable

- name: Print Flutter SDK version
run: fvm flutter --version
```
3 changes: 3 additions & 0 deletions action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
export FVM_VERSION=${1:-"latest"}
exec "${GITHUB_ACTION_PATH}/hacks/install.sh" ${FVM_VERSION}
17 changes: 17 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Setup Flutter Version Management CLI"
description: "Setup the Flutter Version Management CLI, and add it to the PATH"
branding:
icon: "triangle"
color: "blue"
inputs:
version:
description: "The version to install: Default: latest"
required: false
default: "latest"
runs:
using: "composite"
steps:
# Run the action
- name: Setup Flutter Version Management CLI
run: $GITHUB_ACTION_PATH/action.sh ${{ inputs.version }}
shell: bash
17 changes: 17 additions & 0 deletions action_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
export ACTION_TEST_DIR="$(pwd)/.setup-flutter"

# GitHub Context
export GITHUB_ACTION_PATH="$(pwd)"
export GITHUB_ENV="$ACTION_TEST_DIR/.GITHUB_ENV"
export GITHUB_PATH="$ACTION_TEST_DIR/.GITHUB_PATH"

# Runner environment variables
export RUNNER_TOOL_CACHE="$ACTION_TEST_DIR/tool_cache"

# Create mock environment
mkdir -p "$RUNNER_TOOL_CACHE"
touch "$GITHUB_ENV" "$GITHUB_PATH"

# Run the action
./action.sh "$@"
130 changes: 130 additions & 0 deletions hacks/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env bash

# This is a hack of the original script to install FVM
# https://fvm.app/install.sh

# Function to log messages with date and time
log_message() {
echo -e "$1"
}

# Detect OS and architecture
OS="$(uname -s)"
ARCH="$(uname -m)"

# Map to FVM naming
case "$OS" in
Linux*) OS='linux' ;;
Darwin*) OS='macos' ;;
*) log_message "Unsupported OS"; exit 1 ;;
esac

case "$ARCH" in
x86_64) ARCH='x64' ;;
arm64) ARCH='arm64' ;;
armv7l) ARCH='arm' ;;
*) log_message "Unsupported architecture"; exit 1 ;;
esac

# Terminal colors setup
Color_Off='\033[0m' # Reset
Green='\033[0;32m' # Green
Red='\033[0;31m'

success() {
log_message "${Green}$1${Color_Off}"
}

error() {
log_message "${Red}error: $1${Color_Off}" >&2
exit 1
}

# Log detected OS and architecture
log_message "Detected OS: $OS"
log_message "Detected Architecture: $ARCH"

# Check for curl
if ! command -v curl &> /dev/null; then
error "curl is required but not installed."
fi

# Get installed FVM version if exists
INSTALLED_FVM_VERSION=""
if command -v fvm &> /dev/null; then
INSTALLED_FVM_VERSION=$(fvm --version 2>&1) || error "Failed to fetch installed FVM version."
fi

# Define the URL of the FVM binary
if [[ "$1" == "latest" ]]; then
FVM_VERSION=$(curl -s https://api.github.com/repos/leoafarias/fvm/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$FVM_VERSION" ]; then
error "Failed to fetch latest FVM version."
fi
else
FVM_VERSION="$1"
fi

log_message "Installing FVM version $FVM_VERSION."

# Setup installation directory and symlink
FVM_DIR="$RUNNER_TOOL_CACHE/setup-fvm"
FMV_DIR_BIN="$FVM_DIR/bin"
# SYMLINK_TARGET="/usr/local/bin/fvm"


# Create FVM directory if it doesn't exist
mkdir -p "$FVM_DIR" || error "Failed to create FVM directory: $FVM_DIR."

# Check if FVM_DIR exists, and if it does delete it
if [ -d "$FMV_DIR_BIN" ]; then
log_message "FVM bin directory already exists. Removing it."
if ! rm -rf "$FMV_DIR_BIN"; then
error "Failed to remove existing FVM directory: $FMV_DIR_BIN."
fi
fi

# Download FVM
URL="https://github.com/leoafarias/fvm/releases/download/$FVM_VERSION/fvm-$FVM_VERSION-$OS-$ARCH.tar.gz"
if ! curl -L "$URL" -o fvm.tar.gz; then
error "Download failed. Check your internet connection and URL: $URL"
fi


# Extract binary to the new location
if ! tar xzf fvm.tar.gz -C "$FVM_DIR" 2>&1; then
error "Extraction failed. Check permissions and tar.gz file integrity."
fi

# Cleanup
if ! rm -f fvm.tar.gz; then
error "Failed to cleanup"
fi

# Rename FVM_DIR/fvm to FVM_DIR/bin
if ! mv "$FVM_DIR/fvm" "$FMV_DIR_BIN"; then
error "Failed to move fvm to bin directory."
fi

# Create a symlink
# if ! ln -sf "$FMV_DIR_BIN/fvm" "$SYMLINK_TARGET"; then
# error "Failed to create symlink."
# fi

# Add FVM to PATH
export PATH="$FMV_DIR_BIN:$PATH"

# Verify installation
if ! command -v fvm &> /dev/null; then
error "Installation verification failed. FVM may not be in PATH or failed to execute."
fi

INSTALLED_FVM_VERSION=$(fvm --version 2>&1) || error "Failed to verify installed FVM version."
success "FVM $INSTALLED_FVM_VERSION installed successfully."

# --------------------------------
# GitHub Actions
# --------------------------------

# Add FVM to GitHub Actions PATH
echo "$FMV_DIR_BIN" >> $GITHUB_PATH

0 comments on commit 8d23a19

Please sign in to comment.