| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Automation for Travis CI.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # soil/travis.sh <function name>
|
| 7 | #
|
| 8 | # This contains setup for travis-ci.oilshell.org (the server), as well as the
|
| 9 | # client, which is an ephemeral machine for each Travis run.
|
| 10 | #
|
| 11 | # The server needs a public key and the client needs a private key.
|
| 12 | #
|
| 13 | # Other TODO:
|
| 14 | #
|
| 15 | # And I probably need a cron job on my own domain to administer oilshell.org
|
| 16 | # - wwz log files
|
| 17 | # - backup (does sync_logs.sh do this?)
|
| 18 | # - cleanup
|
| 19 | # - clean up old travis CI build logs
|
| 20 | # - back up /downloads/ dir
|
| 21 | #
|
| 22 | # Related docs:
|
| 23 | #
|
| 24 | # https://docs.travis-ci.com/user/environment-variables/#defining-encrypted-variables-in-travisyml
|
| 25 |
|
| 26 | # https://oncletom.io/2016/travis-ssh-deploy/
|
| 27 | # https://github.com/dwyl/learn-travis/blob/master/encrypted-ssh-keys-deployment.md
|
| 28 |
|
| 29 | set -o nounset
|
| 30 | set -o pipefail
|
| 31 | set -o errexit
|
| 32 |
|
| 33 | source soil/common.sh
|
| 34 | source soil/web-worker.sh
|
| 35 |
|
| 36 | #
|
| 37 | # Key Generation: One Time Setup
|
| 38 | #
|
| 39 |
|
| 40 | # Need to pass --pre because I hit this bug. Does not inspire confidence.
|
| 41 | # https://github.com/travis-ci/travis.rb/issues/711
|
| 42 |
|
| 43 | deps() {
|
| 44 | # travis gem needed to encrypt ssh private key (also adds to .travis.yml)
|
| 45 | sudo gem install travis --pre # --version '1.8.10'
|
| 46 | }
|
| 47 |
|
| 48 | keygen() {
|
| 49 | ssh-keygen -t rsa -b 4096 -C "travis-ci.oilshell" -f rsa_travis
|
| 50 | }
|
| 51 |
|
| 52 | encrypt-private-key() {
|
| 53 | ### Use travis gem to add an encrypted version to .travis.yml
|
| 54 |
|
| 55 | # 'travis login' first
|
| 56 |
|
| 57 | #travis encrypt-file ./rsa_travis --add
|
| 58 | travis encrypt-file ./rsa_travis soil/rsa_travis.enc --add
|
| 59 | }
|
| 60 |
|
| 61 | deploy-public-key() {
|
| 62 | # note: permissions must be 700
|
| 63 | ssh travis_admin@travis-ci.oilshell.org mkdir -v -p .ssh
|
| 64 |
|
| 65 | # TODO: or append it?
|
| 66 | scp rsa_travis.pub travis_admin@travis-ci.oilshell.org:.ssh/authorized_keys
|
| 67 | }
|
| 68 |
|
| 69 | decrypt-key() {
|
| 70 | local out=$1
|
| 71 | openssl aes-256-cbc \
|
| 72 | -K $encrypted_a65247dffca0_key -iv $encrypted_a65247dffca0_iv \
|
| 73 | -in soil/rsa_travis.enc -out $out -d
|
| 74 | }
|
| 75 |
|
| 76 | publish-html-assuming-ssh-key() {
|
| 77 | if true; then
|
| 78 | deploy-job-results 'travis-' \
|
| 79 | TRAVIS_JOB_NAME \
|
| 80 | TRAVIS_OS_NAME \
|
| 81 | TRAVIS_TIMER_START_TIME \
|
| 82 | TRAVIS_BUILD_WEB_URL \
|
| 83 | TRAVIS_JOB_WEB_URL \
|
| 84 | TRAVIS_BUILD_NUMBER \
|
| 85 | TRAVIS_JOB_NUMBER \
|
| 86 | TRAVIS_BRANCH \
|
| 87 | TRAVIS_COMMIT \
|
| 88 | TRAVIS_COMMIT_MESSAGE
|
| 89 | else
|
| 90 | deploy-test-wwz # dummy data that doesn't depend on the build
|
| 91 | fi
|
| 92 |
|
| 93 | write-jobs-raw 'travis-'
|
| 94 | remote-rewrite-jobs-index 'travis-'
|
| 95 |
|
| 96 | # note: we could speed jobs up by doing this separately?
|
| 97 | remote-cleanup-jobs-index 'travis-'
|
| 98 |
|
| 99 | # soil/worker.sh recorded this for us
|
| 100 | return $(cat _tmp/soil/exit-status.txt)
|
| 101 | }
|
| 102 |
|
| 103 | publish-html() {
|
| 104 | local privkey=/tmp/rsa_travis
|
| 105 |
|
| 106 | decrypt-key $privkey
|
| 107 | chmod 600 $privkey
|
| 108 | eval "$(ssh-agent -s)"
|
| 109 | ssh-add $privkey
|
| 110 |
|
| 111 | publish-html-assuming-ssh-key
|
| 112 | }
|
| 113 |
|
| 114 | #
|
| 115 | # Maintenance
|
| 116 | #
|
| 117 |
|
| 118 | # Sometimes the cache gets stale and you have to delete it. Weird.
|
| 119 | delete-caches() {
|
| 120 | travis cache -d
|
| 121 | }
|
| 122 |
|
| 123 | if test $(basename $0) = 'travis.sh'; then
|
| 124 | "$@"
|
| 125 | fi
|