[CI] Rework app-tests job to use npm as user's packages manager
          
            #564
        
      Workflow file for this run
  
    
      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: App Tests | |
| on: | |
| push: | |
| paths-ignore: | |
| - 'src/*/doc/**' | |
| - 'src/**/*.md' | |
| - 'ux.symfony.com/**' | |
| pull_request: | |
| paths-ignore: | |
| - 'src/*/doc/**' | |
| - 'src/**/*.md' | |
| - 'ux.symfony.com/**' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| encore-app: | |
| name: "Encore (${{ matrix.name}})" | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: Internal, from "vendor/" | |
| ux-packages-source: php-vendor | |
| - name: External, from "npm add" | |
| ux-packages-source: js-packages | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - run: npm i -g corepack && corepack enable | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'pnpm' | |
| cache-dependency-path: | | |
| package.json | |
| src/**/package.json | |
| test_apps/encore-app/package.json | |
| - uses: shivammathur/setup-php@v2 | |
| - name: Install root dependencies | |
| uses: ramsey/composer-install@v3 | |
| with: | |
| working-directory: ${{ github.workspace }} | |
| - name: Build root packages | |
| run: php .github/build-packages.php | |
| # We always install PHP deps because of the UX Translator, which requires `var/translations` to exists | |
| - name: Install PHP dependencies | |
| uses: ramsey/composer-install@v3 | |
| with: | |
| working-directory: test_apps/encore-app | |
| dependency-versions: highest | |
| - name: Manually replacing "workspace:*" references | |
| run: | | |
| # npm does not support "workspace:*" references, so we need to replace them with the actual package path | |
| for PACKAGE_DATA in $(pnpm ls -r --json --depth -1 | jq 'map(select(.private != true))' | jq -c '.[]'); do | |
| PACKAGE=$(echo $PACKAGE_DATA | jq -r '.name') | |
| PACKAGE_PATH=$(echo $PACKAGE_DATA | jq -r '.path') | |
| echo "🔍 Searching for \"workspace:*\" references in $PACKAGE_PATH/package.json" | |
| # Manually replace "workspace:" constraints with the actual package version, it ensure packages can be installed with npm | |
| jq -rc '[(.dependencies // {}) + (.devDependencies // {}) | to_entries[] | select(.value == "workspace:*") | .key][]' "$PACKAGE_PATH/package.json" | while read -r PACKAGE_FROM_WORKSPACE ; do | |
| # Extract the resolved version of the package from the workspace, e.g.: "link:../../../../assets" | |
| echo "ℹ️ Found \"$PACKAGE_FROM_WORKSPACE\" with \"workspace:*\"" | |
| PACKAGE_FROM_WORKSPACE_PATH=$(pnpm ls --filter $PACKAGE_FROM_WORKSPACE --json --depth -1 | jq -r '.[].path') | |
| echo "ℹ️ The package \"$PACKAGE_FROM_WORKSPACE\" is located in \"$PACKAGE_FROM_WORKSPACE_PATH\" directory" | |
| echo "⚒️ Replacing \"$PACKAGE_FROM_WORKSPACE\" with \"file:$PACKAGE_FROM_WORKSPACE_PATH\" in $PACKAGE_PATH/package.json" | |
| sed -i "s|\"$PACKAGE_FROM_WORKSPACE\": \"workspace:\*\"|\"$PACKAGE_FROM_WORKSPACE\": \"file:$PACKAGE_FROM_WORKSPACE_PATH\"|g" "$PACKAGE_PATH/package.json" | |
| done; | |
| done | |
| - working-directory: test_apps/encore-app | |
| run: npm install | |
| - if: matrix.ux-packages-source == 'js-packages' | |
| name: Install UX JS packages with a JS package manager | |
| working-directory: test_apps/encore-app | |
| run: | | |
| PACKAGES_TO_INSTALL='' | |
| for PACKAGE_DATA in $(pnpm ls -r --json --depth -1 | jq 'map(select(.private != true))' | jq -c '.[]'); do | |
| PACKAGE_PATH=$(echo $PACKAGE_DATA | jq -r '.path') | |
| PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL file:$(realpath --relative-to=. "$PACKAGE_PATH")" | |
| done | |
| echo "Installing packages: $PACKAGES_TO_INSTALL" | |
| npm add --save-dev $PACKAGES_TO_INSTALL | |
| - name: Ensure UX packages are installed from "${{ env.EXPECTED_PATTERN }}" | |
| working-directory: test_apps/encore-app | |
| run: | | |
| echo ###; cat package.json | |
| echo ###; cat package.json | jq -c '(.dependencies // {}) + (.devDependencies // {})' | |
| echo ###; cat package.json | jq -c '(.dependencies // {}) + (.devDependencies // {}) || to_entries[]' | |
| echo ###; cat package.json | jq -c '(.dependencies // {}) + (.devDependencies // {}) || to_entries[] | select(.key | startswith("@symfony/ux-"))' | |
| echo ###; cat package.json | jq -c '(.dependencies // {}) + (.devDependencies // {}) || to_entries[] | select(.key | startswith("@symfony/ux-")) | {name: .key, version: .value}' | |
| for PACKAGE in $(cat package.json | jq -c '(.dependencies // {}) + (.devDependencies // {}) | to_entries[] | select(.key | startswith("@symfony/ux-")) | {name: .key, version: .value}'); do | |
| PACKAGE=$(echo $PACKAGE | jq -r '.name') | |
| PACKAGE_VERSION=$(echo $PACKAGE | jq -r '.version') | |
| echo -n "Checking $PACKAGE@$PACKAGE_VERSION..." | |
| if [[ $PACKAGE_VERSION == $EXPECTED_PATTERN* ]]; then | |
| echo " OK" | |
| else | |
| echo " KO" | |
| echo "The package version of $PACKAGE must starts with the pattern (e.g.: $EXPECTED_PATTERN), got $PACKAGE_VERSION instead." | |
| exit 1 | |
| fi | |
| done; | |
| env: | |
| EXPECTED_PATTERN: ${{ matrix.ux-packages-source == 'php-vendor' && 'file:vendor/symfony/*' || 'file:../../src/*' }} | |
| - name: Ensure project can be built in dev mode | |
| working-directory: test_apps/encore-app | |
| run: npm run dev | |
| - name: Ensure project can be built in prod mode | |
| working-directory: test_apps/encore-app | |
| run: npm run build |