generate-pkgbuild.py3 2.25 KB
Newer Older
ransome1's avatar
CI AUR  
ransome1 committed
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
#! /usr/bin/env python3
from os import environ, makedirs
import re

target = environ.get('TARGET')
if not target:
  print('::error ::TARGET is required but missing')
  exit(1)

release_tag = environ.get('RELEASE_TAG')
if not release_tag:
  print('::error ::RELEASE_TAG is required but missing')
  exit(1)

checksum = None
word_splitter = re.compile(r'\s+')
for line in open('sha1sum.txt').readlines():
  line = line.strip()
  if line.endswith(target):
    checksum, _ = word_splitter.split(line)

maintainer = '# Maintainer: Robin Ahle <ransome@uber.space>\n'
readme_url = f'https://raw.githubusercontent.com/ransome1/sleek/{release_tag}/README.md'
license_url = f'https://raw.githubusercontent.com/ransome1/sleek/{release_tag}/LICENSE.md'

opening = maintainer + '\n# This file is automatically generated. Do not edit.\n'

print('Generating PKGBUILD for sleek...')
makedirs('./pkgbuild/sleek', exist_ok=True)
with open('./pkgbuild/sleek/PKGBUILD', 'w') as pkgbuild:
  content = opening + '\n'
  content += 'pkgname=sleek\n'
  content += f'pkgver={release_tag}\n'
  source_url = f'https://github.com/ransome1/sleek/archive/{release_tag}.tar.gz'
  content += f'source=(sleek-{release_tag}.tar.gz::{source_url})\n'
  content += 'sha1sums=(SKIP)\n'
  content += open('./github/workflows/PKGBUILD/PKGBUILD').read() + '\n'
  pkgbuild.write(content)

print('Generating PKGBUILD for sleek...')
makedirs('./pkgbuild/sleek', exist_ok=True)
with open('./pkgbuild/sleek/PKGBUILD', 'w') as pkgbuild:
  content = opening + '\n'
  content += 'pkgname=sleek\n'
  content += f'pkgver={release_tag}\n'
  source_url_prefix = f'https://github.com/ransome1/sleek/releases/download/{release_tag}'
  source_url = f'{source_url_prefix}/sleek-{target}'
  supported_completions = ['bash', 'fish', 'zsh']
  completion_source = ' '.join(
    f'completion.{release_tag}.{ext}::{source_url_prefix}/completion.{ext}'
    for ext in supported_completions
  )
  content += f'source=(sleek-{checksum}::{source_url} {completion_source} {readme_url} {license_url})\n'
  content += f'_checksum={checksum}\n'
  completion_checksums = ' '.join('SKIP' for _ in supported_completions)
  content += f'_completion_checksums=({completion_checksums})\n'
  content += open('./github/workflows/PKGBUILD/PKGBUILD').read() + '\n'
  pkgbuild.write(content)