aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/release-aur.ts
blob: 5c08fdcc3a39d689b045f9a5f27684107206318f (plain) (blame)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { execSync } from "node:child_process";
import {
  existsSync,
  mkdirSync,
  readFileSync,
  unlinkSync,
  writeFileSync,
} from "node:fs";
import path from "node:path";
import { version as pkgver } from "../src-tauri/tauri.conf.json";

function getSHA256Sum(filePath: string) {
  const response = execSync(`sha256sum ${filePath}`);
  return response.toString().split(" ")[0];
}

const projectRoot = path.resolve(__dirname, "..");

execSync("mkdir -p release", { stdio: "inherit" });
process.chdir("release");

const basePath = process.cwd();
const homePath = process.env.HOME ?? basePath;
const sshPath = path.resolve(homePath, ".ssh");
if (!existsSync(sshPath)) {
  mkdirSync(sshPath, { recursive: true });
}

const url = "https://github.com/HydroRoll-Team/DropOut";
const x86_64Url = `${url}/releases/download/dropout-v${pkgver}/Dropout_${pkgver}_amd64.deb`;
const aarch64Url = `${url}/releases/download/dropout-v${pkgver}/Dropout_${pkgver}_arm64.deb`;
const PKGBUILD = `\
# Maintainer: HsiangNianian <i@jyunko.cn>
# Contributor: 苏向夜 <fu050409@163.com>
pkgname=dropout-bin
pkgver=${pkgver.replace("-", "_")}
pkgrel=1
pkgdesc="A modern, reproducible, and developer-grade Minecraft launcher"
arch=('x86_64' 'aarch64')
url="${url}"
license=('MIT')
depends=('cairo' 'desktop-file-utils' 'gdk-pixbuf2' 'glib2' 'gtk3' 'hicolor-icon-theme' 'libsoup' 'pango' 'webkit2gtk-4.1')
options=('!strip' '!debug')
install=dropout-bin.install
source_x86_64=("${x86_64Url}")
source_aarch64=("${aarch64Url}")
sha256sums_x86_64=('${getSHA256Sum(path.resolve(projectRoot, "artifacts/deb", `Dropout_${pkgver}_amd64.deb`))}')
sha256sums_aarch64=('${getSHA256Sum(path.resolve(projectRoot, "artifacts/deb", `Dropout_${pkgver}_arm64.deb`))}')
package() {
  # Extract package data
  tar -xvf data.tar.gz -C "\${pkgdir}"
}
`;
console.log(PKGBUILD);
const INSTALL = `\
post_install() {
  gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
  update-desktop-database -q
}

post_upgrade() {
  post_install
}

post_remove() {
  gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
  update-desktop-database -q
}`;
console.log(INSTALL);

// Check if AUR_SSH_KEY environment variable is set
const AUR_SSH_KEY = process.env.AUR_SSH_KEY;
if (!AUR_SSH_KEY) {
  console.error("AUR_SSH_KEY environment variable is not set.");
  process.exit(1);
}

// Remove old SSH key file if it exists
const aurSSHKeyPath = path.resolve(sshPath, "aur");
if (existsSync(aurSSHKeyPath)) {
  unlinkSync(aurSSHKeyPath);
}

// Write new SSH key file
writeFileSync(aurSSHKeyPath, `${AUR_SSH_KEY}\n`);
execSync(`chmod 400 ${aurSSHKeyPath}`);

// Add aur to known hosts
const knownHostsPath = path.resolve(sshPath, "known_hosts");
if (existsSync(knownHostsPath)) {
  const knownHosts = readFileSync(knownHostsPath, {
    encoding: "utf-8",
  });
  if (!knownHosts.includes("aur.archlinux.org")) {
    execSync(
      `ssh-keyscan -v -t "rsa,ecdsa,ed25519" aur.archlinux.org >> ~/.ssh/known_hosts`,
      { stdio: "inherit" },
    );
  }
} else {
  execSync(
    `ssh-keyscan -v -t "rsa,ecdsa,ed25519" aur.archlinux.org > ~/.ssh/known_hosts`,
    { stdio: "inherit" },
  );
}

// Clone AUR repository if not exists
if (!existsSync("aur")) {
  execSync(
    `git -c init.defaultBranch=master -c core.sshCommand="ssh -i ${aurSSHKeyPath}" clone ssh://aur@aur.archlinux.org/clip-bridge-bin.git aur`,
    { stdio: "inherit" },
  );
}
execSync(`git -C aur config core.sshCommand "ssh -i ${aurSSHKeyPath}"`, {
  stdio: "inherit",
});

// Write PKGBUILD and .install files
const pkgbuildPath = path.resolve("aur", "PKGBUILD");
const installPath = path.resolve("aur", "dropout-bin.install");
writeFileSync(pkgbuildPath, PKGBUILD);
writeFileSync(installPath, INSTALL);

// Generate .SRCINFO file
execSync("makepkg --printsrcinfo > .SRCINFO", {
  cwd: "aur",
  stdio: "inherit",
});

// Setup Git repository
execSync("git add PKGBUILD .SRCINFO dropout-bin.install", {
  stdio: "inherit",
  cwd: "aur",
});
execSync(`git -C aur config user.name "HsiangNianian"`, { stdio: "inherit" });
execSync(`git -C aur config user.email "i@jyunko.cn"`, {
  stdio: "inherit",
});

// Test AUR package (skip in CI)
if (!process.env.CI) {
  execSync("makepkg -f", {
    stdio: "inherit",
    cwd: "aur",
  });
}

// Publish to AUR
execSync(`git commit -m "release: release v${pkgver}"`, {
  stdio: "inherit",
  cwd: "aur",
});
execSync(`git push origin master`, {
  stdio: "inherit",
  cwd: "aur",
});