This repository has been archived by the owner on Oct 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
.gitlab-ci.yml
102 lines (84 loc) · 3.96 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
image: docker:stable
stages:
- sync
- build
- deploy
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
services:
- docker:dind
before_script:
# Provide information for debugging.
- docker info
# Install requirements.
- apk --no-cache add git
- apk --no-cache add curl
- apk --no-cache add tree
- apk --no-cache add zip
- apk --no-cache add openssl
- apk --no-cache add openssh-client
# Add SSH info.
- mkdir ~/.ssh
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# Fix Git Submodules.
- rm -rf NX_Sysmodules
- git submodule update --init --recursive
- git remote add github [email protected]:Reisyukaku/ReiNX.git || if [ $? -eq 128 ]; then echo "Tried to add remote, already there."; else exit 1; fi
- git fetch github
- git status
- echo $CI_COMMIT_REF_NAME
# Provide information for debugging.
- tree
build:
stage: build
script:
- docker build -t reinx-builder .
- docker run -a stdout -a stderr --name reinx-builder -v $(pwd):/developer reinx-builder
- mv out ReiNX-Build
artifacts:
name: "reinx-nightly-$CI_COMMIT_SHA"
paths:
- ReiNX-Build/
publish_nightly:
stage: deploy
only:
- master
- tags
dependencies:
- build
script:
- zip -r reinx-nightly-$CI_COMMIT_SHA.zip ReiNX-Build
# These weird YAML syntaxes are to allow special character in the commands.
- >
scp reinx-nightly-$CI_COMMIT_SHA.zip $WEBSERVER_USER@$WEBSERVER:/data/reinx-guide/files/builds
# Create cookie file for our upcoming transfer or curl may throw an error.
- touch /tmp/reinx_build_push_cookie_jar
# Cookie for an admin must be created and there is no default REST API for this.
- >
curl -X POST $BASE_URL/user/login -H 'cache-control: no-cache' -H 'content-type: application/x-www-form-urlencoded' --data "$DRUPAL_LOGIN_POST_DATA" -b /tmp/reinx_build_push_cookie_jar -c /tmp/reinx_build_push_cookie_jar
# We also need CSRF Token.
- >
curl -X GET $BASE_URL/rest/session/token -H 'cache-control: no-cache' -b /tmp/reinx_build_push_cookie_jar -c /tmp/reinx_build_push_cookie_jar > /tmp/reinx_build_push_token
# Print Debug info for node JSON.
- >
echo "{\"_links\" : { \"type\" : { \"href\" : \"$BASE_URL/rest/type/node/build\"} },\"type\" : [{\"target_id\":\"build\"}],\"title\" : [{ \"value\" : \"$CI_COMMIT_TITLE\" }],\"field_build_download\" : [{ \"uri\" : \"$BASE_URL/sites/default/files/builds/reinx-nightly-$CI_COMMIT_SHA.zip\" }],\"field_commit_hash\" : [{ \"value\" : \"$CI_COMMIT_SHA\" }],\"field_branch\" : [{ \"value\" : \"$CI_COMMIT_REF_NAME\" }]}"
# Create build node.
- >
curl -X POST $BASE_URL/node?_format=hal_json -H 'Content-type: application/hal+json' -H 'cache-control: no-cache' -H "X-CSRF-Token: $(cat /tmp/reinx_build_push_token)" -b /tmp/reinx_build_push_cookie_jar -c /tmp/reinx_build_push_cookie_jar --data-binary "{\"_links\" : { \"type\" : { \"href\" : \"$BASE_URL/rest/type/node/build\"} },\"type\" : [{\"target_id\":\"build\"}],\"title\" : [{ \"value\" : \"$CI_COMMIT_TITLE\" }],\"field_build_download\" : [{ \"uri\" : \"$BASE_URL/sites/default/files/builds/reinx-nightly-$CI_COMMIT_SHA.zip\" }],\"field_commit_hash\" : [{ \"value\" : \"$CI_COMMIT_SHA\" }],\"field_branch\" : [{ \"value\" : \"$CI_COMMIT_REF_NAME\" }]}"
# Clean up for security's sake.
- rm /tmp/reinx_build_push_cookie_jar
- rm /tmp/reinx_build_push_token
sync_with_github:
stage: sync
only:
- master
- tags
script:
- git checkout master
- git pull origin master
- git push -u github master