Ionic Pro - Package Build fails due to git submodule


#1

It simply skip git submodule setup. Because this, it does not pull out the source code in git submodule and fails to build.

Can any one help please?

Running with gitlab-ci-multi-runner 9.1.0 (0118d89)
  on ip-10-2-214-40 (f537d27d)
Using Shell executor...
Running on ip-10-2-214-40...
Cloning repository...
Cloning into '/home/gitlab-runner/builds/f537d27d/1/thruthesky/philgo-chat'...
Checking out b0b4c52b as master...
Skipping Git submodules setup
$ run "fetch-updates"
Running Stage fetch-updates for Job: 6103900
Checking for build process updates...
$ run "build-android"
Running Stage build-android for Job: 6103900
Parsing ionic.config.json for project settings

While deploy build success with same project and same submodules.

Updating/initializing submodules...
Synchronizing submodule url for 'src/app/modules/...'
Synchronizing submodule url for 'src/app/modules/...'
From https://github.com/thruthesky/...
   e8c5cfe..2ff8703  master     -> origin/master
Submodule path 'src/app/modules/...': checked out '2ff870321bd2abf40ea43cdd3ad0c61fdd710f1d'

#2

As indicated in this Zendesk issue, Submodules are supported now, but only for public repos with no authorization required.

One option suggested in othersimilar issues is to switch from submodules to subtrees.

Finally, if it’s not an option, here is a bash script I came up with as a workaround. I still want to support submodules in my original private repo on Bitbucket, but I don’t care how it is stored on Ionic Pro. So I just create a new temporal branch, copy submodule and include it as a simple directory in the source code. Then I remove .gitmodules file and push the changes to ionic origin. Then I delete the local branch and clean up.

Here is the code that you can save as a shell script and run it each time instead of git push ionic HEAD. But first of all, consider switching to subtrees :slight_smile:

#!/bin/bash

# Prepare repository and push to Ionic Pro
# - checkout a new branch
# - copy submodule to another directory, update its alias in tsconfig.json and commit
#   (we need it because Ionic Pro does not support private submodules yet)
# - push to Ionic Pro and clean up (switch to original branch and delete the new one)

now=$(date +"%m/%d/%Y %H:%M")
original_branch=$(git symbolic-ref --short HEAD)
ionic_origin="ionic"
branch_id=$(date +"%m%d%Y-%H%M%S")
tmp_branch="tmp/$branch_id/$original_branch"
submodule_dir="my-submodule"
target_dir="my-submodule-copy"
commit_msg="Copied submodule for Ionic Pro ($now)"

set -e # exit script if any command fails

printf "Preparing repository for Ionic Pro...\n"

if [ `git branch --list $tmp_branch` ]
then
  printf "  - branch $tmp_branch already exists, deleting it\n"
  git branch -D ${tmp_branch}
fi

printf "  - checking out a new branch $tmp_branch\n"
git checkout -b ${tmp_branch}

printf "  - copying $submodule_dir into $target_dir\n"
cp -r ${submodule_dir} ${target_dir}

printf "  - removing .git directory from the copy\n"
rm -rf ${target_dir}/.git

# this is optional, only if you use TS alias for your submodule! The regex should be updated for your needs
printf "  - replacing @my-submodule alias in tsconfig.json\n"
sed -i "s_\.\.\/${submodule_dir}\/_\.\.\/${target_dir}\/_g" tsconfig.json

printf "  - removing .gitmodules file"
git rm .gitmodules

printf "\nSubmitting...\n"
printf "  - adding changes to git\n"
git add ${target_dir} tsconfig.json

printf "  - committing changes\n"
git commit -m "$commit_msg" > /dev/null

printf "  - pushing changes\n"
git push ${ionic_origin} ${tmp_branch}

printf "\nCleaning up...\n"
printf "  - checking out $original_branch\n"
git checkout ${original_branch} > /dev/null

printf "  - deleting branch $tmp_branch\n"
git branch -D $tmp_branch

printf "\nDone!\n"
printf "  now you can go to Ionic Pro dashboard and build a package for commit with this message:\n    \"$commit_msg\"\n\n"