diff --git a/.travis.yml b/.travis.yml index 337ec47f1..640d5066e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ language: nix -script: - - bash ci/deploy.sh notifications: irc: @@ -10,3 +8,15 @@ notifications: - "irc.freenode.net#nixos-nur" template: - "%{result} - %{branch} \"%{commit_subject}\" %{build_url}" + +jobs: + include: + - name: deploy to nur-combined + script: bash ci/deploy.sh + if: branch = master + + - name: update nur-search/data/packages.json + script: ci/update-nur-search.sh + if: branch = master + + diff --git a/ci/deploy.sh b/ci/deploy.sh index 1bcb8262f..242eb7fff 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -4,27 +4,8 @@ set -eu -o pipefail # Exit with nonzero exit code if anything fails DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" -is-automatic-update() { - [[ "$TRAVIS_EVENT_TYPE" == "cron" ]] || [[ "$TRAVIS_EVENT_TYPE" == "api" ]] -} - -if is-automatic-update; then - keys_dir=$(mktemp -d) - openssl aes-256-cbc \ - -K $encrypted_080f214a372c_key \ - -iv $encrypted_080f214a372c_iv \ - -in ci/keys.tar.gz.enc -out ci/keys.tar.gz -d - tar -C "$keys_dir" -xzvf ci/keys.tar.gz - - eval "$(ssh-agent -s)" - - chmod 600 "${keys_dir}/ssh-key" - ssh-add "${keys_dir}/ssh-key" - gpg --import "${keys_dir}/gpg-private-key" - rm -rf "$keys_dir" -fi - -export encrypted_080f214a372c_key= encrypted_080f214a372c_iv= +source ${DIR}/lib/travis-functions.sh +source ${DIR}/lib/setup-git.sh nix-build --quiet release.nix @@ -37,16 +18,7 @@ set -x result/bin/nur update nix-build -if ! is-automatic-update; then - # Pull requests and commits to other branches shouldn't try to deploy, just build to verify - echo "Skipping deploy; just doing a build." - exit 0 -fi - -git config --global user.name "Nur a bot" -git config --global user.email "joerg.nur-bot@thalheim.io" -git config --global user.signingkey "B4E40EEC9053254E" -git config --global commit.gpgsign true +dont-continue-on-pull-requests git clone git@github.com:nix-community/nur-combined @@ -58,7 +30,6 @@ if [[ -z "$(git diff --exit-code)" ]]; then echo "No changes to the output on this push; exiting." else git add --all repos.json* - git commit -m "automatic update" git push git@github.com:nix-community/NUR HEAD:master fi diff --git a/ci/lib/setup-git.sh b/ci/lib/setup-git.sh new file mode 100644 index 000000000..163a0819c --- /dev/null +++ b/ci/lib/setup-git.sh @@ -0,0 +1,25 @@ +# only source this file +# to setup git to push and pull repositories via ssh +# ================================================== + +# set up git and ssh +# ------------------ +keys_dir=$(mktemp -d) +openssl aes-256-cbc \ + -K $encrypted_080f214a372c_key \ + -iv $encrypted_080f214a372c_iv \ + -in ci/keys.tar.gz.enc -out ci/keys.tar.gz -d +tar -C "$keys_dir" -xzvf ci/keys.tar.gz +eval "$(ssh-agent -s)" +chmod 600 "${keys_dir}/ssh-key" +ssh-add "${keys_dir}/ssh-key" +gpg --import "${keys_dir}/gpg-private-key" +rm -rf "$keys_dir" + +export encrypted_080f214a372c_key= encrypted_080f214a372c_iv= + +git config --global user.name "Nur a bot" +git config --global user.email "joerg.nur-bot@thalheim.io" +git config --global user.signingkey "B4E40EEC9053254E" +git config --global commit.gpgsign true + diff --git a/ci/lib/travis-functions.sh b/ci/lib/travis-functions.sh new file mode 100644 index 000000000..7197eb039 --- /dev/null +++ b/ci/lib/travis-functions.sh @@ -0,0 +1,32 @@ +# only source this file +# to load functions that help with travis.ci +# ========================================== + + +is-automatic-update() { + [[ "$TRAVIS_EVENT_TYPE" == "cron" ]] || [[ "$TRAVIS_EVENT_TYPE" == "api" ]] +} + +is-pull-request(){ + [[ "$TRAVIS_PULL_REQUEST" != "false" ]] +} + +is-not-pull-request(){ + [[ "$TRAVIS_PULL_REQUEST" = "false" ]] +} + +dont-continue-on-pull-requests() { + if is-pull-request + then + echo "stopping because this is a pull request" + exit 0 + fi +} + +only-continue-on-pull-requests() { + if is-not-pull-request + then + echo "stopping because this is not a pull request" + exit 0 + fi +} diff --git a/ci/update-nur-search.sh b/ci/update-nur-search.sh new file mode 100755 index 000000000..51835b935 --- /dev/null +++ b/ci/update-nur-search.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -eu -o pipefail # Exit with nonzero exit code if anything fails + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" + +source ${DIR}/lib/travis-functions.sh + +dont-continue-on-pull-requests + +source ${DIR}/lib/setup-git.sh + + +# build package.json for nur-search +# --------------------------------- + +nix-build --quiet release.nix + +git clone git@github.com:nix-community/nur-search + +result/bin/nur index . > nur-search/data/packages.json + +# rebuild and publish nur-search repository +# ----------------------------------------- + +cd nur-search +if [[ ! -z "$(git diff --exit-code)" ]]; then + git add ./data/packages.json + git commit -m "automatic update package.json" + git push origin master + nix-shell --run "make && make publish" +else + echo "nothings changed will not commit anything" +fi