summarylogtreecommitdiffstats
path: root/.gitlab-ci.yml
blob: 18186f0dec74486ff30d8287a94fff3c7c699b2f (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
77
78
79
80
81
82
83
84
85
86
87
image: archlinux:base-devel

variables:
  PACKAGE_NAME: "auto_facelock"
  AUR_REPO: "ssh://aur@aur.archlinux.org/${PACKAGE_NAME}.git"
  COMMIT_HASH: "$CI_COMMIT_SHORT_SHA"
  CURRENT_DIR: "$(pwd)"

stages:
  - lint
  - build
  - archive
  - publish

cache:
  key: system-v1
  paths:
    - .pkg-cache
    - .venv
    - .pre-commit

lint:
  stage: lint
  before_script:
    - pacman -Sy --noconfirm --noprogressbar --cachedir .pkg-cache archlinux-keyring
    - pacman -Syu --noconfirm --noprogressbar --cachedir .pkg-cache git python python-pre-commit
  script:
    - export XDG_CACHE_HOME=.pre-commit
    - pre-commit run -a || (cat /builds/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/.pre-commit/pre-commit.log && false)
  after_script:
    - git config --global user.email "matthew.d.weger@gmail.com"
    - git config --global user.name "Matthew Weger"
    - git add .
    - git commit -m "Apply pre-commit fixes"
    - git push

build:
  stage: build
  script:
    - |
      pacman -Syu --noconfirm --needed --cachedir .pkg-cache git yay
      makepkg --printsrcinfo > .SRCINFO
      makepkg -si --noconfirm
  artifacts:
    paths:
      - "*.pkg.tar.*"
      - "*.src.tar.gz"
    expire_in: 1 week

archive:
  stage: archive
  script:
    - mkdir -p artifacts
    - mv *.pkg.tar.* "artifacts/${PACKAGE_NAME}-${COMMIT_HASH}.pkg.tar.xz"
    - mv *.src.tar.gz "artifacts/${PACKAGE_NAME}-${COMMIT_HASH}.src.tar.gz"
  dependencies:
    - build
  artifacts:
    paths:
      - artifacts/
    expire_in: 1 week

publish:
  stage: publish
  script:
    - |
      pacman -S --noconfirm --needed --cachedir .pkg-cache openssh
      mkdir -p ~/.ssh
      chmod 700 ~/.ssh
      echo "$AUR_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
      git clone $AUR_REPO aur_repo
      cd aur_repo
      cp ../artifacts/*.pkg.tar.xz .
      cp ../artifacts/*.src.tar.gz .
      cp ../PKGBUILD .
      cp ../.SRCINFO .
      git add PKGBUILD .SRCINFO
      git commit -m "Update package to commit ${COMMIT_HASH}"
      git push origin master
  dependencies:
    - archive
  environment:
    name: production
  when: manual
  rules:
    - if: '$CI_COMMIT_REF_NAME == "main"'
      when: manual