Skip to content

Commit

Permalink
Add workflow to publish frontend web app and update flutter version u…
Browse files Browse the repository at this point in the history
…pdater script
  • Loading branch information
shubhamsinghshubham777 committed Sep 29, 2024
1 parent c524bfc commit babb49c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/publish_frontend_web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy Flutter Web Frontend

on:
push:
branches:
- main
paths:
- 'core/**'
- 'frontend/**'
workflow_dispatch:

permissions:
contents: write
pages: write
id-token: write

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.24.2'
channel: 'stable'

- name: Get dependencies
working-directory: ./frontend
run: flutter pub get

- name: Run build_runner
working-directory: ./frontend
run: flutter pub run build_runner build --delete-conflicting-outputs

- name: Build web app
working-directory: ./frontend
run: flutter build web

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./frontend/build/web
16 changes: 13 additions & 3 deletions scripts/change_flutter_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ VERSION=$1
change_dir_and_use_fvm() {
local dir=$1
echo "Switching Flutter version in $dir directory..."
cd "$dir" || { echo "Error: Unable to change to the $dir directory."; exit 1; }
cd "../$dir" || { echo "Error: Unable to change to the $dir directory."; exit 1; }
fvm use "$VERSION" || { echo "Error: fvm command failed in $dir. Make sure fvm is installed and the version is available."; exit 1; }
cd ..
}

# Function to update flutter-version in README.md
Expand All @@ -25,13 +24,24 @@ update_readme() {
sed -i '' "s|chmod +x scripts/change_flutter_version.sh; ./scripts/change_flutter_version.sh 3.*|chmod +x scripts/change_flutter_version.sh; ./scripts/change_flutter_version.sh $VERSION|" README.md
}

# Function to update Flutter version in GitHub Actions workflow
update_github_workflow() {
echo "Updating Flutter version in GitHub Actions workflow..."
sed -i '' "s/flutter-version: '.*'/flutter-version: '$VERSION'/" .github/workflows/publish_frontend_web.yaml
}

# Execute for frontend
change_dir_and_use_fvm "frontend"

# Execute for backend
change_dir_and_use_fvm "backend"

cd ..

# Update README.md
update_readme

echo -e "\033[32m✓\033[0m Successfully switched to \033[36mFlutter Version $VERSION\033[0m in both frontend and backend directories and updated the GitHub workflow."
# Update GitHub Actions workflow
update_github_workflow

echo -e "\033[32m✓\033[0m Successfully switched to \033[36mFlutter Version $VERSION\033[0m in both frontend and backend directories, updated the GitHub workflow, and modified the README."

0 comments on commit babb49c

Please sign in to comment.