~aasg/haunted-blog

49703cc2f0728a7bcf21cd100027ac361ed3a11a — Aluísio Augusto Silva Gonçalves 2 months ago 3bd6c60
ci: Trigger SnowWeb redeployment on successful build
1 files changed, 18 insertions(+), 1 deletions(-)

M .build.yml
M .build.yml => .build.yml +18 -1
@@ 4,6 4,7 @@
image: nixos/latest
packages:
  - nixos.cachix
  - nixos.curl
  - nixos.dnsutils
  - nixos.ipfs
  - nixos.ipfs-cluster


@@ 18,6 19,7 @@ environment:
secrets:
  - cb717add-b052-4389-ba30-1fafaf9c79c7
  - 4e8ea133-31d9-499f-b45c-a20208be2838
  - 97e2208a-0cd8-4894-8fd8-db35b7edb816
tasks:
  - prepare: |
      # Enable flakes.


@@ 34,23 36,38 @@ tasks:
      result=$(realpath result)
      bsdtar -caf ~/site.tar.zst --format=rpax --strip-components=3 "$result"
  - publish: |
      pushd haunted-blog
      head_rev=$(git rev-parse HEAD)
      main_rev=$(git rev-parse master)
      if [[ -z "$head_rev" || "$head_rev" != "$main_rev" ]]; then
        exit 0
      fi
      popd

      set -o pipefail
      shopt -s lastpipe
      export CLUSTER_CREDENTIALS

      # Push to IPFS.
      result=$(realpath result)
      read -r CLUSTER_CREDENTIALS <~/.ipfs-cluster.key
      ipfs-cluster-ctl --host "$cluster_address" \
        add --quieter --recursive --name "$job_name-$JOB_ID" "$result" \
      | tee ~/cid | ipfs cid base32 | read -r cid
      echo "Published to https://$cid.ipfs.dweb.link"

      # Update DNSLink on aasg.name.
      nsupdate -vk ~/.nsupdate.conf <<NSUPDATE
        delete blog.dnslink.aasg.name TXT
        add blog.dnslink.aasg.name 300 TXT "dnslink=/ipfs/$cid"
        send
      NSUPDATE
      echo "Published to /ipns/aasg.name"

      # Trigger a rebuild for aasg.name.
      curl --silent --show-error --fail --cert ~/.snowweb-api-client.pem --request POST https://aasg.name/.snowweb/reload
      echo "Published to https://aasg.name"

      echo "Published to https://$cid.ipfs.dweb.link"
artifacts:
  - site.tar.zst
  - cid