0
0
mirror of https://github.com/cucumber-sp/yandex-music-linux.git synced 2024-12-23 22:22:59 +03:00

Switch generate_packages to Python

dep fix
This commit is contained in:
Andrey Onishchenko 2024-02-18 22:34:35 +03:00
parent b3e166c8a5
commit af2bdcbd02
5 changed files with 165 additions and 147 deletions

View File

@ -15,19 +15,23 @@ jobs:
container: container:
image: archlinux:latest image: archlinux:latest
steps: steps:
- name: Pacman database update - name: Packages install
run: pacman -Syy --noconfirm run: pacman -Syy --noconfirm && pacman -S --noconfirm git jq nix python python-requests
- name: Install deps
run: pacman -S --noconfirm git jq nix
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Check and update current packages - name: Fix git access
run: sh .github/workflows/update_packages.sh run:
git config --global --add safe.directory "*"
- name: Retrieve version - name: Update version file
run: python utility/update_version.py
- name: Update package files
run: python utility/generate_packages.py
- name: Retrieve version to make commit
run: sh .github/workflows/retrieve_version.sh run: sh .github/workflows/retrieve_version.sh
- name: Commit and push changes - name: Commit and push changes
@ -38,7 +42,8 @@ jobs:
add: "." add: "."
author_name: "GitHub Actions" author_name: "GitHub Actions"
author_email: "loraner123@gmail.com" author_email: "loraner123@gmail.com"
- name: Publish AUR package
- name: Publish package changes to AUR
uses: KSXGitHub/github-actions-deploy-aur@v2.7.0 uses: KSXGitHub/github-actions-deploy-aur@v2.7.0
with: with:
pkgname: "yandex-music" pkgname: "yandex-music"
@ -50,6 +55,7 @@ jobs:
ssh_private_key: "${{ secrets.AUR_SSH_PRIVATE_KEY }}" ssh_private_key: "${{ secrets.AUR_SSH_PRIVATE_KEY }}"
commit_message: "${{ github.event.commits[0].message }}" commit_message: "${{ github.event.commits[0].message }}"
ssh_keyscan_types: "rsa,dsa,ecdsa,ed25519" ssh_keyscan_types: "rsa,dsa,ecdsa,ed25519"
outputs: outputs:
new_version: ${{ steps.commit.outputs.commited }} new_version: ${{ steps.commit.outputs.commited }}
commit_long_sha: ${{ steps.commit.outputs.commit_long_sha }} commit_long_sha: ${{ steps.commit.outputs.commit_long_sha }}

View File

@ -1,25 +0,0 @@
#!/bin/bash
set -e
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
else
OS=$(uname -s)
fi
case $OS in
"Arch Linux")
echo "Arch Linux"
pacman -S --noconfirm git sudo base-devel jq nix
git config --global --add safe.directory "*"
sh ./utility/generate_packages.sh
;;
*)
echo "Operating system is not recognized."
;;
esac

View File

@ -0,0 +1,73 @@
import json
import os
import shutil
import subprocess
def check_dependency(dependency):
if shutil.which(dependency):
return True
print(f"{dependency} not installed.")
return False
script_dir = os.path.dirname(os.path.realpath(__file__))
# loading versions information from json
version_info_path = os.path.join(script_dir, "version_info.json")
with open(version_info_path, "r") as f:
version_info = json.load(f)
# Arch
def generate_arch():
pkgbuild_template = os.path.join(script_dir, "../templates/PKGBUILD")
pkgbuild_path = os.path.join(script_dir, "../PKGBUILD")
with open(pkgbuild_template, "r") as f:
pkgbuild = f.read()
pkgbuild = pkgbuild.replace("%version%", version_info["ym"]["version"])
pkgbuild = pkgbuild.replace("%release%", "1")
pkgbuild = pkgbuild.replace("%exe_name%", version_info["ym"]["exe_name"])
pkgbuild = pkgbuild.replace("%exe_link%", version_info["ym"]["exe_link"])
pkgbuild = pkgbuild.replace("%exe_sha256%", version_info["ym"]["exe_sha256"])
with open(pkgbuild_path, "w") as f:
f.write(pkgbuild)
# Nix
def is_nix_version_2_19():
version = subprocess.run(["nix", "--version"], capture_output=True, text=True).stdout.split()[2]
major, minor, _ = map(int, version.split("."))
if major > 2 or (minor >= 19 and major == 2):
return True
return False
def generate_nix():
nixcmd = "nix --extra-experimental-features nix-command --extra-experimental-features flakes"
flake_path = os.path.join(script_dir, "../flake.nix")
# Update url in flake.nix
with open(flake_path, "r") as f:
flake = f.read()
_start_index = flake.find("ymExe.url = ")
_end_index = flake.find(";", _start_index)
flake = flake.replace(flake[_start_index:_end_index+1], f'ymExe.url = {version_info["ym"]["exe_link"]};')
with open(flake_path, "w") as f:
f.write(flake)
if not check_dependency("nix"):
print("flake.nix was updated, but nix is not installed to update flake.lock")
return
if is_nix_version_2_19():
subprocess.run(f"{nixcmd} flake update ymExe", shell=True)
else:
subprocess.run(f"{nixcmd} flake lock --update-input ymExe", shell=True)
if subprocess.run("git status --porcelain -- flake.lock", shell=True).stdout:
subprocess.run(f"{nixcmd} flake update", shell=True)
generate_arch()
generate_nix()

View File

@ -1,113 +0,0 @@
#!/bin/bash
set -e
TEMPDIR=
exe_link=
version=
exe_name=
exe_sha256=
clear() {
rm -rf "$TEMPDIR"
}
TEMPDIR="$(mktemp -d)"
trap clear EXIT
check_dep() {
if ! command -v "$@" &>/dev/null; then
echo "$@" not installed. >&2
return 1
fi
}
check_deps() {
check_dep sed
check_dep curl
check_dep jq
}
load_current_version() {
# loading json from file https://music-desktop-application.s3.yandex.net/stable/download.json
curl -s https://music-desktop-application.s3.yandex.net/stable/download.json > "$TEMPDIR"/download.json
exe_link=$(jq -r '.windows' "$TEMPDIR"/download.json)
version="$(echo "$exe_link" | grep -oP '(?<=x64_).*(?=.exe)')"
exe_name="$(basename "$exe_link")"
echo "Windows url: $exe_link"
echo "Version: $version"
echo "Exe name: $exe_name"
curl "$exe_link" > "$TEMPDIR/$exe_name"
exe_sha256="$(sha256sum "$TEMPDIR/$exe_name" | awk '{print $1}')"
echo "Exe sha256: $exe_sha256"
}
update_version() {
rm -rf ./utility/version_info.json
cat > ./utility/version_info.json <<EOF
{
"ym": {
"version": "$version",
"exe_name": "$exe_name",
"exe_link": "$exe_link",
"exe_sha256": "$exe_sha256"
}
}
EOF
}
update_pkbuild() {
cp ./templates/PKGBUILD ./PKGBUILD
sed -i "s#%version%#$version#g" ./PKGBUILD
sed -i "s#%release%#1#g" ./PKGBUILD
sed -i "s#%exe_name%#$exe_name#g" ./PKGBUILD
sed -i "s#%exe_link%#$exe_link#g" ./PKGBUILD
sed -i "s#%exe_sha256%#$exe_sha256#g" ./PKGBUILD
}
is_nix_version_2_19() {
local version re major minor
version="$(nix --version | awk '{print $3}')"
re='([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)'
if [[ $version =~ $re ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
if [ "$major" -gt 2 ] || [ "$minor" -ge 19 ]; then
return 0
fi
fi
return 1
}
update_flake() {
local nixcmd="nix --extra-experimental-features nix-command --extra-experimental-features flakes"
sed -i 's#\(ymExe\.url\s*=\s*\).*;#\1'"$exe_link"';#' ./flake.nix
if check_dep nix; then
# Starting from 2.19 the interface of `nix flake` command changed. See
# https://nixos.org/manual/nix/stable/release-notes/rl-2.19
if is_nix_version_2_19; then
$nixcmd flake update ymExe
else
$nixcmd flake lock --update-input ymExe
fi
if [[ $(git status --porcelain -- flake.lock) ]]; then
$nixcmd flake update
fi
else
echo "flake.nix was updated, but nix is not installed to update flake.lock"
fi
}
check_deps
load_current_version
update_version
update_pkbuild
update_flake

77
utility/update_version.py Normal file
View File

@ -0,0 +1,77 @@
import atexit
import hashlib
import json
import os
import shutil
import tempfile
import requests
YM_VERSIONS_URL = "https://music-desktop-application.s3.yandex.net/stable/download.json"
ELECTRON_VERSIONS_URL = "https://releases.electronjs.org/releases.json"
ELECTRON_DOWNLOAD_URL = "https://github.com/electron/electron/releases/download/v{0}/electron-v{0}-linux-{1}.zip"
script_dir = os.path.dirname(os.path.realpath(__file__))
tempdir = tempfile.mkdtemp()
def clear():
shutil.rmtree(tempdir)
atexit.register(clear)
def assert_dependency(dependency):
if shutil.which(dependency):
return
print(f"{dependency} not installed.")
exit(1)
# loading versions json
versions_obj = requests.get(YM_VERSIONS_URL).json()
exe_link = versions_obj["windows"]
version = exe_link.split("x64_")[1].split(".exe")[0]
exe_name = os.path.basename(exe_link)
# downloading exe file
print(f"Downloading {exe_name}")
exe_path = os.path.join(tempdir, exe_name)
with open(exe_path, "wb") as f:
f.write(requests.get(exe_link).content)
# calculating sha256
print("Calculating sha256")
with open(exe_path, "rb") as f:
exe_sha256 = hashlib.sha256(f.read()).hexdigest()
print(f"Sha256: {exe_sha256}")
# getting electron version
print("Getting latest electron version")
electron_releases = requests.get(ELECTRON_VERSIONS_URL).json()
electron_versions = list(map(lambda x: x["version"], electron_releases))
electron_versions = list(filter(lambda x: "-" not in x and x.startswith("27"), electron_versions))
electron_version = electron_versions[0]
print(f"Latest electron version: {electron_version}")
electron_x64 = ELECTRON_DOWNLOAD_URL.format(electron_version, "x64")
electron_armv7l = ELECTRON_DOWNLOAD_URL.format(electron_version, "armv7l")
electron_arm64 = ELECTRON_DOWNLOAD_URL.format(electron_version, "arm64")
version_info = {
"ym": {
"version": version,
"exe_name": exe_name,
"exe_link": exe_link,
"exe_sha256": exe_sha256
},
"electron": {
"version": electron_version,
"x64": electron_x64,
"armv7l": electron_armv7l,
"arm64": electron_arm64
}
}
version_file = os.path.join(script_dir, "version_info.json")
# writing json to file
with open(version_file, "w") as f:
f.write(json.dumps(version_info, indent=4))
print(f"Version info written to {version_file}")