# @file .gitlab-ci.yml - GitLab CI configuration file. # @author Eddie Roosenmallen # @author Bryan Hoang # @date September 2022 variables: # Can't cache `~/.npm/`. npm_config_cache: '.cache/npm/' npm_config_prefer_offline: 'true' npm_config_fund: 'false' # DCP_BUILD variables only apply when using a gitlab-hosted dcp-client DCP_BUILD: debug DCP_BUILD_BRANCH: develop DCP_BUILD_HOST: 'http://dcp-client-srv.office.distributive.network' DCP_CLIENT_GITLAB: 'gitlab:Distributed-Compute-Protocol/dcp-client#' default: # Use in-house GitLab runners. tags: - dcp-core - linux image: node:lts before_script: - npm add --global npm@latest - npm config set allow-git=all # Access private deps. e.g., `dcp-client` from GitLab. - git config --global url."${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}".insteadOf "${CI_SERVER_URL}" workflow: rules: # Only run branch pipelines for `develop`, or merge request pipelines. - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "merge_request_event" # Allow manually running a branch pipeline without opening an MR first. - if: $CI_PIPELINE_SOURCE == "web" || $CI_PIPELINE_SOURCE == "api" stages: - build - test - deploy # Installs npm dependencies to be cached for subsequent jobs. Also checks that # the lock file is synced with the manifest file. build: stage: build script: - npm clean-install - DCP_CLIENT_VERSION=`node -p "require('./package.json').dependencies['dcp-client']"` - DCP_CLIENT_ORIGIN=`printf "${DCP_CLIENT_GITLAB}"` - | [[ "${DCP_CLIENT_VERSION}" == "gitlab:"* ]] && wget "${DCP_BUILD_HOST}/?dcpClient=${DCP_CLIENT_VERSION//$DCP_CLIENT_ORIGIN/}&build=${DCP_BUILD}" -O node_modules/dcp-client/dist/dcp-client-bundle.js - echo "Done" # Because CI will error if the last command returns with a non-zero exit code... and the above will be unless a specific dcp-client version is required cache: - key: prefix: $CI_JOB_NAME_SLUG files: - package-lock.json paths: - $npm_config_cache - key: prefix: node-modules files: - package-lock.json paths: - node_modules/ policy: push tidelift: stage: build rules: - when: never variables: # This should be kept in a GitLab Variable. Read more: # https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui TIDELIFT_API_KEY: $TIDELIFT_API_KEY inherit: default: - tags # The CLI only requires `glibc`. image: frolvlad/alpine-glibc before_script: - apk add --no-cache curl - echo "Downloading Tidelift CLI" - curl https://download.tidelift.com/cli/tidelift -o tidelift - echo "Setting permissions" - chmod +x tidelift script: - echo "Running alignment and saving to Tidelift" - ./tidelift alignment save --wait allow_failure: true # Run `trunk check` on the project to hightlight newly introduced lint issues # when compared to the target branch. check: allow_failure: true variables: # Can't cache `~/.cache/trunk/`. TRUNK_CACHE: ${CI_PROJECT_DIR}/.cache/trunk/ stage: test script: - UPSTREAM_BRANCH=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-$CI_DEFAULT_BRANCH} # Fetch the branch so that `trunk` has the proper information needed to # determine the upstream changes to compare lint results against. - git fetch origin $UPSTREAM_BRANCH - npm run check -- --ci --upstream origin/$UPSTREAM_BRANCH cache: - key: prefix: $CI_JOB_NAME_SLUG files: - .trunk/trunk.yaml paths: - $TRUNK_CACHE - key: prefix: node-modules files: - package-lock.json paths: - node_modules/ policy: pull test: variables: DCP_CLIENT_ALLOW_INSECURE_CONFIGURATION: true stage: test script: - npx peter -v --junit test_report.xml tests/ cache: - key: prefix: node-modules files: - package-lock.json paths: - node_modules/ policy: pull artifacts: expire_in: 1 day when: always paths: - test_report.xml reports: junit: test_report.xml publish_docs: stage: deploy needs: - build rules: - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH changes: paths: - catalog-info.yaml - docs/ # Symlinked into `docs/`, but changes are only detected for by the # source file.` - README.md variables: AWS_ACCESS_KEY_ID: $BACKSTAGE_ACCESS_KEY AWS_SECRET_ACCESS_KEY: $BACKSTAGE_ACCESS_SECRET AWS_DEFAULT_REGION: 'us-east-1' AWS_REGION: 'us-east-1' TECHDOCS_S3_BUCKET_NAME: 'backstage.distributive.network' ENTITY_NAMESPACE: 'default' image: registry.gitlab.com/distributed-compute-protocol/backstage-ci-image:latest script: - ./publish-docs.sh cache: - key: prefix: node-modules files: - package-lock.json paths: - node_modules/ policy: pull