Commit 61195b6e authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Refactor GitLab pipeline

parent b9f21b52
Loading
Loading
Loading
Loading
+34 −17
Original line number Diff line number Diff line
update submodules:
  stage: build
  except:
    - pushes
.git:
  image:
    name: alpine/git
    entrypoint: [""]
@@ -11,27 +8,47 @@ update submodules:
  before_script:
    - git config user.name "${GITLAB_USER_NAME}"
    - git config user.email "${GITLAB_USER_EMAIL}"
  script:
    - |
      git submodule foreach --recursive '
        branch=`git config -f ~/.gitmodules submodule.${name}.branch`;
        git checkout origin/${branch:-HEAD} || exit 1
        (cd ${toplevel}; exec git add ${path})
      '
    - |
      git diff --cached --no-patch --exit-code ||
      git commit -m "
      Update submodules

      `git status --short -uno`

      MSG_FOOTER="
      Automatically generated:
        source: Gitlab CI
        runner: ${CI_RUNNER_DESCRIPTION} (${CI_RUNNER_VERSION})
        job:    ${CI_JOB_URL} (#${CI_JOB_ID})
        time:   `date`
      "
    - |
      git_commit() {
        while test "$1"; do
          case $1 in
            --) shift; MSG=`printf '%s\n\n' "$@" "$MSG_FOOTER"`; break ;;
            *) CHK="$CHK $1"; shift ;;
          esac
        done
        git diff --no-patch --exit-code $CHK ||
        git commit -m "$MSG"
      }
  after_script:
    - git push
      ${CI_PROJECT_URL/:\/\//:\/\/gitlab-ci-token:${PUSH_TOKEN?PUSH_TOKEN must be defined and allowed for ${CI_COMMIT_REF_NAME}}@}
      HEAD:${CI_COMMIT_REF_NAME}


stages:
  - submodules

workflow:
  rules:
  - if: $CI_PIPELINE_SOURCE != "push"


Update Submodules:
  stage: submodules
  extends: [.git]
  script:
    - |
      git submodule foreach --recursive '
        branch=`git config -f ~/.gitmodules submodule.${name}.branch`;
        git checkout origin/${branch:-HEAD} || exit 1
        (cd ${toplevel}; exec git add ${path})
      '
    - git_commit --cached -- "Update submodules" "`git status --short -uno`"