update-nur-search.sh: add script to deploy package.json

This commit is contained in:
Ingolf Wagner 2020-03-12 01:32:27 +08:00
parent d8f72669b7
commit 8aae37c250
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
5 changed files with 106 additions and 34 deletions

View file

@ -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

View file

@ -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

25
ci/lib/setup-git.sh Normal file
View file

@ -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

View file

@ -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
}

34
ci/update-nur-search.sh Executable file
View file

@ -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