Skip to content
Open
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
177 changes: 177 additions & 0 deletions .travis_osx_upload_bottles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
set -e

# Work around https://github.com/travis-ci/travis-ci/issues/8703 :-@
# Travis overrides cd to do something with Ruby. Revert to the default.
unset -f cd
shell_session_update() { :; }

echo -en 'travis_fold:start:brew.update\\r'
echo "Updating Homebrew listings..."
brew update
echo -en 'travis_fold:end:brew.update\\r'
export HOMEBREW_NO_AUTO_UPDATE=1

brew uninstall --force --ignore-dependencies pkg-config
brew install pkg-config

if [[ ${BUILD_UNIVERSAL} == "1" ]]; then
UNIVERSAL_FLAG='--universal'
echo "Using --universal option for builds"
else
UNIVERSAL_FLAG=''
echo "Not using --universal option for builds"
fi


function fail {
echo $1 >&2
exit 1
}

function retry {
local n=1
local max=5
local delay=2
while true; do
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
echo "Command failed. Attempt $n/$max:"
sleep $delay;
else
fail "The command has failed after $n attempts."
fi
}
done
}

set shadowed_pkgs
shadowed_pkgs=()

function not_shadowed {
for pkg in $shadowed_pkgs; do
if [[ "$pkg" = "$1" ]]; then
return 1
fi
done
return 0
}

function upload_bottle {
if [[ ! "$1" ]]; then
echo "Called upload_bottle with no args; do nothing."
return 0
fi

local outdated=$(brew outdated | grep -m 1 "$1")
if [[ ! "$outdated" ]] && (brew ls --versions "$1" >/dev/null); then
echo "$1 is already installed and up to date."
return 0
fi

local deps=""
local bottled=$(brew info "$1" | grep -m 1 "(bottled)")
if [[ "$bottled" ]]; then
deps=$(brew deps --1 "$1")
else
deps=$(brew deps --1 --include-build "$1")
fi
if [[ "$deps" ]]; then
echo -n "$1 dependencies: "
echo $deps
while read -r dependency; do
echo "$1: Dependency $dependency."
upload_bottle "$dependency"
done <<< "$deps"
fi

if [[ "$outdated" ]]; then
echo "$1 is installed but outdated."
if [[ "$bottled" ]]; then
if (not_shadowed "$1"); then
echo "$1: Found bottle. Skipping."
retry brew uninstall --ignore-dependencies "$1"
retry brew install "$@"
return 0
fi
fi
retry brew uninstall --ignore-dependencies "$1"
else
echo "$1 is not installed."
if [[ "$bottled" ]]; then
if (not_shadowed "$1"); then
echo "$1: Found bottle. Skipping."
retry brew install "$@"
return 0
fi
fi
fi

echo "Found no bottle for $1. Let's build one."

retry brew install --build-bottle "$@"
brew bottle --json "$1"
# TODO: ^ first line in stdout is the bottle file
# use instead of file cmd. json file has a similar name. "| head -n 1"?
local jsonfile=$(find . -name $1*.bottle.json)
retry brew uninstall --ignore-dependencies "$1"
local bottlefile=$(find . -name $1*.tar.gz)
retry brew install "$bottlefile"

# Add the bottle info into the package's formula
echo "brew bottle --merge --write $jsonfile"
brew bottle --merge --write "$jsonfile"

# Path to the cachefile will be updated now
#local cachefile=$(brew --cache $1)

mkdir -p Formula
brew cat $1 > "Formula/$1.rb"
mkdir -p "bottles"
mv "$bottlefile" "bottles/"
#tar cfzv "$1-formula.tar.gz" "$1.rb" "$bottlefile"

# upload the package
#curl -T "$1-formula.tar.gz" "https://transfer.sh/$archive"
}

function add_shadowed {
if [[ ! "$1" ]]; then
return 0
fi
shadowed_pkgs+=("$1")
}

function prevent_stall {
while kill -0 "$!" 2> /dev/null
do
sleep 5
echo "Waiting..."
done
}

set +e
brew tap pygame/portmidi
# Extract packages to build from these strings: "Warning: python is provided by core, but is now shadowed by pygame/portmidi/python."
# ie "python" in the above example
brew tap-pin pygame/portmidi | sed 's/^Warning: \(\w\+\).*/\1/g' | add_shadowed
echo "Shadowed packages: ${shadowed_pkgs[@]}"

IFS=';' pkgs=( "$BOTTLES_BUILD" )
for pkg in $pkgs; do
upload_bottle "$pkg" & prevent_stall
done

# archive all packages upload the archive
echo "Creating brew-packages.tar.gz..."
tar cfzv "brew-packages.tar.gz" "Formula" "bottles"
shasum -a 256 "./brew-packages.tar.gz"

set -e

echo "Uploading brew-packages.tar.gz..."
curl -vs --upload-file "./brew-packages.tar.gz" "https://transfer.sh/" &> /dev/stdout || curl -vs -F "file=@brew-packages.tar.gz" "https://file.io/" &> /dev/stdout
echo "

"
sleep 5
90 changes: 90 additions & 0 deletions upload-bottles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import json


bottles_to_build = ('openssl', )
PY_VERSION = '3'
PY_VERSION_ = '3.7'
osx_image = "xcode7.3"


import subprocess

proc = subprocess.run(["travis", "whoami", "--org"],
capture_output=True, shell=True)
if proc.returncode:
if b'not logged in' in proc.stderr:
loginproc = subprocess.run(["travis", "login", "--org"], shell=True)
loginproc.check_returncode()
else:
raise Exception(proc.stderr)

proc = subprocess.run(["travis", "token", "--org"],
capture_output=True, shell=True, text=True)
proc.check_returncode()
token = proc.stdout.strip()

import sys
if sys.version_info.major >= 3:
from urllib.request import Request, urlopen
else:
from urllib2 import Request, urlopen
input = raw_input

body={
"request": {
"message": "Build bottles: %s" % (bottles_to_build, ),
"branch": "travis-upload",
"config": {
"merge_mode": "replace",
"language": "python",
"cache": {
"directories": [
"$HOME/.cache/pip",
"$HOME/Library/Caches/Homebrew",
"/Library/Caches/Homebrew"
]
},
"matrix": {
"include": [
{
"os": "osx",
"osx_image": osx_image,
"language": "generic",
"env": [
"PY_VERSION=%s" % PY_VERSION,
"PY_VERSION_=%s" % PY_VERSION_,
"MAKEFLAGS=-j8",
"BOTTLES_BUILD='%s'" % ';'.join(bottles_to_build),
"ROOT_URL=https://github.com/pygame/homebrew-portmidi/releases/download/bottles0",
]}
]
},
"script": [
"source .travis_osx_upload_bottles.sh"
],
"before_cache": [
"brew cleanup"
]
}
}
}

print(body, '\n\n')
print('Building and uploading the following bottles: %s' % (bottles_to_build, ))

confirmation = input('Proceed? [Y/n]')
if confirmation and confirmation[0].lower() != 'y':
print('Aborting.')


r = Request("https://api.travis-ci.org/repo/pygame%2Fpygame/requests",
headers={
"Content-Type": "application/json",
"Accept": "application/json",
"Travis-API-Version": "3",
"Authorization": "token %s" % token
},
data=json.dumps(body).encode('ascii'))
response = urlopen(r)

print(json.loads(response.read().decode()))