ci: populate GIT_VERSION variable in index.html
[web/firmware-selector-openwrt-org.git] / .gitlab-ci.yml
index a7c5a87aaf08342b7075efee6e672f6c12f0f558..a9537fb042991e3fe8d071cc253d5002688daf3d 100644 (file)
@@ -5,6 +5,7 @@ include:
 stages:
   - pre-build
   - test
+  - deploy
 
 check HTML, JS, CSS with eslint and prettier:
   stage: pre-build
@@ -21,7 +22,7 @@ check HTML, CSS and SVG with html5validator:
   stage: pre-build
   image: cyb3rjak3/html5validator:latest
   script:
-    - html5validator --root www --also-check-css --also-check-svg --show-warnings --log INFO
+    - html5validator --root www --also-check-css --show-warnings --log INFO
 
 .build python:
   stage: pre-build
@@ -47,7 +48,32 @@ build site on Python 3.8:
   variables:
     CI_PYTHON_VERSION: "3.8"
 
-test site with selenium:
+.build site:
+  stage: pre-build
+  image: debian:9
+  before_script:
+    - apt-get update; apt-get install -y make python3 ca-certificates git
+  artifacts:
+    expire_in: 1 week
+    when: always
+    paths:
+      - build
+
+build site for target environment using scrape method:
+  extends: .build site
+  script:
+    - cp -R ./www ./build
+    - sed -i "s;%GIT_VERSION%;$(git describe --tags);" build/index.html
+    - misc/collect.py scrape https://downloads.openwrt.org build
+
+build site for target environment using scan method:
+  extends: .build site
+  script:
+    - cp -R ./www ./build
+    - sed -i "s;%GIT_VERSION%;$(git describe --tags);" build/index.html
+    - misc/collect.py scan downloads.openwrt.org tests/profiles build
+
+.test site:
   stage: test
   image: selenium/standalone-firefox:latest
   script:
@@ -57,11 +83,37 @@ test site with selenium:
     - (cd build; python3 -m http.server &)
     - pytest-3 tests
 
-build site for target environment:
-  stage: test
-  image: debian:9
+test scraped site with selenium:
+  extends: .test site
+  dependencies:
+    - build site for target environment using scrape method
+
+test scaned site with selenium:
+  extends: .test site
+  dependencies:
+    - build site for target environment using scan method
+
+.deploy:
+  stage: deploy
+  image: alpine
+  dependencies:
+    - build site for target environment using scrape method
   before_script:
-    - apt-get update; apt-get install -y make python3
+    - apk update && apk add rsync
+  only:
+    - master
   script:
-    - cp -R ./www ./build
-    - misc/collect.py scrape https://downloads.openwrt.org build
+    - rsync -rlptvz build/ "rsync://firmware_selector@mirror-02.infra.openwrt.org/$RSYNC_TARGET/www/"
+
+deploy to firmware-selector.staging.openwrt.org:
+  extends: .deploy
+  variables:
+    RSYNC_TARGET: firmware-selector-staging-upload
+
+deploy to firmware-selector.openwrt.org:
+  extends: .deploy
+  variables:
+    RSYNC_TARGET: firmware-selector-upload
+  when: manual
+  before_script:
+    - apk update && apk add rsync