-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
143 lines (126 loc) · 5.81 KB
/
.gitlab-ci.yml
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
stages:
- prepare
- test
- build
- publish
- post-publish
include:
- component: cloud.mathcrowd.cn:2444/agile/frontend/frontend-ci/npm-package@14.0
npm:
stage: publish
only:
- main
tags:
- k8s-runner
script:
- |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
npm config set proxy http://192.168.10.100:88
npm config set https-proxy http://192.168.10.100:88
npm config set registry https://registry.npmjs.org/
echo "*.map" >> .npmignore
sed -i 's|@agile/mathcrowd-geometry-lib|@mathcrowd/mathcrowd-geometry-lib|g' package.json
sed -i 's|https://cloud.mathcrowd.cn:2444/api/v4/projects/68/packages/npm/|https://registry.npmjs.org/|g' package.json
sed -i 's|https://cloud.mathcrowd.cn:2444/agile/frontend/mathcrowd-geometry-lib.git|https://github.com/mathedu4all/mathcrowd-geometry-lib.git|g' package.json
- |
NPM_PACKAGE_NAME=$(node -p "require('./package.json').name")
NPM_PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [[ "$(npm view ${NPM_PACKAGE_NAME} versions)" != *"'${NPM_PACKAGE_VERSION}'"* ]]; then
npm publish --access=public
echo "Successfully published version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} to npmjs registry."
else
echo "Version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} has already been published, so no new version has been published."
fi
github:
stage: post-publish
only:
- main
tags:
- k8s-runner
script:
- echo "Setting up SSH directory and permissions..."
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "Adding GitHub and CI server SSH hosts to known_hosts..."
- ssh-keyscan github.com > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- echo "Adding private keys to SSH..."
- echo "$GITHUB_KEY" > ~/.ssh/github.key
- chmod 400 ~/.ssh/github.key
- echo "Setting HTTP and HTTPS proxy..."
- git config --global http.proxy http://192.168.10.100:88
- git config --global https.proxy http://192.168.10.100:88
- echo "Adding GitHub remote repository..."
- git remote add github git@github.com:mathedu4all/mathcrowd-geometry-lib.git
- echo "Pushing to GitHub..."
- GIT_TRACE=1 GIT_CURL_VERBOSE=1 GIT_SSH_COMMAND='ssh -i ~/.ssh/github.key' git push -f github HEAD:main
trigger-update:
stage: post-publish
only:
- tags
tags:
- k8s-runner
script:
# Extract a few values from package.json
- |
NPM_PACKAGE_NAME=$(node -p "require('./package.json').name")
NPM_PACKAGE_VERSION=$(node -p "require('./package.json').version")
PROJECTS="agile/frontend/pixi-react-lib"
git config --global user.email "bot@mathcrowd.cn"
git config --global user.name "Gitlab CI Bot"
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keyscan $CI_SERVER_SHELL_SSH_HOST > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
echo "$CI_BOT_KEY" > ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa
- |
for project in $PROJECTS
do
response=$(curl --silent --header "PRIVATE-TOKEN: $CI_BOT_TOKEN" "https://cloud.mathcrowd.cn:2444/api/v4/projects?search=$(basename $project)")
project_id=$(node -pe "JSON.parse(process.argv[1])[0].id" "$response")
git clone "git@cloud.mathcrowd.cn:$project.git"
cd $(basename $project)
echo "Updating dependencies for $project\n"
CURRENT_VERSION=$(node -p "require('./package-lock.json').packages[\"node_modules/$NPM_PACKAGE_NAME\"].version")
if [[ "${CURRENT_VERSION}" == "${NPM_PACKAGE_VERSION}" ]]; then echo "${NPM_PACKAGE_NAME} has already been updated to Version ${NPM_PACKAGE_VERSION}." && exit 0; fi
if [[ ! -f .npmrc ]]; then
echo 'No .npmrc found! Creating one now. Please review the following link for more information: https://docs.gitlab.com/ee/user/packages/npm_registry/index.html#project-level-npm-endpoint-1'
{
echo "@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_API_V4_URL}/packages/npm/"
echo "${CI_API_V4_URL#http*:}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
} >> .npmrc
fi
npm config set proxy http://192.168.10.100:88
npm config set https-proxy http://192.168.10.100:88
npm config set registry https://registry.npmjs.org/
npm install ${NPM_PACKAGE_NAME}@${NPM_PACKAGE_VERSION} --save-peer --cache .cache
git checkout -B update-dependencies
git add package.json package-lock.json
git commit -m "update ${NPM_PACKAGE_NAME} to Version ${NPM_PACKAGE_VERSION}"
git push -f --set-upstream origin update-dependencies
curl --header "PRIVATE-TOKEN: ${CI_BOT_TOKEN}" --data "assignee_id=2" --data-urlencode "source_branch=update-dependencies" --data-urlencode "target_branch=main" --data-urlencode "title=Update ${NPM_PACKAGE_NAME} to ${NPM_PACKAGE_VERSION}" "https://cloud.mathcrowd.cn:2444/api/v4/projects/$project_id/merge_requests"
done
github-tags:
stage: post-publish
tags:
- k8s-runner
script:
- echo "Setting up SSH directory and permissions..."
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "Adding GitHub and CI server SSH hosts to known_hosts..."
- ssh-keyscan github.com > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- echo "Adding private keys to SSH..."
- echo "$GITHUB_KEY" > ~/.ssh/github.key
- chmod 400 ~/.ssh/github.key
- echo "Setting HTTP and HTTPS proxy..."
- git config --global http.proxy http://192.168.10.100:88
- git config --global https.proxy http://192.168.10.100:88
- echo "Adding GitHub remote repository..."
- git remote add github git@github.com:mathedu4all/mathcrowd-geometry-lib.git
- echo "Pushing to GitHub..."
- GIT_TRACE=1 GIT_CURL_VERBOSE=1 GIT_SSH_COMMAND='ssh -i ~/.ssh/github.key' git push github --tags
only:
- tags