include:
  - project: 'infra/packages/ci-utils'
    ref: main
    file: 'shared-ci.yml'
  - local: 'gitlabci-version.yml'
#  - project: 'infra/packages/ci-utils'
#    ref: main
#    file: 'debian-binary.yml'

variables:
  PACKAGE_NAME: rocketchat
  UPSTREAM_GITHUB_PATH: RocketChat/Rocket.Chat

autoupdate:
  extends: .autoupdate:github:release-tags

.build:binary:
  extends: .build
  image: registry.git.cccv.de/infra/packages/docker-images/bullseye
  script:
  - git clone --depth 1 --branch ${UPSTREAM_VERSION} https://github.com/RocketChat/Rocket.Chat rocketchat
  - NODEJS_VERSION="$(jq -r .engines.node rocketchat/package.json)"
  - METEOR_VERSION="$(cut -d@ -f2 rocketchat/apps/meteor/.meteor/release)"
  - wget -q "https://deb.nodesource.com/node_14.x/pool/main/n/nodejs/nodejs_${NODEJS_VERSION}-deb-1nodesource1_amd64.deb" -O nodejs.deb
  - apt-get -qq install ./nodejs.deb
  # NodeJS < 14.9.0 did not contain corepack
  - test -e /usr/bin/corepack || npm install -g corepack
  # Install/enable yarn
  - corepack enable
  - rm nodejs.deb
  - wget -q "https://static.meteor.com/packages-bootstrap/${METEOR_VERSION}/meteor-bootstrap-os.linux.x86_64.tar.gz" -O meteor-bootstrap.tar.gz
  # The package only contains an ".meteor" directory that ends up in "/root/.meteor"
  - tar -C ~/ -xzf meteor-bootstrap.tar.gz
  - rm meteor-bootstrap.tar.gz
  - export METEOR_ALLOW_SUPERUSER=true
  - export PATH=$PATH:/root/.meteor
  - meteor --version
  - cd rocketchat && YARN_CHECKSUM_BEHAVIOR=update yarn install --json && git diff yarn.lock && cd ..
  # yarn build:ci uses hard-coded /tmp/dist directory for build output
  - cd rocketchat && yarn build:ci && cd .. && mv /tmp/dist ./build
  - cd build/bundle/programs/server/ && npm install --production && cd ../../../..
  artifacts:
    paths:
    - build

build:binary:bullseye:
  extends: .build:binary

package:apt:bullseye:
  extends: .package:apt
  dependencies:
  - build:binary:bullseye
  needs:
  - build:binary:bullseye

# for now, publish the bullseye package for buster as well
publish:apt:buster:
  extends: .publish:apt
  variables:
    APTLY_DISTRO: buster
  dependencies:
  - package:apt:bullseye
  needs:
  - package:apt:bullseye

publish:apt:bullseye:
  extends: .publish:apt
  variables:
    APTLY_DISTRO: bullseye
  dependencies:
  - package:apt:bullseye
  needs:
  - package:apt:bullseye
