Skip to content

Commit

Permalink
Set up automatic PPA release
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Jan 6, 2020
1 parent 575a982 commit f3d53e4
Show file tree
Hide file tree
Showing 32 changed files with 289 additions and 129 deletions.
9 changes: 0 additions & 9 deletions .dockerignore

This file was deleted.

32 changes: 12 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ script:
- tox
- python setup.py sdist bdist_wheel

before_deploy: # Wrapped in an `if` to make sure it's run only once before the first deploy and not before every single deploy
if [[ -z "$DEB_BUILT" ]]; then
export DEB_BUILT=true &&
docker build -f ci/Dockerfile-deb-build -t git-machete:deb-build . &&
id=$(docker create git-machete:deb-build) &&
docker cp $id:/git-machete/deb_dist/ . &&
docker rm -v $id &&
docker build -f ci/Dockerfile-deb-test-python deb_dist/ &&
docker build -f ci/Dockerfile-deb-test-python3 deb_dist/ ;
fi

deploy:

- provider: pypi
Expand All @@ -38,21 +27,24 @@ deploy:
python: 3.6
tags: true

- provider: script
- provider: releases # Github
skip_cleanup: true
script: ./ci/homebrew-git-push.sh
token:
secure: arhgNhJMfVq8xaa5xMswvjkgfgE8dDJ6BM0X+HI28m7BrwjxaVyr5Ct1qIohEQSZOpihwHzFLLwzSICc5sR6H8Ai4yYcm/sLGOAHyp4p1HeAXPqbtyUtn3rbcjsKXSfwjntkGommC6sYoY5GZhJy2qcRQIADjRMPQWRURY5/6KBBY05scL2vVpQw2NHp2pNCiMSDhokFsN3mv1PX15QDJdKFuIrD61cD15ljkwol7OJ+wKzGozyJB6GHkWi7WsGXsgdzjruHY7tcqPEksa+sWxxGGMmLQ7gVruVUlguunACjh0xlZvMBDKWEeffvRy9JSkAKVccTtaiZw9beoCaihZOVys/Bw4Znv3e+UpkOOrBwMFOdjc1R/Kz1/aewuYFckKhP/opdkpOj3T0VIckmK4s/vWYWhHLRiAHE4gb47UxYIKHGqPfs9XMyZryRF6iaTm3LKtTb+ufM0OQEKtWR0MBBRmpqapx74Jd6tuf7n4KbsS4ZuVeb27+OBhfogpYdfGW2KxzwCOwYl+iGCsNkPyMUOmqo8MfFvwEsHU7SnZ1G2tcSoptT8+Bj8n2lKB7sf/llywUJxKKG9kpK9Y9Tc6yvtgjj4ewjsjgaGCksS5jVPk223WEHu/iX4FK4Ftms9cXWLbQpMKW4dACyAEu8ONIRw+TXvUFA2J3wWsOiQNk=
on:
python: 3.6
tags: true

- provider: releases # Github
- provider: script # brew tap (artifacts must be released to PyPI first)
skip_cleanup: true
token:
secure: arhgNhJMfVq8xaa5xMswvjkgfgE8dDJ6BM0X+HI28m7BrwjxaVyr5Ct1qIohEQSZOpihwHzFLLwzSICc5sR6H8Ai4yYcm/sLGOAHyp4p1HeAXPqbtyUtn3rbcjsKXSfwjntkGommC6sYoY5GZhJy2qcRQIADjRMPQWRURY5/6KBBY05scL2vVpQw2NHp2pNCiMSDhokFsN3mv1PX15QDJdKFuIrD61cD15ljkwol7OJ+wKzGozyJB6GHkWi7WsGXsgdzjruHY7tcqPEksa+sWxxGGMmLQ7gVruVUlguunACjh0xlZvMBDKWEeffvRy9JSkAKVccTtaiZw9beoCaihZOVys/Bw4Znv3e+UpkOOrBwMFOdjc1R/Kz1/aewuYFckKhP/opdkpOj3T0VIckmK4s/vWYWhHLRiAHE4gb47UxYIKHGqPfs9XMyZryRF6iaTm3LKtTb+ufM0OQEKtWR0MBBRmpqapx74Jd6tuf7n4KbsS4ZuVeb27+OBhfogpYdfGW2KxzwCOwYl+iGCsNkPyMUOmqo8MfFvwEsHU7SnZ1G2tcSoptT8+Bj8n2lKB7sf/llywUJxKKG9kpK9Y9Tc6yvtgjj4ewjsjgaGCksS5jVPk223WEHu/iX4FK4Ftms9cXWLbQpMKW4dACyAEu8ONIRw+TXvUFA2J3wWsOiQNk=
file_glob: true
file:
- dist/*
- deb_dist/*.deb
script: bash ci/homebrew-tap/travis-deploy.sh
on:
python: 3.6
tags: true

- provider: script # PPA
skip_cleanup: true
script: bash ci/apt-ppa/upload-travis-deploy.sh
on:
python: 3.6
tags: true
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,33 @@ We suggest a couple of alternative ways of installation.

git-machete works under both Python 2.7 and Python 3.x.

### Using Homebrew (Mac)
### Using Homebrew (macOS)

```shell script
brew tap VirtusLab/git-machete
brew install git-machete
```

### Using Debian packages (Ubuntu, Debian etc.)
### Using PPA (Ubuntu)

See [the latest release](https://github.com/VirtusLab/git-machete/releases/latest) for downloadable .deb packages.
Tip: run `sudo apt-get install -y software-properties-common` first if `add-apt-repository` is not available on your system.

### Using AUR (Arch Linux only)
```shell script
sudo add-apt-repository ppa:virtuslab/git-machete
sudo apt-get update
sudo apt-get install -y python3-git-machete
```

### Using AUR (Arch Linux)

Install the AUR package [git-machete](https://aur.archlinux.org/packages/git-machete) using an AUR helper of your preference.

### Using Nix
### Using Nix (macOS & most Linux distributions)

On MacOS and most Linux distributions, you can install via [Nix](https://nixos.org/nix/):
On macOS and most Linux distributions, you can install via [Nix](https://nixos.org/nix/):

```shell script
# If you haven't set up any channels:
nix-channel --add https://nixos.org/channels/nixos-unstable unstable
nix-channel --add https://nixos.org/channels/nixos-unstable unstable # if you haven't set up any channels yet
nix-env -i git-machete
```

Expand Down
4 changes: 2 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- improved: git-machete is compatible with git >= 2.0.0
- added: functional tests
- added: automatic push to brew tap repository
- added: automatic push to Ubuntu PPA

## New in git-machete 2.12.6

Expand Down Expand Up @@ -132,8 +133,7 @@

## New in git-machete 2.7.0

- improved: during `traverse`, if there's a branch that's untracked, no longer rely on `git push` implicitly picking `origin` as the default remote;
instead, either choose the only existing remote if there's just one defined (even if it's not `origin`), or let the user pick the remote explicitly if there is more than one
- improved: during `traverse`, if there's a branch that's untracked, no longer rely on `git push` implicitly picking `origin` as the default remote

## New in git-machete 2.6.2

Expand Down
27 changes: 0 additions & 27 deletions ci/Dockerfile-deb-build

This file was deleted.

9 changes: 0 additions & 9 deletions ci/Dockerfile-deb-test-python

This file was deleted.

9 changes: 0 additions & 9 deletions ci/Dockerfile-deb-test-python3

This file was deleted.

7 changes: 0 additions & 7 deletions ci/README-deb.md

This file was deleted.

3 changes: 3 additions & 0 deletions ci/apt-ppa/.env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Can be used by docker-compose for building the `ppa-upload` image locally
USER_ID=1000
GROUP_ID=1000
1 change: 1 addition & 0 deletions ci/apt-ppa/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
16 changes: 16 additions & 0 deletions ci/apt-ppa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Automated PPA upload

```shell script
cd ci/apt-ppa
cp .env-sample .env # and optionally edit if needed to match your current user's UID/GID
. upload-export-vars
docker-compose up --build ppa-upload
```


## Test the availability of the uploaded package

```shell script
cd ci/apt-ppa
docker-compose up --build ppa-test-install
```
18 changes: 18 additions & 0 deletions ci/apt-ppa/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3'
services:
ppa-upload:
image: virtuslab/git-machete-ci-ppa-upload:${DOCKER_TAG:-latest}
build:
context: .
dockerfile: upload.Dockerfile
args:
- user_id=${USER_ID:-0}
- group_id=${GROUP_ID:-0}
volumes:
- ${PWD}/../..:/home/ci-user/git-machete
env_file:
- upload-vars.env
ppa-test-install:
build:
context: .
dockerfile: test-install.Dockerfile
9 changes: 9 additions & 0 deletions ci/apt-ppa/test-install-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e -x

apt-get update
apt-get install -y python3-git-machete
git machete --version
apt-get purge -y python3-git-machete
! command -v git-machete
8 changes: 8 additions & 0 deletions ci/apt-ppa/test-install.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ubuntu

RUN apt-get update && apt-get install -y git software-properties-common
RUN add-apt-repository ppa:virtuslab/git-machete

COPY test-install-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]
7 changes: 7 additions & 0 deletions ci/apt-ppa/upload-dput.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

; We need to use SFTP since FTP is insecure & completely blocked on Travis
[ppa]
fqdn = ppa.launchpad.net
method = sftp
incoming = ~virtuslab/ubuntu/git-machete/
login = virtuslab
29 changes: 29 additions & 0 deletions ci/apt-ppa/upload-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

{ [[ -f setup.py ]] && grep -q "name='git-machete'" setup.py; } || {
echo "Error: the repository should be mounted as a volume under $(pwd)"
exit 1
}

set -e -o pipefail -u
echo "$GPG_PRIVATE_KEY_PASSPHRASE" > ~/.gnupg/passphrase.txt
echo "$GPG_PRIVATE_KEY_CONTENTS_BASE64" | base64 -d > ~/.gnupg/private-keys-v1.d/"$GPG_PRIVATE_KEY_ID".key
echo "$GPG_PUBRING_KEYBOX_CONTENTS_BASE64" | base64 -d > ~/.gnupg/pubring.kbx
echo "$GPG_TRUSTDB_GPG_CONTENTS_BASE64" | base64 -d > ~/.gnupg/trustdb.gpg
echo "$SSH_PRIVATE_KEY_CONTENTS_BASE64" | base64 -d > ~/.ssh/id_rsa
chmod 700 ~/.ssh/id_rsa

set -x
VERSION=$(cut -d\' -f2 git_machete/__init__.py)
export VERSION
envsubst '$VERSION' < debian/files.envsubst > debian/files
cp LICENSE debian/copyright
# The first version ever released to PPA is 2.12.7, so we skip everything older than that from the changelog.
sed '/## New in git-machete 2\.12\.6/,$d' RELEASE_NOTES.md | awk -f ~/release-notes-to-changelog.awk > debian/changelog

# Since we upload over SFTP, we need to whitelist the host first to avoid the prompt.
ssh-keyscan ppa.launchpad.net > ~/.ssh/known_hosts

# -p flag points to a script that wraps gpg so that we don't get asked for password to the private key on TTY.
debuild -S -p"$HOME/gpg-sign.sh"
dput ppa:virtuslab/git-machete ../python3-git-machete_*_source.changes
7 changes: 7 additions & 0 deletions ci/apt-ppa/upload-export-vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

export GPG_PRIVATE_KEY_PASSPHRASE=$(cat ~/.gnupg/passphrase.txt)
export GPG_PRIVATE_KEY_ID=$(basename --suffix=.key ~/.gnupg/private-keys-v1.d/*.key)
export GPG_PRIVATE_KEY_CONTENTS_BASE64=$(base64 --wrap=0 ~/.gnupg/private-keys-v1.d/$GPG_PRIVATE_KEY_ID.key)
export GPG_PUBRING_KEYBOX_CONTENTS_BASE64=$(base64 --wrap=0 ~/.gnupg/pubring.kbx)
export GPG_TRUSTDB_GPG_CONTENTS_BASE64=$(base64 --wrap=0 ~/.gnupg/trustdb.gpg)
export SSH_PRIVATE_KEY_CONTENTS_BASE64=$(base64 --wrap=0 ~/.ssh/launchpad/id_rsa)
4 changes: 4 additions & 0 deletions ci/apt-ppa/upload-gpg-sign.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# --pinentry-mode=loopback is the only option (--batch, --yes, --passphrase-fd 0 all had no effect) that makes it possible for gpg NOT to ask for password via a TTY within Docker context.
gpg --pinentry-mode=loopback --passphrase-file="$HOME/.gnupg/passphrase.txt" "$@"
23 changes: 23 additions & 0 deletions ci/apt-ppa/upload-release-notes-to-changelog.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Requires GNU awk (gawk) due to the use of |&

function trailer(v) {
"git log -1 --date=rfc2822 --format=%cd v" v " 2>/dev/null || date --rfc-email" |& getline date
printf "\n -- Pawel Lipski <[email protected]> %s\n\n\n", date
}

/## New in git-machete .*/ {
if (version) {
trailer(version)
}
match($0, /[0-9.]+/)
newVersion = substr($0, RSTART, RLENGTH)
version = newVersion
print "python3-git-machete (" version ") bionic; urgency=medium\n"
}

/^- / {
gsub("^- ", " * ")
print $0
}

END { trailer(version) }
16 changes: 16 additions & 0 deletions ci/apt-ppa/upload-travis-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -e -o pipefail -u -x

DOCKER_TAG=$(git rev-parse HEAD:ci/apt-ppa/)
export DOCKER_TAG
cd ci/apt-ppa/

# If the image corresponding to the current state of ci/apt-ppa/ is missing, build it and push to Docker Hub.
docker-compose pull ppa-upload || {
docker-compose build --build-arg user_id="$(id -u)" --build-arg group_id="$(id -g)" ppa-upload
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker-compose push ppa-upload
}

docker-compose up --exit-code-from=ppa-upload ppa-upload
6 changes: 6 additions & 0 deletions ci/apt-ppa/upload-vars.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GPG_PRIVATE_KEY_PASSPHRASE
GPG_PRIVATE_KEY_ID
GPG_PRIVATE_KEY_CONTENTS_BASE64
GPG_PUBRING_KEYBOX_CONTENTS_BASE64
GPG_TRUSTDB_GPG_CONTENTS_BASE64
SSH_PRIVATE_KEY_CONTENTS_BASE64
29 changes: 29 additions & 0 deletions ci/apt-ppa/upload.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ubuntu

RUN apt-get update && apt-get install -y debhelper devscripts fakeroot gawk python3-all python3-paramiko python3-setuptools

ARG user_id
ARG group_id

RUN "[" ${user_id:-0} -ne 0 ] \
&& [ ${group_id:-0} -ne 0 ] \
&& groupadd -g ${group_id} ci-user \
&& useradd -l -u ${user_id} -g ci-user ci-user \
&& install -d -m 0755 -o ci-user -g ci-user /home/ci-user

USER ci-user

RUN install -d -m 0700 ~/.gnupg/ ~/.gnupg/private-keys-v1.d/ ~/.ssh/

COPY upload-dput.cf /etc/dput.cf

COPY --chown=ci-user:ci-user upload-gpg-sign.sh /home/ci-user/gpg-sign.sh
RUN chmod +x ~/gpg-sign.sh

COPY --chown=ci-user:ci-user upload-release-notes-to-changelog.awk /home/ci-user/release-notes-to-changelog.awk

COPY --chown=ci-user:ci-user upload-entrypoint.sh /home/ci-user/entrypoint.sh
RUN chmod +x ~/entrypoint.sh
CMD ["/home/ci-user/entrypoint.sh"]

WORKDIR /home/ci-user/git-machete
File renamed without changes.
4 changes: 4 additions & 0 deletions debian/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These files are automatically generated by ci/apt-ppa/upload-entrypoint.sh: debian/changelog from RELEASE_NOTES.md, debian/copyright from LICENSE, debian/files from debian/files.envsubst
changelog
copyright
files
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
12 changes: 12 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Source: python3-git-machete
Maintainer: Pawel Lipski <[email protected]>
Build-Depends: debhelper,dh-python,python3-all,python3-setuptools
Section: devel
Priority: optional
Standards-Version: 4.1.4
X-Python3-Version: >= 3.6

Package: python3-git-machete
Architecture: any
Description: Probably the sharpest git repository organizer & rebase workflow automation tool you've ever seen
Depends: ${python3:Depends}, python3-pkg-resources
1 change: 1 addition & 0 deletions debian/files.envsubst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3-git-machete_$VERSION_source.buildinfo devel optional
7 changes: 7 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/make -f

#export DH_VERBOSE = 1
export PYBUILD_NAME = git-machete

%:
dh $@ --with python3 --buildsystem=pybuild
Loading

0 comments on commit f3d53e4

Please sign in to comment.