Commit eadfd460 authored by Ruben ten Hove's avatar Ruben ten Hove
Browse files

ci: deploy to netlify

parent 3d06f8ba
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,3 +5,4 @@
__pycache__
.coverage
.DS_Store
.netlify

netlify.sh

0 → 100644
+47 −0
Original line number Diff line number Diff line
#!/usr/bin/env sh

set -e

if [ "${NETLIFY}" = "true" ]; then
    rm -rf templates public

    git clone https://gitlab.com/just-ci/templates.git
    mkdir -p public

    cd templates

    GIT_TAGS=$(git tag --format "%(refname:strip=1)") # Produces list with 'tags/' prefix
    GIT_BRANCHES=$(git branch -r --format "%(refname:strip=3)")

    for GIT_REF in ${GIT_TAGS} ${GIT_BRANCHES}; do
        printf "[*] Processing ${GIT_REF}..."
        git checkout ${GIT_REF} -q

        FILES=$(grep -rl "\- local: " . --exclude-dir=tests --exclude=.gitlab-ci.yml --exclude=pages-templates.yaml)
        printf "$(echo ${FILES} | wc -w) file(s)..."

        GIT_REF_NAME=${GIT_REF#tags/}
        echo ${FILES} | xargs sed -i "s|- local: \"|- remote: \"${BASE_URL}/${GIT_REF_NAME}/|g"
        echo ${FILES} | xargs sed -i "s|- local: |- remote: ${BASE_URL}/${GIT_REF_NAME}/|g"
        cp -r . /opt/build/repo/public/${GIT_REF_NAME}
        rm -rf /opt/build/repo/public/${GIT_REF_NAME}/.git

        git reset --hard -q
        echo "done."
    done

    echo "[*] Removing files not used by end users..."

    rm -rf /opt/build/repo/public/*/tests
    find /opt/build/repo/public -type f ! -name "*.yaml" ! -name "*.yml" -delete
    find /opt/build/repo/public -type f -name ".gitlab-ci.yml" -delete
    find /opt/build/repo/public -type f -name ".yamllint.yml" -delete
    find /opt/build/repo/public -type f -name ".pre-commit-config.yaml" -delete
    find /opt/build/repo/public -type d -empty -delete

    cd /opt/build/repo/public

    tree -H '.' --noreport --dirsfirst -T "${PAGES_TEMPLATES_NAME:-Templates}" --charset utf-8 -o index.html .

    echo "[*] Publishing $(echo $GIT_TAGS | wc -w) tags and $(echo $GIT_BRANCHES | wc -w) branches to ${BASE_URL}..."
fi

netlify.toml

0 → 100644
+6 −0
Original line number Diff line number Diff line
[build]
  command = "netlify.sh"
  publish = "public"

[build.environment]
  BASE_URL = "https://jobs.just-ci.dev"