invertase / melos

🌋 A tool for managing Dart projects with multiple packages. With IntelliJ and Vscode IDE support. Supports automated versioning, changelogs & publishing via Conventional Commits.
https://melos.invertase.dev/~melos-latest
Apache License 2.0
1.11k stars 198 forks source link

fix: ```melos bootstrap``` does not work correctly in gitlab CI CD #626

Closed meg4cyberc4t closed 8 months ago

meg4cyberc4t commented 8 months ago

Is there an existing issue for this?

Version

3.4.0

Description

I am currently installing CI/CD for my project in gitlab. Here is my code for the moment:

image: "ghcr.io/cirruslabs/flutter:3.16.4"

stages:
  - setup

melos-bootstrap:
  stage: setup
  script:
    - flutter --disable-analytics
    - flutter pub get
    - export PATH="$PATH":"$HOME/.pub-cache/bin"
    - dart pub global activate melos
    - dart run melos bootstrap --sdk-path="/sdks/flutter" --verbose

During the execution of melos bootstrap, the following error occurs for two packages:

Rename failed, path = '/root/.pub-cache/_temp/dirXBDFVA' (OS Error: File exists, errno = 17)
BootstrapException: Failed to install.: editorjs_reader at /builds/mobile-dev/monorepo/applications/new_lxp_mobile/packages/editorjs_reader.
[    14.677s] [lxp_ithub_theme]: Waiting for another flutter command to release the startup lock...
[    14.677s] [lxp_ithub_theme]: Rename failed, path = '/root/.pub-cache/_temp/dirDISVMQ' (OS Error: File exists, errno = 17)

I could assume that the problem is with write permissions, but it's all inside running in the docker container from the root user. Please help me, I don't know why it doesn't work.

On the local machine, melos bootstrap is executed without errors.

Steps to reproduce

  1. Copy my code from description to .gitlab_ci.yml in your gitlab project.
  2. Run it.

Expected behavior

Running melos bootstrap without errors

Screenshots

No response

Additional context and comments

No response

spydon commented 8 months ago

I suggest you try running with an image that is not defaulting to root, for example this one: https://github.com/gmeligio/flutter-docker-image

meg4cyberc4t commented 8 months ago

I changed the image to your link. The same result:

melos bootstrap
  â””> /builds/mobile-dev/monorepo
Running "/home/flutter/sdks/flutter/bin/flutter pub get" in workspace packages...
  ✓ flutter_kinescope_sdk
    â””> applications/new_lxp_mobile/packages/flutter_kinescope_player
  ✓ monorepo_logger
    â””> packages/monorepo_logger
  ✓ monorepo_lint_rules
    â””> packages/monorepo_lint_rules
  ✓ monorepo_remote_configs
    â””> packages/monorepo_remote_configs
[editorjs_reader]: Rename failed, path = '/home/flutter/.pub-cache/_temp/dirCJVRMY' (OS Error: File exists, errno = 17)
  - editorjs_reader
    â””> applications/new_lxp_mobile/packages/editorjs_reader
       â””> Failed to install.
Resolving dependencies...
Rename failed, path = '/home/flutter/.pub-cache/_temp/dirCJVRMY' (OS Error: File exists, errno = 17)
BootstrapException: Failed to install.: editorjs_reader at /builds/mobile-dev/monorepo/applications/new_lxp_mobile/packages/editorjs_reader.
  ✓ monorepo_platforminfo
    â””> packages/monorepo_platforminfo
[lxp_ithub_theme]: Waiting for another flutter command to release the startup lock...
[lxp_ithub_theme]: Rename failed, path = '/home/flutter/.pub-cache/_temp/dirWFZBAI' (OS Error: File exists, errno = 17)
spydon commented 8 months ago

Interesting, any change if you don't run the first pub get (it shouldn't be needed)?

meg4cyberc4t commented 8 months ago

I tried to remove the flutter pub get at the beginning, it doesn't work. I also tried to change PUB_CACHE and ignore dropped dependencies. This error just appears in other dependencies in the repository.

spydon commented 8 months ago

I tried to remove the flutter pub get at the beginning, it doesn't work.

Same behavior as before?

I also tried to change PUB_CACHE and ignore dropped dependencies. This error just appears in other dependencies in the repository.

Can you post one of the pubspecs of your packages and your melos.yaml?

meg4cyberc4t commented 8 months ago

Same behavior as before?

Yes

Can you post one of the pubspecs of your packages and your melos.yaml?

name: monorepo

sdkPath: .fvm/flutter_sdk

packages:
  - packages/*
  - applications/*
  - applications/**/packages/*
  - applications/**/host_features/*
  - applications/**/common_features/*

scripts:
  analyze:
    name: analyze
    run: flutter analyze
name: editorjs_reader
description: Creating widgets that reads the returned data editor.js
version: 0.0.1

environment:
  sdk: ">=3.1.5 <4.0.0"
  flutter: ">=3.16.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_html: ^3.0.0-beta.2
  html2md: ^1.3.1
  json_annotation: ^4.8.1
  markdown_widget: ^2.3.1

flutter:
  uses-material-design: false

dev_dependencies:
  flutter_test:
    sdk: flutter
  alchemist: ^0.7.0
  build_runner: ^2.4.6
  monorepo_lint_rules: any
  json_serializable: ^6.7.1

name: lxp_ithub_theme
description: Theme for the LXP IThub application and related company projects
version: 1.0.0
publish_to: "none"

environment:
  sdk: ">=3.1.3 <4.0.0"
  flutter: ">=3.16.0"

dependencies:
  cross_file_image: any
  monorepo_logger: any
  editorjs_reader: any
  flutter_kinescope_sdk: any
  equatable: ^2.0.5
  flutter:
    sdk: flutter
  flutter_gen: ^5.3.2
  flutter_svg: ^2.0.8
  collection: ^1.17.2
  markdown_widget: ^2.3.1
  json_annotation: ^4.8.1
  webview_flutter: ^4.4.2
  flutter_animate: ^4.3.0
  wolt_modal_sheet: ^0.2.0

dev_dependencies:
  alchemist: ^0.7.0
  build_runner: ^2.4.6
  flutter_gen_runner: ^5.3.2
  flutter_test:
    sdk: flutter
  html2md: ^1.3.1
  monorepo_lint_rules: any
  json_serializable: ^6.7.1

flutter_gen:
  output: lib/src/generated

flutter:
  assets:
    - assets/icons/
    - assets/landings/
    - assets/fonts/
    - assets/licenses/

  uses-material-design: false
  generate: true
  fonts:
    - family: Inter
      fonts:
        - asset: assets/fonts/Inter-Bold.ttf
          weight: 800
        - asset: assets/fonts/Inter-Medium.ttf
          weight: 500
        - asset: assets/fonts/Inter-Regular.ttf
          weight: 400
    - family: LXPIcons
      fonts:
        - asset: assets/fonts/LXPIcons.ttf
spydon commented 8 months ago

If you change editorjs_reader: any to editorjs_reader: ^0.0.1, does it make a difference? I'm not sure how bootstrap handles any when it builds up the pubspec_overrides.yaml.

meg4cyberc4t commented 8 months ago

I changed it, but the behavior is the same

spydon commented 8 months ago

Hmm, what if you remove --sdk-path="/sdks/flutter" from bootstrap? It shouldn't be needed since you seem to have Flutter on your path.

meg4cyberc4t commented 8 months ago

I used it because in melos.yaml has it:

sdkPath: .fvm/flutter_sdk

but in CI, I don't set up fvm, I just use the container image.

If I delete this line and the argument, I get the same behavor...

spydon commented 8 months ago

Ah right, that makes sense. Could you try to replicate this behavior with a smaller repository?

meg4cyberc4t commented 8 months ago

I made a small repository, but I didn't find any errors there. I started removing/moving dependencies to figure out the problem, but other packages started to fall. Added to melos.yaml

command:
  bootstrap:
    runPubGetInParallel: false

and everything worked!