diff --git a/.github/workflows/update-build-release.yml b/.github/workflows/update-build-release.yml index 5baa472..602568a 100644 --- a/.github/workflows/update-build-release.yml +++ b/.github/workflows/update-build-release.yml @@ -15,19 +15,23 @@ jobs: container: image: archlinux:latest steps: - - name: Pacman database update - run: pacman -Syy --noconfirm - - - name: Install deps - run: pacman -S --noconfirm git jq nix + - name: Packages install + run: pacman -Syy --noconfirm && pacman -S --noconfirm git jq nix python python-requests - name: Checkout uses: actions/checkout@v4 - - name: Check and update current packages - run: sh .github/workflows/update_packages.sh + - name: Fix git access + 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 - name: Commit and push changes @@ -38,7 +42,8 @@ jobs: add: "." author_name: "GitHub Actions" author_email: "loraner123@gmail.com" - - name: Publish AUR package + + - name: Publish package changes to AUR uses: KSXGitHub/github-actions-deploy-aur@v2.7.0 with: pkgname: "yandex-music" @@ -50,6 +55,7 @@ jobs: ssh_private_key: "${{ secrets.AUR_SSH_PRIVATE_KEY }}" commit_message: "${{ github.event.commits[0].message }}" ssh_keyscan_types: "rsa,dsa,ecdsa,ed25519" + outputs: new_version: ${{ steps.commit.outputs.commited }} commit_long_sha: ${{ steps.commit.outputs.commit_long_sha }} diff --git a/.github/workflows/update_packages.sh b/.github/workflows/update_packages.sh deleted file mode 100644 index fa3f1ce..0000000 --- a/.github/workflows/update_packages.sh +++ /dev/null @@ -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 diff --git a/utility/generate_packages.py b/utility/generate_packages.py new file mode 100644 index 0000000..95343dc --- /dev/null +++ b/utility/generate_packages.py @@ -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() \ No newline at end of file diff --git a/utility/generate_packages.sh b/utility/generate_packages.sh deleted file mode 100644 index 9aa3dfc..0000000 --- a/utility/generate_packages.sh +++ /dev/null @@ -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 <