summaryrefslogtreecommitdiffstats
path: root/.builds/alpine.yml
blob: e5c07c29fae718ca05e8fc943b7face9ada45bf1 (plain)
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
74
75
76
image: alpine/edge
repositories:
  sr.ht: >
    https://mirror.sr.ht/alpine/sr.ht/
    https://mirror.sr.ht/alpine/sr.ht/alpine%40sr.ht.rsa.pub
    alpine@sr.ht.rsa.pub
packages:
  - rsync
  - xz
sources:
  - https://git.sr.ht/~sircmpwn/man.sr.ht
  - https://git.sr.ht/~sircmpwn/sr.ht-apkbuilds
environment:
  project: man.sr.ht
  repo_server: deploy@mirror.sr.ht
  repo_path: /var/www/mirror.sr.ht/alpine/sr.ht/x86_64
  master: man.sr.ht
secrets:
  - fa00a8d3-7b63-42d5-8060-3bb31c3e3018 # ssh deploy key
  - d0adc1d4-af78-4852-920f-1134392f5d10 # package signing key
tasks:
  - archive: |
      cd ${project}
      pkgver=$(git describe --abbrev=0)
      if ! git describe --exact-match HEAD
      then
        cdate=$(git show -s -1 --format='%ci' HEAD)
        cdate=$(echo "$cdate" | cut -d' ' -f1 | sed -e 's/-//g')
        pkgver="${pkgver}_git${cdate}"
      fi
      echo "pkgver=$pkgver" >> ~/.buildenv
      git archive --prefix=${project}-$pkgver/ HEAD | xz \
        > ~/sr.ht-apkbuilds/sr.ht/${project}/${project}-$pkgver.tar.xz
  - package: |
      cd sr.ht-apkbuilds/sr.ht/${project}
      echo 'PACKAGER_PRIVKEY="/home/build/.abuild/alpine@sr.ht.rsa"' >> \
        ~/.abuild/abuild.conf
      prev_pkgver=$(apk search -x ${project} | cut -d '-' -f3-)
      prev_pkgrel=$(printf "%s" "$prev_pkgver" | cut -d'-' -f2 | cut -c2-)
      prev_pkgver=$(printf "%s" "$prev_pkgver" | cut -d'-' -f1)
      if [ "$prev_pkgver" = "$pkgver" ]
      then
        pkgrel=$(($prev_pkgrel + 1))
      else
        pkgrel=1
      fi
      sed -e "s/pkgver=.*/pkgver=$pkgver/" -i APKBUILD
      sed -e "s/pkgrel=.*/pkgrel=$pkgrel/" -i APKBUILD
      sed -e "s?http://git.sr.ht/.*/snapshot/??g" -i APKBUILD
      cat APKBUILD
      echo "pkgrel=$pkgrel" >> ~/.buildenv
      abuild checksum
      abuild -r
      cd ~/${project}
      git describe --exact-match HEAD || complete-build
  - publish: |
      cd ~/packages/sr.ht/x86_64
      sshopts="-o StrictHostKeyChecking=no"
      set -u
      ssh $sshopts $repo_server rm -f $repo_path/${project}'*.apk'
      rsync --blocking-io \
        -rPe "ssh $sshopts" *.apk $repo_server:$repo_path/
      ssh $sshopts $repo_server find $repo_path -type f -name '*.apk' -print0 |
        ssh $sshopts $repo_server xargs -0 apk index \
          --rewrite-arch x86_64 \
          -x $repo_path/APKINDEX.tar.gz \
          -o $repo_path/APKINDEX.unsigned.tar.gz
      rsync --blocking-io -rPe "ssh $sshopts" \
        $repo_server:$repo_path/APKINDEX.unsigned.tar.gz APKINDEX.tar.gz
      abuild-sign -k ~/.abuild/alpine@sr.ht.rsa APKINDEX.tar.gz
      rsync --blocking-io -rPe "ssh $sshopts" \
        APKINDEX.tar.gz $repo_server:$repo_path/
  - deploy: |
      sshopts="-o StrictHostKeyChecking=no"
      ssh $sshopts deploy@$master doas apk upgrade -U
      ssh $sshopts deploy@$master doas service man.sr.ht restart