Add auto update using Travis

This commit is contained in:
Elis Hirwing 2018-12-28 16:01:55 +01:00 committed by adisbladis
parent 1b2aea39fc
commit 0f83fd684e
No known key found for this signature in database
GPG key ID: ED58F95069B004F5
5 changed files with 118 additions and 2 deletions

16
.travis.yml Normal file
View file

@ -0,0 +1,16 @@
language: nix
os: linux
env:
global:
- SSH_KEY="/tmp/deploy_rsa"
- TARGET_BRANCH="master"
- DEPLOY_BRANCH="master"
- GIT_NAME="EXWM-Updater"
- GIT_EMAIL="exwm-updater@example.org"
before_install:
- openssl aes-256-cbc -K $encrypted_88023bb2dbf0_key -iv $encrypted_88023bb2dbf0_iv -in .travis/deploy_rsa.enc -out $SSH_KEY -d
script:
- "./update"
after_success:
- "./.travis/deploy.sh"

38
.travis/README.org Normal file
View file

@ -0,0 +1,38 @@
* Set up of ssh key
#+begin_src sh
# Generate SSH key
ssh-keygen -t rsa -b 4096 -C 'build@travis-ci.org' -f ./.travis/deploy_rsa
# Get the travis util
nix-shell --run fish -p travis
# Generate a github access token to use with travis:
# https://github.com/settings/tokens
#
# I gave it all scopes for user and repo.
# Log in to travis
travis login --user etu --github-token <your-token-here>
# Encrypt the file using travis
travis encrypt-file .travis/deploy_rsa --add
# Move the encrypted file to the travis directory
mv deploy_rsa.enc .travis/
# Add the public key as a deploy key to the repo with write-access:
# https://github.com/adisbladis/exwm-overlay/settings/keys/new
cat .travis/deploy_rsa.pub
# Remove secret private and the public key
rm -rf .travis/deploy_rsa .travis/deploy_rsa.pub
# Then just go ahead and commit .travis/deploy_rsa
#+end_src
* Set up travis build
Copy my =.travis.yml= file. Alter the names of the the variables in
=before_install= based on the names of the names of the variables here:
https://travis-ci.org/etu/exwm-overlay/settings
You should also make a copy of =.travis/deploy.sh=.

62
.travis/deploy.sh Executable file
View file

@ -0,0 +1,62 @@
#!/bin/bash
set -e
REPO=$(git config remote.origin.url)
if [ -n "$TRAVIS_BUILD_ID" ]; then
# When running on Travis we need to use SSH to deploy to GitHub
#
# The following converts the repo URL to an SSH location,
# decrypts the SSH key and sets up the Git config with
# the correct user name and email (globally as this is a
# temporary travis environment)
#
# Set the following environment variables in the travis configuration (.travis.yml)
#
# DEPLOY_BRANCH - The only branch that Travis should deploy from
# GIT_NAME - The Git user name
# GIT_EMAIL - The Git user email
#
echo GIT_NAME: $GIT_NAME
echo GIT_EMAIL: $GIT_EMAIL
if [ "$TRAVIS_BRANCH" != "$DEPLOY_BRANCH" ]; then
echo "Travis should only deploy from the DEPLOY_BRANCH ($DEPLOY_BRANCH) branch"
exit 0
fi
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo "Travis should not deploy from pull requests"
exit 0
fi
# Switch both git and https protocols as we don't know which travis
# is using today (it changed in the past!)
REPO=${REPO/git:\/\/github.com\//git@github.com:}
REPO=${REPO/https:\/\/github.com\//git@github.com:}
# Add SSH key to SSH agent
chmod 600 $SSH_KEY
eval `ssh-agent -s`
ssh-add $SSH_KEY
git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"
# Set a rw remote
git remote set-url origin $REPO
# Checkout master
git fetch origin
git checkout master
# Add changes
git add repos/
# Commit changes
git commit -m "Built from commit $REV"
# Push changes
git push $REPO $TARGET_BRANCH
fi

BIN
.travis/deploy_rsa.enc Normal file

Binary file not shown.

4
update
View file

@ -1,12 +1,12 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p curl jq nix
#! nix-shell -i bash -p curl xmlstarlet nix coreutils
set -euxo pipefail
function update_repo() {
repo=$1
echo $repo
commit_sha=$(curl "https://api.github.com/repos/ch11ng/$repo/commits?sha=master" | jq -r 'first.sha')
commit_sha=$(curl "https://github.com/ch11ng/$repo/commits/master.atom" | xmlstarlet sel -N atom="http://www.w3.org/2005/Atom" -t -m /atom:feed/atom:entry -v atom:id -n | head -n 1 | cut -d '/' -f 2)
digest=$(nix-prefetch-url --unpack "https://github.com/ch11ng/$repo/archive/${commit_sha}.tar.gz")
echo "{\"rev\": \"${commit_sha}\", \"sha256\": \"${digest}\"}" > repos/$repo.json
}