Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build.sh #7

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.whl_ruamel.yaml.clib_name }}
path: ${{ steps.build-whl.outputs.whl_ruamel.yaml.clib_path }}

- name: Upload install script
uses: actions/upload-artifact@master
with:
Expand Down Expand Up @@ -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
asset_content_type: text/plain
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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'))"
```
Expand Down
91 changes: 91 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -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())
41 changes: 28 additions & 13 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,41 @@ 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

RELEASE_TAG="cyg${CYGWIN_VERSION}-py${PYTHON_VERSION}-borg${BORG_VERSION}"
WHL=$(find . -name "*.whl" | head -n 1)
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)

$PYTHON setup.py bdist_wheel

WHL=$(find . -name "*.whl" | head -n 1)

if [ "$package" == "borgbackup" ]; then
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

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

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'))"

\$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/",
Expand All @@ -38,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