-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
.gitlab-ci.yml
150 lines (126 loc) · 5.2 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
144
145
146
147
148
149
150
image: ruby:2.3
stages:
- test
- deploy
variables:
OUT_DIR: build
STAGING_URL: $CI_COMMIT_REF_NAME-$CI_PROJECT_NAME-$CI_PROJECT_NAMESPACE.surge.sh
# Common steps required for each type of "Build" (f-droid.org, GitLab Pages, feature branches)
.setup_for_jekyll: &setup_for_jekyll |
ruby -v
apt-get update
apt-get install -y locales
echo "en_US UTF-8" > /etc/locale.gen
locale-gen en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8
apt-get install -y zlib1g-dev
gem install jekyll bundler
bundle install --path vendor
#
# This is a manual task for building in preperation to deploy to
# https://f-droid.org. The intention is for it to be run locally using
# `gitlab-runner` each time a tag is found that is signed by a key in
# the whitelist keyring. Invoke like so:
#
# gitlab-runner exec docker f-droid.org --pre-build-script ./prepare-for-deploy.py \
# --docker-volumes "/root/deploy-whitelist-keyring.gpg:/root/.gnupg/pubring.gpg:ro" \
# --docker-volumes `pwd`/_site:/builds/output --env DEPLOY_DIR=/builds/output
#
# And when it is finished, you should have a directory in _site/build/
# which includes the entire static site ready to be deployed to
# https://f-droid.org.
#
f-droid.org:
stage: deploy
when: manual
cache:
paths: [ vendor/ruby ]
script:
- '[ ! -d "$DEPLOY_DIR" ] && echo "DEPLOY_DIR env variable must point to a directory" && exit 1'
- *setup_for_jekyll
- 'echo "url: https://f-droid.org" > userconfig.yml'
- 'echo "baseurl: \"\"" >> userconfig.yml'
- echo "Additional Jekyll config used for CI:" && cat userconfig.yml
- bundle exec jekyll build -d $OUT_DIR --config _config.yml,userconfig.yml --verbose --trace
- ./tools/prepare-multi-lang.sh $OUT_DIR
- cp -r $OUT_DIR $DEPLOY_DIR/
build:
stage: test
except: [ master ]
cache:
paths: [ vendor/ruby ]
artifacts:
paths: [ $OUT_DIR ]
script:
- *setup_for_jekyll
- 'echo "url: https://$STAGING_URL" > userconfig.yml'
- 'echo baseurl: /$CI_PROJECT_NAME >> userconfig.yml'
- echo "Additional Jekyll config used for CI:" && cat userconfig.yml
- bundle exec jekyll build -d $OUT_DIR/$CI_PROJECT_NAME --config _config.yml,userconfig.yml --verbose --trace
- ./tools/prepare-multi-lang.sh $OUT_DIR/$CI_PROJECT_NAME --no-multi-views
# This deploys feature branches to https://surge.sh, a free static site hosting service.
# See CONTRIBUTING.md for details of how to configure your GitLab project to enable this.
# Ideally we would use GitLab pages for this, but until they suupport deploying feature
# branches alongside master branches (https://gitlab.com/gitlab-org/gitlab-pages/issues/33)
# this is the next best option.
#
# Note that although we are building the entire F-Droid repo in the `build` stage, this `preview`
# stage only builds the GP repo. This is because i18n versions of f-droid.org increase the size
# well beyond the 100MiB limit of surge.sh.
preview:
stage: deploy
except: [ master ]
# This is allowed to fail because only those who have setup $SURGE_LOGIN and $SURGE_TOKEN
# as GitLab secret variables (see CONTRIBUTING.md) are able to preview like this.
allow_failure: true
script:
- *setup_for_jekyll
- 'echo "url: https://$STAGING_URL" > userconfig.yml'
- 'echo baseurl: /$CI_PROJECT_NAME >> userconfig.yml'
- 'echo fdroid-repo: https://guardianproject.info/fdroid/repo >> userconfig.yml'
- echo "Additional Jekyll config used for CI:" && cat userconfig.yml
- bundle exec jekyll build -d $OUT_DIR/$CI_PROJECT_NAME --config _config.yml,userconfig.yml --verbose --trace
- ./tools/prepare-multi-lang.sh $OUT_DIR/$CI_PROJECT_NAME --no-multi-views
- apt-get install -y npm
- npm install -g surge
- update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
- surge --project $OUT_DIR --domain $STAGING_URL
environment:
# Should ideally use $STAGING_URL here, but seems custom variables aren't supported.
url: https://$CI_COMMIT_REF_NAME-$CI_PROJECT_NAME-$CI_PROJECT_NAMESPACE.surge.sh/$CI_PROJECT_NAME
name: review/$CI_COMMIT_REF_NAME
on_stop: teardown_preview
teardown_preview:
stage: deploy
image: node:wheezy
except: [ master ]
when: manual
variables:
GIT_STRATEGY: none
# This is allowed to fail because only those who have setup $SURGE_LOGIN and $SURGE_TOKEN
# as GitLab secret variables (see CONTRIBUTING.md) are able to preview like this.
allow_failure: true
script:
- npm install -g surge
- surge teardown $STAGING_URL
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
pages:
stage: deploy
only: [ master ]
cache:
paths: [ vendor/ruby ]
artifacts:
paths: [ public ]
script:
- *setup_for_jekyll
# This is where GitLab pages will deploy to by default (e.g. "https://fdroid.gitlab.io/fdroid-website")
# so we need to make sure that the Jekyll configuration understands this.
- 'echo url: https://$CI_PROJECT_NAMESPACE.gitlab.io > userconfig.yml'
- 'echo baseurl: /$CI_PROJECT_NAME >> userconfig.yml'
- echo "Additional Jekyll config used for CI:" && cat userconfig.yml
- bundle exec jekyll build -d public --config _config.yml,userconfig.yml
- ./tools/prepare-multi-lang.sh public/$CI_PROJECT_NAME --no-multi-views