From 6f9cc329590348cf55fbfd49ef5eec2f29bec6ea Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 19 Jun 2022 02:35:08 +0200 Subject: [PATCH] c3d2-web: DRY --- hosts/containers/c3d2-web/default.nix | 38 ++++++++++----------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/hosts/containers/c3d2-web/default.nix b/hosts/containers/c3d2-web/default.nix index d3434d37..4350daef 100644 --- a/hosts/containers/c3d2-web/default.nix +++ b/hosts/containers/c3d2-web/default.nix @@ -165,6 +165,14 @@ in # Build at least once touch ${config.users.users.c3d2-web.home}/deploy-pending + status() { + curl -X POST \ + "https://gitea.c3d2.de/api/v1/repos/c3d2/c3d2-web/statuses/$REV?token=${pkgs.c3d2-web.giteaToken}" \ + -H "Accept: application/json" \ + -H "Content-Type: application/json" \ + -d "$1" + } + if [ ! -d c3d2-web ]; then git clone --depth=1 https://gitea.c3d2.de/c3d2/c3d2-web.git cd c3d2-web @@ -187,49 +195,31 @@ in # web set +e - curl -X POST \ - "https://gitea.c3d2.de/api/v1/repos/c3d2/c3d2-web/statuses/$REV?token=${pkgs.c3d2-web.giteaToken}" \ - -H "accept: application/json" \ - -H "Content-Type: application/json" \ - -d "{ \"context\": \"c3d2-web\", \"description\": \"building...\", \"state\": \"pending\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-$REV.txt\"}" + status "{ \"context\": \"c3d2-web\", \"description\": \"building...\", \"state\": \"pending\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-$REV.txt\"}" make -j$(nproc) export DESTDIR=${webroot}/c3d2 \ 2>&1 \ >${webroot}/log/build-$REV.txt if [ $? = 0 ]; then - STATUS="{ \"context\": \"c3d2-web\", \"description\": \"deployed\", \"state\": \"success\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-$REV.txt\"}" + status "{ \"context\": \"c3d2-web\", \"description\": \"deployed\", \"state\": \"success\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-$REV.txt\"}" else - STATUS="{ \"context\": \"c3d2-web\", \"description\": \"build failure\", \"state\": \"failure\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-$REV.txt\"}" + status "{ \"context\": \"c3d2-web\", \"description\": \"build failure\", \"state\": \"failure\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-$REV.txt\"}" fi - curl -X POST \ - "https://gitea.c3d2.de/api/v1/repos/c3d2/c3d2-web/statuses/$REV?token=${pkgs.c3d2-web.giteaToken}" \ - -H "accept: application/json" \ - -H "Content-Type: application/json" \ - -d "$STATUS" git clean -fx # gemini - curl -X POST \ - "https://gitea.c3d2.de/api/v1/repos/c3d2/c3d2-web/statuses/$REV?token=${pkgs.c3d2-web.giteaToken}" \ - -H "accept: application/json" \ - -H "Content-Type: application/json" \ - -d "{ \"context\": \"c3d2-gemini\", \"description\": \"building...\", \"state\": \"pending\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-gemini-$REV.txt\"}" + status "{ \"context\": \"c3d2-gemini\", \"description\": \"building...\", \"state\": \"pending\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-gemini-$REV.txt\"}" make -f Makefile.gemini -j$(nproc) export DESTDIR=${geminiRoot} \ 2>&1 \ >${webroot}/log/build-gemini-$REV.txt if [ $? = 0 ]; then - STATUS="{ \"context\": \"c3d2-gemini\", \"description\": \"deployed\", \"state\": \"success\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-gemini-$REV.txt\"}" + status "{ \"context\": \"c3d2-gemini\", \"description\": \"deployed\", \"state\": \"success\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-gemini-$REV.txt\"}" else - STATUS="{ \"context\": \"c3d2-gemini\", \"description\": \"build failure\", \"state\": \"failure\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-gemini-$REV.txt\"}" + status "{ \"context\": \"c3d2-gemini\", \"description\": \"build failure\", \"state\": \"failure\", \"target_url\": \"https://c3d2-web.serv.zentralwerk.org/log/build-gemini-$REV.txt\"}" fi - curl -X POST \ - "https://gitea.c3d2.de/api/v1/repos/c3d2/c3d2-web/statuses/$REV?token=${pkgs.c3d2-web.giteaToken}" \ - -H "accept: application/json" \ - -H "Content-Type: application/json" \ - -d "$STATUS" set -e done '';