diff --git a/.github/workflows/agent.yml b/.github/workflows/agent.yml index 2a383213..1b954c8c 100644 --- a/.github/workflows/agent.yml +++ b/.github/workflows/agent.yml @@ -4,8 +4,8 @@ on: push: branches: [ master ] tags: - # Push events to matching v*, i.e. v1.0, v20.15.10 - - 'v*.*.*' + # Making sure this doesn't trigger when tags are pushed + - 'v[0-9]+.[0-9]+.[0-9]+.[0-9]+.[0-9]+.[0-9]' pull_request: branches: [ master ] diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..4545bd51 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,323 @@ +os: linux +dist: xenial +language: shell + +env: + global: + # GO VERSION is set here with GIMME_GO_VERSION see: https://github.com/travis-ci/gimme + # may also want to run `go mod edit -go=1.20` to fix go.mod as well + - GIMME_GO_VERSION=1.20 GIMME_OS=linux GIMME_ARCH=amd64 + +branches: + only: + - master + # https://docs.travis-ci.com/user/customizing-the-build/#safelisting-or-blocklisting-branches + - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ + +stages: + - 'Fmt' + - 'Tests' + - 'Trigger FSC Tests' + - 'Test Build using latest tag (no upload)' + - 'Build, Upload and Publish (draft)' + - 'Test github release assets' + - 'Publish (real)' + - 'Readme-sync-preview' + - 'Readme-sync' + +jobs: + + include: + + - stage: Fmt + script: + - test -z "$(go fmt ./pkg/...)" + - stage: Tests + name: hadolint + os: linux + dist: xenial + script: + - make -e lint + - for f in `find scripts/dockerfiles -type f`; do echo $f; docker run --rm -i hadolint/hadolint:v2.1.0 < $f; done + + - stage: Tests + name: coveralls + os: linux + dist: xenial + script: + - make -e cover COVER_FILE=coverage.txt + after_success: + - go get github.com/mattn/goveralls + - $GOPATH/bin/goveralls -coverprofile=coverage.txt -service=travis-ci + + - stage: Tests + name: sourceclear + os: linux + dist: xenial + addons: + srcclr: true + script: + - go get -v -d ./... + + - stage: Tests + name: windows build.ps1 test + os: windows + language: shell + before_script: skip + script: + - PowerShell -Command Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser + - PowerShell -File "scripts\build.ps1" noninteractive + - PowerShell -File "scripts\check_exe.ps1" + after_success: + - ( [ ${TRAVIS_EVENT_TYPE} = "push" ] && [ ! -z ${TRAVIS_TAG} ] ) && scripts/upload_artifacts.sh + + - stage: Tests + name: acceptance + os: linux + dist: xenial + language: python + python: "3.9" + install: + - pip install -r tests/acceptance/requirements.txt + script: + - MYHOST="http://localhost:8080" make test-acceptance + + - stage: 'Trigger FSC Tests' + if: (branch = master AND type = push) OR type = pull_request OR tag IS present + env: + SDK=agent + SDK_BRANCH=$(if [ -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then echo ${TRAVIS_BRANCH}; else echo "$TRAVIS_PULL_REQUEST_BRANCH"; fi) + EVENT_TYPE=$TRAVIS_EVENT_TYPE + PULL_REQUEST_SLUG=$TRAVIS_PULL_REQUEST_SLUG + PULL_REQUEST_SHA=$TRAVIS_PULL_REQUEST_SHA + GITHUB_REPOSITORY=$TRAVIS_REPO_SLUG + UPSTREAM_REPO=$TRAVIS_REPO_SLUG + UPSTREAM_SHA=$TRAVIS_COMMIT + PULL_REQUEST_NUMBER=$TRAVIS_PULL_REQUEST + TOKEN=$GITHUB_TOKEN + cache: false + before_install: + ./scripts/pull_travis_ci_tools.sh + install: skip + script: + - "$HOME/travisci-tools/trigger-script-with-status-update.sh" + + - stage: 'Test Build using latest tag (no upload)' + name: linux + os: linux + dist: xenial + script: + - export APP_VERSION=$(git describe --abbrev=0 --tags | tr -d '^v') + - $TRAVIS_BUILD_DIR/scripts/ci_create_packages.sh + - $TRAVIS_BUILD_DIR/scripts/ci_build_generate_secret.sh + + - stage: 'Build, Upload and Publish (draft)' + if: type = push AND tag IS present AND tag =~ /^v[0-9]+\.[0-9]+\.[0-9]+(\-beta)?[0-9]*$/ + name: linux + os: linux + dist: xenial + + # The version of the app is set via git tag (below). This is picked up in the Makefile and compiled into the binary via LDFLAGS. + # It is also picked up in scripts/Makefile.ci to be used in the package name when they are built. + + env: APP_VERSION=${TRAVIS_TAG#v} + + before_install: + - ./scripts/pull_travis_ci_tools.sh + install: + # installs hub to ~/bin + - $HOME/travisci-tools/release_github/install_hub.sh + - export PATH=$HOME/bin:$HOME/travisci-tools/release_github:$PATH + + script: + # now we're going to create packages & upload packages + - $TRAVIS_BUILD_DIR/scripts/ci_create_packages.sh && $TRAVIS_BUILD_DIR/scripts/ci_upload_packages.sh + # create the github release (draft) + - release_github_v2.sh "$TRAVIS_TAG" + # attach generate_secret to the github release + - $TRAVIS_BUILD_DIR/scripts/ci_build_generate_secret.sh && $TRAVIS_BUILD_DIR/scripts/ci_attach_generate_secret.sh + + - stage: 'Test github release assets' + if: type = push AND tag IS present AND tag =~ /^v[0-9]+\.[0-9]+\.[0-9]+(\-beta)?[0-9]*$/ + name: linux + os: linux + env: APP_VERSION=${TRAVIS_TAG#v} + + before_install: + - ./scripts/pull_travis_ci_tools.sh + + install: + # installs hub to ~/bin + - $HOME/travisci-tools/release_github/install_hub.sh + - export PATH=$HOME/bin:$HOME/travisci-tools/slack:$PATH + + before_script: skip + + script: + - hub release download $(git describe --abbrev=0 --tags) -i '*-linux-amd64-*' + - tar xvfz generate_secret-linux-amd64-${APP_VERSION}.tar.gz -C /tmp + - /tmp/generate_secret + + after_failure: + - SLACK_TEXT="${APP_VERSION} $TRAVIS_OS_NAME assets failed verification." send_to_slack.sh + + - stage: 'Test github release assets' + if: type = push AND tag IS present AND tag =~ /^v[0-9]+\.[0-9]+\.[0-9]+(\-beta)?[0-9]*$/ + name: darwin + os: osx + env: APP_VERSION=${TRAVIS_TAG#v} + + before_install: + - ./scripts/pull_travis_ci_tools.sh + - HOMEBREW_NO_AUTO_UPDATE=1 brew install jq + + install: + # installs hub to ~/bin + - $HOME/travisci-tools/release_github/install_hub.sh + - export PATH=$HOME/bin:$HOME/travisci-tools/slack:$PATH + + before_script: skip + + script: + - hub release download $(git describe --abbrev=0 --tags) -i '*-darwin-amd64-*' + - tar xvfz generate_secret-darwin-amd64-${APP_VERSION}.tar.gz -C /tmp + - /tmp/generate_secret + + after_failure: + - SLACK_TEXT="${APP_VERSION} $TRAVIS_OS_NAME assets failed verification." send_to_slack.sh + + - stage: 'Test github release assets' + if: type = push AND tag IS present AND tag =~ /^v[0-9]+\.[0-9]+\.[0-9]+(\-beta)?[0-9]*$/ + name: windows + os: windows + env: APP_VERSION=${TRAVIS_TAG#v} + + before_install: + - ./scripts/pull_travis_ci_tools.sh + + install: + # installs hub to ~/bin + - $HOME/travisci-tools/release_github/install_hub.sh + - export PATH=$HOME/bin:$HOME/travisci-tools/slack:$PATH + + before_script: skip + + script: + - hub release download $(git describe --abbrev=0 --tags) -i '*-windows-amd64-*' + - tar xvfz generate_secret-windows-amd64-${APP_VERSION}.tar.gz -C /tmp + - /tmp/generate_secret.exe + + after_failure: + - SLACK_TEXT="${APP_VERSION} $TRAVIS_OS_NAME assets failed verification." send_to_slack.sh + + - stage: 'Publish (real)' + if: type = push AND tag IS present AND tag =~ /^v[0-9]+\.[0-9]+\.[0-9]+(\-beta)?[0-9]*$/ + name: publish and notify in slack + os: linux + env: APP_VERSION=${TRAVIS_TAG#v} + + before_install: + - ./scripts/pull_travis_ci_tools.sh + + install: + # installs hub to ~/bin + - $HOME/travisci-tools/release_github/install_hub.sh + - export PATH=$HOME/bin:$HOME/travisci-tools/slack:$PATH + + before_script: skip + + script: + - SLACK_TEXT="${APP_VERSION} all assets verified. Publishing https://github.com/optimizely/agent/releases/tag/${TRAVIS_TAG}" send_to_slack.sh + # how to use hub: https://hub.github.com/hub.1.html + - hub release edit --draft=false -m "" ${TRAVIS_TAG} + + - stage: 'Readme-sync-preview' + # publishes changes in your docs pull request (ie, contains changes to /docs/readme-sync directory) to https://rollouts-sandbox-doc-test.readme.io/ for previewing before + # committing to master + before_script: skip + cache: false + # translation: if we're committing to a pull request... + if: false AND type = pull_request + + language: node_js + install: + + + # make dir $HOME/readme-sync2 & clone readme-sync2 repo to it; install dependencies + + - mkdir $HOME/readme-sync2 && pushd $HOME/readme-sync2 && git init && git pull https://$CI_USER_TOKEN@github.com/optimizely/readme-sync2.git && popd + - source ~/.nvm/nvm.sh && cd $HOME/readme-sync2 && nvm install && npm install + + script: + # we need to be in $TRAVIS_BUILD_DIR in order to run the following git diff properly + - cd $TRAVIS_BUILD_DIR + + # print which docs changed in this Pull Request (and which therefore we expect to be updated by readme-sync-2 tool): + - CHANGED_DOCS_FILES=($(git diff --name-only $TRAVIS_COMMIT_RANGE -- docs/readme-sync)) + - echo $CHANGED_DOCS_FILES + + # only if changes were made in the docs/readme-sync repo, trigger this readme-sync stage and sync the docs + # to staging readme project at https://rollouts-sandbox-doc-test.readme.io/docs + + + # build v3.1 docs to v 1.0 of readme staging project + - git diff --quiet $TRAVIS_COMMIT_RANGE -- docs/readme-sync/v3.1 || ( cd $HOME/readme-sync2 && npx ts-node sync/index.ts --apiKey $README_SYNC_API_KEY_PREVIEW --version 1.0 --docs $TRAVIS_BUILD_DIR/docs/readme-sync/v3.1) + # build v4.0 docs to v 1.5 of staging project + - git diff --quiet $TRAVIS_COMMIT_RANGE -- docs/readme-sync/v4.0 || ( cd $HOME/readme-sync2 && npx ts-node sync/index.ts --apiKey $README_SYNC_API_KEY_PREVIEW --version 1.5 --docs $TRAVIS_BUILD_DIR/docs/readme-sync/v4.0) + + - stage: 'Readme-sync' + before_script: skip + cache: false + # translation: if we're merging into a master branch... + if: false AND type = push AND branch = master + + language: node_js + install: + + + # make dir $HOME/readme-sync2 & clone readme-sync2 repo to it; install dependencies + + - mkdir $HOME/readme-sync2 && pushd $HOME/readme-sync2 && git init && git pull https://$CI_USER_TOKEN@github.com/optimizely/readme-sync2.git && popd + - source ~/.nvm/nvm.sh && cd $HOME/readme-sync2 && nvm install && npm install + + script: + # we need to be in $TRAVIS_BUILD_DIR in order to run the following git diff properly + - cd $TRAVIS_BUILD_DIR + + #print which docs changed in this Pull Request (and which therefore we expect to be updated by readme-sync-2 tool): + - CHANGED_DOCS_FILES=($(git diff --name-only $TRAVIS_COMMIT_RANGE -- docs/readme-sync)) + - echo $CHANGED_DOCS_FILES + + #only if changes were made in the docs/readme-sync repo, trigger this readme-sync stage and sync the docs to full stack readme project (https://dash.readme.com/project/full-stack/v4.0/docs/welcome) + # sync v3.1 docs folder to readme project v 3.1 + - git diff --quiet $TRAVIS_COMMIT_RANGE -- docs/readme-sync/v3.1 || ( cd $HOME/readme-sync2 && npx ts-node sync/index.ts --apiKey $README_SYNC_API_KEY --version 3.1 --docs $TRAVIS_BUILD_DIR/docs/readme-sync/v3.1 + # sync v4.0 docs folder to readme project v 4.0 + - git diff --quiet $TRAVIS_COMMIT_RANGE -- docs/readme-sync/v4.0 || ( cd $HOME/readme-sync2 && npx ts-node sync/index.ts --apiKey $README_SYNC_API_KEY --version 4.0 --docs $TRAVIS_BUILD_DIR/docs/readme-sync/v4.0 + ######################################################################################### + # directories/scripts for full SDK-reference-guides, to be implemented after agent docs sync + ######################################################################################### + # this commented out code can be used to implement syncing SDK guides in future: https://optimizely.atlassian.net/browse/OASIS-6807 + ## this preps the input directory for readme-sync script + #- mkdir -p $HOME/readme-sync2/docs/readme-sync/sdk-reference-guides + ## ${TRAVIS_REPO_SLUG#optimizely/} translates to go-sdk docs/readme-sync/sdk-reference-guides/go-sdk + #- ln -s $TRAVIS_BUILD_DIR/docs/readme-sync/sdk-reference-guides/${TRAVIS_REPO_SLUG#optimizely/} $HOME/readme-sync2/docs/readme-sync/sdk-reference-guides/${TRAVIS_REPO_SLUG#optimizely/} + + ## now we need to get all the other *-sdk repos too + ## + ## first we list all possible sdks and inside the for loop, remove the one we are updating + #- export ALL_SDK_REPOS="android-sdk csharp-sdk go-sdk java-sdk javascript-sdk objective-c-sdk python-sdk react-sdk ruby-sdk swift-sdk" + #- mkdir $HOME/sdks && pushd $HOME/sdks && for i in ${ALL_SDK_REPOS//${TRAVIS_REPO_SLUG#optimizely/}}; do git clone https://github.com/optimizely/$i; ( [ -d "$HOME/sdks/$i/docs/readme-sync/sdk-reference-guides/$i" ] && ln -s $HOME/sdks/$i/docs/readme-sync/sdk-reference-guides/$i $HOME/readme-sync2/docs/readme-sync/sdk-reference-guides/$i ) || true; done && popd + ## check our work + #- ls -al $HOME/sdks + #- ls -al $HOME/readme-sync2/docs/readme-sync/sdk-reference-guides + #script: + ## we need to be in $TRAVIS_BUILD_DIR in order to run the following git diff properly + #- cd $TRAVIS_BUILD_DIR + #- git diff --quiet $TRAVIS_COMMIT_RANGE -- docs/readme-sync || ( cd $HOME/readme-sync2 && npx ts-node sync/index.ts --apiKey $README_SYNC_API_KEY --version 4.0 --docs docs/readme-sync/ ) + + + +before_script: + # https://github.com/travis-ci/gimme + - eval "$(gimme)" + - make -e setup build