From 4c9c1aba05bec65391c0f8d3b6a877729d4a3c00 Mon Sep 17 00:00:00 2001 From: MDLeom <2809763-curben@users.noreply.gitlab.com> Date: Tue, 25 Jan 2022 10:01:07 +0000 Subject: [PATCH] ci(ga): trigger cloudflare & netlify from github if gitlab is down --- .github/workflows/pages.yml | 20 ++++++++++++++++++-- src/gitlab_status.sh | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/gitlab_status.sh diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index f9d46d0e..33158fad 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -8,7 +8,7 @@ on: jobs: pages: runs-on: ubuntu-latest - container: alpine:latest + container: node:lts-alpine steps: - uses: actions/checkout@v2 - name: Install Dependencies @@ -16,7 +16,7 @@ jobs: apk update apk add brotli curl git grep - name: Build - run: sh src/script.sh + run: sh ./src/script.sh - name: Compress run: | find public -type f -regex '.*\.\(txt\|conf\|tpl\|rules\)$' -exec gzip -f -k -9 {} \; @@ -39,3 +39,19 @@ jobs: name: tmp path: ./tmp retention-days: 30 + - name: Cloudflare Pages + env: + CLOUDFLARE_BUILD_HOOK: ${{ secrets.CLOUDFLARE_BUILD_HOOK }} + if: ${{ env.CLOUDFLARE_BUILD_HOOK != 0 && env.GITLAB_STATUS == 'down' }} + run: curl -X POST "https://api.cloudflare.com/client/v4/pages/webhooks/deploy_hooks/${{ env.CLOUDFLARE_BUILD_HOOK }}" + - name: Netlify + env: + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + if: ${{ env.NETLIFY_SITE_ID != 0 && env.GITLAB_STATUS == 'down' }} + run: | + npm install + npm install netlify-cli -g + netlify --telemetry-disable + npm run build + netlify deploy --dir=public --prod diff --git a/src/gitlab_status.sh b/src/gitlab_status.sh new file mode 100644 index 00000000..7465a35d --- /dev/null +++ b/src/gitlab_status.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +CURL_STATUS=$(curl -sSIL "https://gitlab.com/curben/urlhaus-filter/-/nonsense" | grep -F "HTTP/2 200") +GITLAB_STATUS="up" + +if [ -z "$CURL_STATUS" ]; then + GITLAB_STATUS="down" +fi + +echo "GITLAB_STATUS=$GITLAB_STATUS" >> "$GITHUB_ENV"