test3 #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Flutter Build & Release | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| permissions: | |
| contents: write | |
| checks: write | |
| pull-requests: write | |
| packages: write | |
| env: | |
| WEB_ARTIFACT_NAME: tablemaster-web-prod.zip | |
| IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/tablemaster-mobile-web | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| flutter-version: ['3.38.9'] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: ${{ matrix.flutter-version }} | |
| channel: stable | |
| cache: true | |
| - name: Show Flutter version | |
| run: flutter --version | |
| - name: Check prod config exists | |
| run: test -f config/prod.json | |
| - name: Check Sentry Flutter secret exists | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| env: | |
| SENTRY_DSN: ${{ secrets.SENTRY_DSN_FLUTTER }} | |
| run: test -n "$SENTRY_DSN" | |
| - name: Get dependencies | |
| run: flutter pub get | |
| - name: Run Flutter Analyze | |
| run: flutter analyze | |
| - name: Run Flutter Tests | |
| run: | | |
| set +e | |
| flutter test --machine > flutter-test-output.log 2>&1 | |
| test_exit_code=$? | |
| awk '/^\{/ { print }' flutter-test-output.log > flutter-test-results.json | |
| if [ ! -s flutter-test-results.json ]; then | |
| cat flutter-test-output.log | |
| echo "No valid Flutter JSON test output was generated." | |
| exit 1 | |
| fi | |
| exit "$test_exit_code" | |
| - name: Upload Flutter Test Results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: flutter-test-results | |
| path: | | |
| flutter-test-results.json | |
| flutter-test-output.log | |
| - name: Test Report | |
| if: always() | |
| uses: dorny/test-reporter@v1 | |
| with: | |
| name: Flutter Test Results | |
| path: flutter-test-results.json | |
| reporter: 'flutter-json' | |
| - name: Run Flutter Format Check | |
| run: dart format --set-exit-if-changed . | |
| continue-on-error: true | |
| - name: Build Web Production | |
| env: | |
| SENTRY_DSN: ${{ secrets.SENTRY_DSN_FLUTTER }} | |
| run: > | |
| flutter build web --release | |
| --dart-define-from-file=config/prod.json | |
| --dart-define=SENTRY_DSN="$SENTRY_DSN" | |
| - name: Zip Web Build | |
| run: | | |
| cd build/web | |
| zip -r ../../${WEB_ARTIFACT_NAME} . | |
| - name: Build APK Production | |
| env: | |
| SENTRY_DSN: ${{ secrets.SENTRY_DSN_FLUTTER }} | |
| run: > | |
| flutter build apk --release | |
| --dart-define-from-file=config/prod.json | |
| --dart-define=SENTRY_DSN="$SENTRY_DSN" | |
| - name: Rename APK | |
| run: | | |
| cp build/app/outputs/flutter-apk/app-release.apk tablemaster-prod.apk | |
| - name: Upload workflow artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: flutter-builds | |
| path: | | |
| tablemaster-prod.apk | |
| ${{ env.WEB_ARTIFACT_NAME }} | |
| - name: Create GitHub Release | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| TAG="flutter-prod-${{ github.run_number }}" | |
| TITLE="TableMaster Flutter Prod #${{ github.run_number }}" | |
| gh release create "$TAG" \ | |
| tablemaster-prod.apk \ | |
| "${WEB_ARTIFACT_NAME}" \ | |
| --title "$TITLE" \ | |
| --notes "Build Flutter production depuis main. | |
| Commit: ${{ github.sha }} | |
| Fichiers: | |
| - tablemaster-prod.apk | |
| - ${WEB_ARTIFACT_NAME}" \ | |
| --latest | |
| docker-build-and-push: | |
| name: Build and push web Docker image | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download web artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: flutter-builds | |
| - name: Extract web build | |
| run: | | |
| mkdir -p web-deploy | |
| unzip -q "${WEB_ARTIFACT_NAME}" -d web-deploy | |
| mkdir -p build | |
| mv web-deploy build/web | |
| - name: Normalize image name | |
| run: | | |
| IMAGE_NAME_LOWER=$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]') | |
| echo "IMAGE_NAME_LOWER=$IMAGE_NAME_LOWER" >> $GITHUB_ENV | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push web image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_NAME_LOWER }}:prod | |
| ${{ env.IMAGE_NAME_LOWER }}:${{ github.sha }} | |
| deploy-web: | |
| name: Deploy web to Oracle VPS | |
| runs-on: ubuntu-latest | |
| needs: docker-build-and-push | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Prepare SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.ORACLE_SSH_KEY_B64 }}" | base64 -d > ~/.ssh/oracle_key | |
| chmod 600 ~/.ssh/oracle_key | |
| ssh-keyscan -H ${{ secrets.ORACLE_HOST }} >> ~/.ssh/known_hosts | |
| - name: Copy Docker Compose file | |
| env: | |
| ORACLE_USER: ${{ secrets.ORACLE_USER }} | |
| ORACLE_HOST: ${{ secrets.ORACLE_HOST }} | |
| run: | | |
| set -e | |
| REMOTE_APP_DIR="/opt/tablemaster/prod/TableMasterMobile" | |
| test -n "$ORACLE_USER" | |
| test -n "$ORACLE_HOST" | |
| ssh -i ~/.ssh/oracle_key "$ORACLE_USER@$ORACLE_HOST" "mkdir -p '$REMOTE_APP_DIR'" | |
| scp -i ~/.ssh/oracle_key docker-compose.prod.yml "$ORACLE_USER@$ORACLE_HOST:$REMOTE_APP_DIR/docker-compose.yml" | |
| - name: Deploy with Docker Compose | |
| env: | |
| ORACLE_USER: ${{ secrets.ORACLE_USER }} | |
| ORACLE_HOST: ${{ secrets.ORACLE_HOST }} | |
| GHCR_OWNER: ${{ github.repository_owner }} | |
| GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }} | |
| GHCR_READ_TOKEN: ${{ secrets.GHCR_READ_TOKEN }} | |
| run: | | |
| set -e | |
| REMOTE_APP_DIR="/opt/tablemaster/prod/TableMasterMobile" | |
| test -n "$ORACLE_USER" | |
| test -n "$ORACLE_HOST" | |
| test -n "$GHCR_USERNAME" | |
| test -n "$GHCR_READ_TOKEN" | |
| GHCR_OWNER_LOWER=$(echo "$GHCR_OWNER" | tr '[:upper:]' '[:lower:]') | |
| ssh -i ~/.ssh/oracle_key "$ORACLE_USER@$ORACLE_HOST" << EOF | |
| set -e | |
| cd "$REMOTE_APP_DIR" | |
| export GHCR_OWNER="$GHCR_OWNER_LOWER" | |
| echo "$GHCR_READ_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin | |
| docker compose pull | |
| docker compose up -d | |
| docker image prune -f | |
| docker compose ps | |
| EOF |