~aasg/haunted-blog

ref: e20dc282fae04bd2f99bd8001f203a7c5b498dce haunted-blog/.build.yml -rw-r--r-- 2.2 KiB
e20dc282 — Aluísio Augusto Silva Gonçalves posts/lri-log-2021w21: New post a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# SPDX-FileCopyrightText: 2020 Aluísio Augusto Silva Gonçalves <https://aasg.name>
# SPDX-License-Identifier: MIT

image: nixos/latest
packages:
  - nixos.cachix
  - nixos.curl
  - nixos.dnsutils
  - nixos.ipfs
  - nixos.ipfs-cluster
  - nixos.libarchive
  - nixos.nixUnstable
  - nixos.reuse
sources:
  - https://git.sr.ht/~aasg/haunted-blog
environment:
  job_name: haunted-blog
  cluster_address: /dnsaddr/c.ipfs.aasg.name
secrets:
  - cb717add-b052-4389-ba30-1fafaf9c79c7
  - 4e8ea133-31d9-499f-b45c-a20208be2838
  - 97e2208a-0cd8-4894-8fd8-db35b7edb816
tasks:
  - prepare: |
      # Enable flakes.
      mkdir -p ~/.config/nix
      echo 'experimental-features = nix-command flakes' >~/.config/nix/nix.conf
      # Haunt is not yet in Nixpkgs, so use our prebuilt derivation.
      cachix use aasg-nixexprs
  - check: |
      # Verify that the source is REUSE-compliant.
      reuse --root=haunted-blog lint
  - build: |
      nix build './haunted-blog#' --log-format raw-with-logs
  - package: |
      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"

artifacts:
  - site.tar.zst
  - cid