Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
build-generic.yaml 19.28 KiB
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Huawei Inc.

# This job is documented in docs/ci/hidden-jobs/workspace.rst
.workspace:
  interruptible: true
  image:
    name: registry.ostc-eu.org/ostc/oniro/bitbake-builder:latest
  tags: [large-disk, $CI_ONIRO_RUNNER_TAG, $CI_ONIRO_INSTANCE_SIZE]
  variables:
    CI_ONIRO_RUNNER_TAG : ""
    CI_ONIRO_MANIFEST_URL: https://gitlab.eclipse.org/eclipse/oniro-core/oniro
    CI_ONIRO_MANIFEST_BRANCH: kirkstone
    CI_ONIRO_MANIFEST_NAME: default.xml
    CI_ONIRO_MANIFEST_MIRROR: oniro-develop
    CI_ONIRO_GIT_REPO_PATH: ""
    CI_ONIRO_INSTANCE_SIZE: s3.large.8
  before_script:
    - test ! -e "$CI_PROJECT_DIR"/.scratch-dir-name || (
        echo "precondition failed - concurrent modification of $CI_PROJECT_DIR"
        && env | grep CI_ | sort
        && ls -l
        && exit 1 )

    # Create scratch space, being careful not to pollute the working directory.
    # This is done so that we are not attached to the contents of
    # $CI_PROJECT_DIR which contains something that GitLab CI prepared for us.
    - SCRATCH_DIR="$(mktemp -p /tmp -d workspace.XXXXXXXXXX)"
    - echo "$SCRATCH_DIR" > "$CI_PROJECT_DIR"/.scratch-dir-name
    - cd "$SCRATCH_DIR"

    - |
        set -x
        echo "Building repo workspace with the following properties:"
        echo "CI_ONIRO_MANIFEST_URL: $CI_ONIRO_MANIFEST_URL"
        echo "CI_ONIRO_MANIFEST_NAME: $CI_ONIRO_MANIFEST_NAME"
        echo "CI_ONIRO_MANIFEST_BRANCH: $CI_ONIRO_MANIFEST_BRANCH"
        repo init --reference \
           "$CI_ONIRO_RUNNER_PERSISTENT_STORAGE"/pub/git-repo-mirrors/"$CI_ONIRO_MANIFEST_MIRROR" \
           --manifest-url "$CI_ONIRO_MANIFEST_URL" \
           --manifest-name "$CI_ONIRO_MANIFEST_NAME" \
           --manifest-branch "$CI_ONIRO_MANIFEST_BRANCH"
        set +x
    - time repo sync --no-clone-bundle

    # See the documentation of CI_ONIRO_GIT_REPO_PATH
    - |
      set -x
      if [ -n "$CI_ONIRO_GIT_REPO_PATH" ]; then
        if [ -n "$CI_MERGE_REQUEST_SOURCE_PROJECT_URL" ]; then
            echo "CI: Bootstrapping '$CI_PROJECT_DIR' as 'incoming-merged' remote in '$CI_ONIRO_GIT_REPO_PATH'";
            ( cd "$CI_ONIRO_GIT_REPO_PATH" \
                && git remote add incoming-merged "$CI_MERGE_REQUEST_SOURCE_PROJECT_URL" \
                && git fetch incoming-merged );
        fi;
        echo "CI: Switching $CI_ONIRO_GIT_REPO_PATH to $CI_COMMIT_SHA";
        ( cd "$CI_ONIRO_GIT_REPO_PATH" && git checkout "$CI_COMMIT_SHA" );
      fi
      set +x

  script:
    # Reload the value of SCRATCH_DIR set in the before_script phase. Those run
    # in separate shell processes and do not share environment variables.
    - SCRATCH_DIR="$(cat "$CI_PROJECT_DIR"/.scratch-dir-name)"
    - cd "$SCRATCH_DIR"

  after_script:
    # If the primary script failed early enough, the scratch dir may not have
    # been created yet. Check for that to avoid confusing errors.
    - test -f "$CI_PROJECT_DIR"/.scratch-dir-name || exit 0