From 595ba639053e60c27a864d2c9f7d285dd3246f9d Mon Sep 17 00:00:00 2001 From: Nick Venenga Date: Thu, 29 Apr 2021 21:04:46 -0400 Subject: [PATCH 1/6] Update build.sh --- build.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index aa8c38a..c7e2d0e 100644 --- a/build.sh +++ b/build.sh @@ -9,11 +9,21 @@ export CYGWIN_VERSION=$(cygcheck -V | head -n 1 | grep -Po "[0-9.]+") # $PYTHON -m ensurepip $PYTHON -m pip install -U pip wheel -$PYTHON -m pip download borgbackup -tar xf borgbackup*.tar.* -cd $(find . -maxdepth 1 -name "borgbackup*" -type d | tail -n 1 | xargs basename) -export BORG_VERSION=$($PYTHON setup.py --version) -$PYTHON setup.py bdist_wheel + +function build_wheel { + package=$1 + $PYTHON -m pip download "$package" + tar xf $package*.tar.* + pushd $(find . -maxdepth 1 -name "$package*" -type d | tail -n 1 | xargs basename) + if [ "$package" == "borgbackup" ]; then + export BORG_VERSION=$($PYTHON setup.py --version) + fi + $PYTHON setup.py bdist_wheel + popd +} + +build_wheel borgbackup +build_wheel ruamel.yaml.clib RELEASE_TAG="cyg${CYGWIN_VERSION}-py${PYTHON_VERSION}-borg${BORG_VERSION}" WHL=$(find . -name "*.whl" | head -n 1) From c55c7880505ce86be2d4ce58058fd08799c9368d Mon Sep 17 00:00:00 2001 From: Nick Venenga Date: Thu, 29 Apr 2021 21:23:21 -0400 Subject: [PATCH 2/6] Update build.sh --- build.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/build.sh b/build.sh index c7e2d0e..e7a9548 100644 --- a/build.sh +++ b/build.sh @@ -15,19 +15,28 @@ function build_wheel { $PYTHON -m pip download "$package" tar xf $package*.tar.* pushd $(find . -maxdepth 1 -name "$package*" -type d | tail -n 1 | xargs basename) + + $PYTHON setup.py bdist_wheel + + WHL=$(find . -name "*.whl" | head -n 1) + if [ "$package" == "borgbackup" ]; then - export BORG_VERSION=$($PYTHON setup.py --version) + export BORG_VERSION="$($PYTHON setup.py --version)" + export RELEASE_TAG="cyg${CYGWIN_VERSION}-py${PYTHON_VERSION}-borg${BORG_VERSION}" + export BORGBACKUP_WHL="$WHL" + echo "::set-output name=borg_version::${BORG_VERSION}" + echo "::set-output name=version::${RELEASE_TAG}" fi - $PYTHON setup.py bdist_wheel + + echo "::set-output name=whl_$package_name::$(basename ${WHL})" + echo "::set-output name=whl_$package_path::$(cygpath -w $(readlink -f ${WHL}))" + popd } build_wheel borgbackup build_wheel ruamel.yaml.clib -RELEASE_TAG="cyg${CYGWIN_VERSION}-py${PYTHON_VERSION}-borg${BORG_VERSION}" -WHL=$(find . -name "*.whl" | head -n 1) - cat << EOF > install.ps1 Start-Process -Verb runAs -Wait powershell -ArgumentList "-NoProfile", "-ExecutionPolicy", "AllSigned", "-Command", "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" @@ -48,14 +57,10 @@ Start-Process -Verb runAs -Wait "C:\tools\cygwin\cygwinsetup.exe" -ArgumentList ln -s "\$PYTHON" /usr/bin/python3 ln -s "\$PIP" /usr/bin/pip ln -s "\$PIP" /usr/bin/pip3 - pip3 install https://github.com/nijave/borg-windows-package/releases/download/${RELEASE_TAG}/$(basename ${WHL}) borgmatic + pip3 install https://github.com/nijave/borg-windows-package/releases/download/${RELEASE_TAG}/$(basename ${BORGBACKUP_WHL}) borgmatic '@ | & "c:\tools\cygwin\bin\bash.exe" --login -i EOF -echo "::set-output name=borg_version::${BORG_VERSION}" -echo "::set-output name=version::${RELEASE_TAG}" -echo "::set-output name=whl_name::$(basename ${WHL})" -echo "::set-output name=whl_path::$(cygpath -w $(readlink -f ${WHL}))" echo "::set-output name=script_path::$(cygpath -w $(readlink -f install.ps1))" exit 0 From 8f12fb00f611483bcf154cdcad6b23cb867926ab Mon Sep 17 00:00:00 2001 From: Nick Venenga Date: Thu, 29 Apr 2021 21:24:32 -0400 Subject: [PATCH 3/6] Update pythonapp.yml --- .github/workflows/pythonapp.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 7490c23..485e7c2 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -58,8 +58,14 @@ jobs: uses: actions/upload-artifact@master with: name: ${{ steps.build-whl.outputs.version }} - path: ${{ steps.build-whl.outputs.whl_path }} - + path: ${{ steps.build-whl.outputs.whl_borgbackup_path }} + + - name: Upload ruamel.yaml.clib wheel + uses: actions/upload-artifact@master + with: + name: ${{ steps.build-whl.outputs.version }} + path: ${{ steps.build-whl.outputs.whl_ruamel.yaml.clib_path }} + - name: Upload install script uses: actions/upload-artifact@master with: @@ -100,4 +106,4 @@ jobs: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ${{ steps.build-whl.outputs.script_path }} asset_name: install.ps1 - asset_content_type: text/plain \ No newline at end of file + asset_content_type: text/plain From 79ecfb494d7dee169096d131e4dc18138a8d87e7 Mon Sep 17 00:00:00 2001 From: Nick Venenga Date: Thu, 29 Apr 2021 21:25:18 -0400 Subject: [PATCH 4/6] Update pythonapp.yml --- .github/workflows/pythonapp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 485e7c2..c357a12 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -63,7 +63,7 @@ jobs: - name: Upload ruamel.yaml.clib wheel uses: actions/upload-artifact@master with: - name: ${{ steps.build-whl.outputs.version }} + name: ${{ steps.build-whl.outputs.whl_ruamel.yaml.clib_name }} path: ${{ steps.build-whl.outputs.whl_ruamel.yaml.clib_path }} - name: Upload install script From dc25fe6da2c15888cdf5b5f36c2d4f5cf88849da Mon Sep 17 00:00:00 2001 From: Nick Venenga Date: Thu, 29 Apr 2021 19:11:41 -0700 Subject: [PATCH 5/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f3d70c9..04af325 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # borg-windows-package ## Usage: -Install using Powershell to run `install.ps1` +Use Command Prompt to download and run `install.ps1` via Powershell ``` @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://github.com/nijave/borg-windows-package/releases/latest/download/install.ps1'))" ``` From f184133daac2877490e064f3091decacecd5c525 Mon Sep 17 00:00:00 2001 From: Nick Venenga Date: Thu, 29 Apr 2021 20:08:17 -0700 Subject: [PATCH 6/6] wip --- build.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 build.py diff --git a/build.py b/build.py new file mode 100644 index 0000000..49aa9f2 --- /dev/null +++ b/build.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 + +import pathlib +import typing +import subprocess +from subprocess import check_output + +def run(*args): + return subprocess.check_output(args, text=True).strip() + +def delete_all(s: str, removals: typing.List[str]) -> str: + for r in removals: + s = s.replace(r, '') + return s + +DIR_STACK = [] +def pushd(dir, stack=DIR_STACK): + last_dir = os.getcwd() + os.chdir(dir) + DIR_STACK.append(last_dir) + +def popd(stack=DIR_STACK): + os.chdir(DIR_STACK.pop()) + +REPO_BASE = "https://github.com/nijave/borg-windows-package/releases/download" +BUILD_TARGETS = ["borgbackup", "ruamel.yaml.clib"] + +python = next(pathlib.Path("/usr/bin").glob("python3*.*.exe")) +python_version = run(python, "--version").split()[-1] +cygwin_version = run("cygcheck", "-V").splitlines()[0].split()[-1] + +# Build tools +run(python, "-m", "pip", "install", "-U", "pip", "setuptools", "wheel") + + +def build_wheel(module: str) -> typing.Tuple[str, str]: + download_output = run("pip", "download", module) + save_prefixes = ("Saved ", "File was already downloaded") + archive = [ + delete_all(line.strip(), save_prefixes) for line in download_output.splitlines() + if any(line.strip().startswith(prefix) for prefix in save_prefixes) + ][0].strip() + run("tar", "xf", archive) + with tarfile.open(archive, "r") as tf: + module_dir = tf.getnames()[0] + pushd(module_dir) + if ( + subprocess.run( + [python, "setup.py", "bdist_wheel"], + text=True + ).returncode != 0 + ): + raise RuntimeError(f"{module} build failed") + whl_file = module_dir / next(pathlib.Path(".").glob("**/*.whl")) + # capture some build info + # set outputs + # return name, path + + +build_info = { + output[0]: output[1] + for output in ( + build_wheel(package) for package in BUILD_TARGETS + ) +} + +install_script = open("install.ps1", "w") +install_script.write(f""" +Start-Process -Verb runAs -Wait powershell -ArgumentList "-NoProfile", "-ExecutionPolicy", "AllSigned", + "-Command", "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" + +$env:PATH = "$env:PATH;$env:ALLUSERSPROFILE\chocolatey\bin" + +Start-Process -Verb runAs -Wait "c:\ProgramData\chocolatey\bin\choco.exe" -ArgumentList "install", "-y", "cygwin" + +Start-Process -Verb runAs -Wait "C:\tools\cygwin\cygwinsetup.exe" -ArgumentList "-nqWgv", + "-s", "http://mirrors.kernel.org/sourceware/cygwin/", + "-R", "C:\tools\cygwin", + "-P", "{CYGWIN_PYTHON_PACKAGE}-pip,gcc-core,openssh,zstd" | Out-String + +@' + PYTHON=\$(find /usr/bin -name "python*.exe" | head -n 1) + PIP=\$(find /usr/bin -name "pip*.*" | head -n 1) + ln -s "\$PYTHON" /usr/bin/python + ln -s "\$PYTHON" /usr/bin/python3 + ln -s "\$PIP" /usr/bin/pip + ln -s "\$PIP" /usr/bin/pip3 + pip3 install \ + {REPO_BASE}/{RELEASE_TAG}/$(basename {BORGBACKUP_WHL}) borgmatic +'@ | & "c:\tools\cygwin\bin\bash.exe" --login -i +""".strip()) \ No newline at end of file diff --git a/build.sh b/build.sh index e7a9548..a9546c0 100644 --- a/build.sh +++ b/build.sh @@ -43,7 +43,7 @@ Start-Process -Verb runAs -Wait powershell -ArgumentList "-NoProfile", "-Executi \$env:PATH = "\$env:PATH;\$env:ALLUSERSPROFILE\chocolatey\bin" -Start-Process -Verb runAs -Wait "c:\ProgramData\chocolatey\bin\choco.exe" -ArgumentList "install", "cygwin" +Start-Process -Verb runAs -Wait "c:\ProgramData\chocolatey\bin\choco.exe" -ArgumentList "install", "-y", "cygwin" Start-Process -Verb runAs -Wait "C:\tools\cygwin\cygwinsetup.exe" -ArgumentList "-nqWgv", "-s", "http://mirrors.kernel.org/sourceware/cygwin/",