ci: deploy on tags as well
[web/firmware-selector-openwrt-org.git] / .gitlab-ci.yml
index 5a01f2290d7233138ed2ca0b6a725f324604f5a7..a981f3b7db5792689f53db8a26d435963faeed35 100644 (file)
@@ -5,9 +5,118 @@ include:
 stages:
   - pre-build
   - test
+  - deploy
+
+check HTML, JS, CSS with eslint and prettier:
+  stage: pre-build
+  image: node
+  cache:
+    paths:
+      - node_modules/
+  script:
+    - yarn install
+    - yarn prettier --check www/
+    - yarn eslint www/
 
 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
+  image: python:$CI_PYTHON_VERSION-slim-buster
+  before_script:
+    - apt-get update; apt-get install -y make
+  script:
+    - cp -R ./www ./build
+    - misc/collect.py scrape https://downloads.openwrt.org build
+  artifacts:
+    expire_in: 1 week
+    when: always
+    paths:
+      - build
+
+build site on Python 3.6:
+  extends: .build python
+  variables:
+    CI_PYTHON_VERSION: "3.6"
+
+build site on Python 3.8:
+  extends: .build python
+  variables:
+    CI_PYTHON_VERSION: "3.8"
+
+.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:
+    - /opt/bin/entry_point.sh &
+    - sudo apt-get update; sudo apt-get install -y python3-pip python3-pytest
+    - pip3 install selenium-firefox
+    - (cd build; python3 -m http.server &)
+    - pytest-3 tests
+
+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:
+    - apk update && apk add rsync
+  only:
+    - master
+    - tags
+  script:
+    - 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
+  only:
+    - tags