-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish-package.sh
executable file
·76 lines (58 loc) · 1.65 KB
/
publish-package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash -e
setup () {
eval $(ssh-agent -s) && ssh-add <(echo "${SSH_PRIVATE_KEY}") && mkdir -p ~/.ssh
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
git config --global user.email ${GIT_EMAIL}
git config --global user.name ${GIT_NAME}
}
checkout_subtree () {
echo "pushing ${PACKAGE_VERSION}"
git remote add origin ${REPOSITORY} || true
git fetch --unshallow origin || true
git remote add ${PACKAGE} ${REPOSITORY} | true
TEMP_BRANCH=${CI_PIPELINE_ID}_tmp_${PACKAGE_VERSION}
git branch -D ${TEMP_BRANCH} | true
git subtree split --prefix=packages/${PACKAGE} -b ${TEMP_BRANCH}
git checkout ${TEMP_BRANCH}
}
cleanup () {
git checkout origin/${CI_COMMIT_REF_NAME}
git branch -D ${TEMP_BRANCH}
}
publish_tag () {
setup
checkout_subtree
git tag -a ${PACKAGE_VERSION} -m "Version ${PACKAGE_VERSION}"
git push -f ${PACKAGE} refs/tags/${PACKAGE_VERSION}:refs/tags/${PACKAGE_VERSION}
# Delete the tag locally to avoid conflicts
git tag -d ${PACKAGE_VERSION}
cleanup
}
publish_branch () {
setup
checkout_subtree
git push -f ${PACKAGE} ${TEMP_BRANCH}:${CI_COMMIT_REF_NAME}
cleanup
}
delete_branch () {
setup
git remote add ${PACKAGE} ${REPOSITORY} | true
git push ${PACKAGE} --delete ${CI_COMMIT_REF_NAME} || true
}
case "$1" in
"delete-branch")
delete_branch
;;
"branch")
PACKAGE_VERSION="dev-${CI_COMMIT_REF_NAME}"
publish_branch
;;
"tag")
PACKAGE_VERSION=$(cat packages/$PACKAGE/composer.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
publish_tag
;;
*)
echo "Publish 'tag' or 'branch'"
exit 1
;;
esac