name: 'Meteor Build' description: 'Build Meteor bundle for production or coverage' inputs: type: required: false description: 'production or coverage' default: 'production' reset-meteor: required: false description: 'Reset Meteor' node-version: required: true description: 'Node version' NPM_TOKEN: required: false description: 'NPM token' deno-version: required: true description: 'Deno version' source-hash: required: true description: 'RC cache id (e.g. packages-build-cache-key + meteor apps/meteor archive hash from CI)' runs: using: composite steps: - name: Cache build uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 id: cache-build with: path: /tmp/Rocket.Chat.tar.gz key: ${{ runner.arch }}-${{ runner.os }}-${{ inputs.type }}-rc-build-${{ inputs.source-hash }} - name: Set Swap Space uses: pierotofy/set-swap-space@49819abfb41bd9b44fb781159c033dba90353a7c # v1.0 if: steps.cache-build.outputs.cache-hit != 'true' with: swap-size-gb: 4 - name: Merge dependencies for build shell: bash if: steps.cache-build.outputs.cache-hit != 'true' run: | # Merge dependencies and devDependencies into a new 'dependencies' field cd apps/meteor cp package.json package.json.bak jq '.dependencies = (.dependencies + .devDependencies) | del(.devDependencies)' package.json > package.json.tmp && mv package.json.tmp package.json - name: Setup NodeJS uses: ./.github/actions/setup-node if: steps.cache-build.outputs.cache-hit != 'true' with: node-version: ${{ inputs.node-version }} deno-version: ${{ inputs.deno-version }} cache-modules: true install: true type: 'production' NPM_TOKEN: ${{ inputs.NPM_TOKEN }} # - name: Free disk space # run: | # sudo apt clean # docker rmi $(docker image ls -aq) # df -h - name: Cache vite uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 if: steps.cache-build.outputs.cache-hit != 'true' with: path: ./node_modules/.vite key: vite-local-cache-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('package.json') }} restore-keys: | vite-local-cache-${{ runner.arch }}-${{ runner.os }}- - name: Cache meteor local uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 if: steps.cache-build.outputs.cache-hit != 'true' with: path: ./apps/meteor/.meteor/local key: meteor-local-cache-${{ runner.arch }}-${{ runner.os }}-${{ inputs.type }}-${{ hashFiles('apps/meteor/.meteor/versions') }} restore-keys: | meteor-local-cache-${{ runner.arch }}-${{ runner.os }}-${{ inputs.type }}- - name: Cache meteor uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 if: steps.cache-build.outputs.cache-hit != 'true' with: path: ~/.meteor key: meteor-cache-${{ runner.arch }}-${{ runner.os }}-${{ inputs.type }}-${{ hashFiles('apps/meteor/.meteor/release') }} restore-keys: | meteor-cache-${{ runner.arch }}-${{ runner.os }}-${{ inputs.type }}- - name: Install Meteor shell: bash if: steps.cache-build.outputs.cache-hit != 'true' run: | # Restore bin from cache set +e METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor) METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET") set -e LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor if [ -e $LAUNCHER ] then echo "Cached Meteor bin found, restoring it" sudo cp "$LAUNCHER" "/usr/local/bin/meteor" else echo "No cached Meteor bin found." fi # only install meteor if bin isn't found command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh - name: Versions shell: bash if: steps.cache-build.outputs.cache-hit != 'true' run: | npm --versions yarn -v node -v meteor --version meteor npm --versions meteor node -v git version - uses: rharkor/caching-for-turbo@00a0515f175df9fd2e15c4560144ad5fdbebb0c7 # v2.3.13 - name: Reset Meteor shell: bash if: ${{ steps.cache-build.outputs.cache-hit != 'true' && inputs.reset-meteor == 'true' }} working-directory: ./apps/meteor run: meteor reset - name: Restore packages build uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 with: name: packages-build path: /tmp - name: Unpack packages build shell: bash run: | tar -xzf /tmp/RocketChat-packages-build.tar.gz -C . - name: Build Rocket.Chat shell: bash if: steps.cache-build.outputs.cache-hit != 'true' env: METEOR_PROFILE: 1000 BABEL_ENV: ${{ inputs.type }} run: | # check if BABEL_ENV is set to coverage if [[ $BABEL_ENV == "coverage" ]]; then echo -e "rocketchat:coverage\n" >> ./apps/meteor/.meteor/packages # Inject swc-plugin-coverage-instrument into .swcrc for istanbul-compatible coverage node -e " const fs = require('fs'); const swcrc = JSON.parse(fs.readFileSync('./apps/meteor/.swcrc', 'utf8')); swcrc.jsc.experimental = swcrc.jsc.experimental || {}; swcrc.jsc.experimental.plugins = swcrc.jsc.experimental.plugins || []; swcrc.jsc.experimental.plugins.push(['swc-plugin-coverage-instrument', {}]); fs.writeFileSync('./apps/meteor/.swcrc', JSON.stringify(swcrc, null, 2) + '\n'); " echo "Coverage enabled (SWC istanbul plugin injected)" fi # Restore original package.json so meteor should not copy devDependencies mv apps/meteor/package.json.bak apps/meteor/package.json yarn build:ci declare -a meter_modules_to_remove=( "meteor/babel-compiler/node_modules/@meteorjs/swc-core/.swc/node_modules/@swc/core-darwin-arm64" # Removes 35M "meteor/babel-compiler/node_modules/@meteorjs/swc-core/.swc/node_modules/@swc/core-linux-x64-musl" # Removes 58M "meteor/babel-compiler/node_modules/@meteorjs/swc-core/.swc/node_modules/@swc/core-linux-arm64-musl" # Removes 44M "meteor/babel-compiler/node_modules/typescript" # Removes 31M # "meteor/babel-compiler/node_modules/@babel" # Removes 14M "@rocket.chat/i18n/src" # Removes 16M "typescript" # Removes 19M # "@babel" # Removes 34M - Needed by Minimongo ) du -s /tmp/dist/bundle for dir_path in "${meter_modules_to_remove[@]}"; do path=/tmp/dist/bundle/programs/server/npm/node_modules/${dir_path} if [ -d "$path" ]; then rm -rf "$path" echo "Removed directory: $path" else echo "Path is not a directory or does not exist: $path" fi done # Remove all .d.ts files from node_modules to reduce size # Removes 184M find /tmp/dist/bundle -type f -name "*.d.ts" -delete du -s /tmp/dist/bundle - name: Prepare build shell: bash if: steps.cache-build.outputs.cache-hit != 'true' run: | cd /tmp/dist tar czf /tmp/Rocket.Chat.tar.gz bundle - name: Store build uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: build-${{ inputs.type }} path: /tmp/Rocket.Chat.tar.gz overwrite: true include-hidden-files: true