diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6d87e8379e..8445e06fdc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -144,6 +144,160 @@ jobs: run: | ./scripts/ci/run-nightly-make-task-if-exists.sh "${TASK}" + self-check: + needs: pre_job + name: '${{ matrix.name }} - Python ${{ matrix.python-version-short }}' + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + include: + # TODO: Check if we want to fix the errors on Py 3.6 to have it tested as well + #- name: 'Self-check on Python 3.6' + # python-version-short: '3.6' + # python-version: '3.6.13' + - name: 'Self-check on Python 3.8' + python-version-short: '3.8' + python-version: '3.8.14' + services: + mongo: + image: mongo:4.4 + ports: + - 27017:27017 + + rabbitmq: + image: rabbitmq:3.8-management + options: >- + --name rabbitmq + ports: + - 5671:5671/tcp # AMQP SSL port + - 5672:5672/tcp # AMQP standard port + - 15672:15672/tcp # Management: HTTP, CLI + + env: + # CI st2.conf (with ST2_CI_USER user instead of stanley) + ST2_CONF: 'conf/st2.ci.conf' + + # Name of the user who is running the CI (on GitHub Actions this is 'runner') + ST2_CI_USER: 'runner' + + # GitHub is juggling how to set vars for multiple shells. Protect our PATH assumptions. + PATH: /home/runner/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + + # Space separated list of tests to be skipped if the self-check is running in GitHub Actions + TESTS_TO_SKIP: "tests.test_quickstart_rules tests.test_run_pack_tests_tool" + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Custom Environment Setup + run: | + ./scripts/github/setup-environment.sh + - name: 'Set up Python (${{ matrix.python-version }})' + uses: actions/setup-python@v2 + with: + python-version: '${{ matrix.python-version }}' + - name: Cache Python Dependencies + uses: actions/cache@v2 + with: + path: | + ~/.cache/pip + virtualenv + ~/virtualenv + # TODO: maybe make the virtualenv a partial cache to exclude st2*? + # !virtualenv/lib/python*/site-packages/st2* + # !virtualenv/bin/st2* + key: ${{ runner.os }}-v3-python-${{ matrix.python-version }}-${{ hashFiles('requirements.txt', 'test-requirements.txt') }} + restore-keys: | + ${{ runner.os }}-python-${{ matrix.python }}- + - name: Cache APT Dependencies + id: cache-apt-deps + uses: actions/cache@v2 + with: + path: | + ~/apt_cache + key: ${{ runner.os }}-apt-v5-${{ hashFiles('scripts/github/apt-packages.txt') }} + restore-keys: | + ${{ runner.os }}-apt-v5- + - name: Install APT Depedencies + env: + CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}} + run: | + cat /etc/environment + # install dev dependencies for Python YAML and LDAP packages + # https://github.com/StackStorm/st2-auth-ldap + ./scripts/github/install-apt-packages-use-cache.sh + - name: Install virtualenv + run: | + ./scripts/github/install-virtualenv.sh + - name: Install requirements + run: | + ./scripts/ci/install-requirements.sh + - name: Run Redis Service Container + timeout-minutes: 2 + run: | + docker run --rm --detach -p 127.0.0.1:6379:6379/tcp --name redis redis:latest + until [ "$(docker inspect -f {{.State.Running}} redis)" == "true" ]; do sleep 0.1; done + - name: Setup Tests + run: | + # prep a ci-specific dev conf file that uses runner instead of stanley + # this user is the username of the user in GitHub actions, used for SSH, etc during + # integration tests (important) + cp conf/st2.dev.conf "${ST2_CONF}" + sed -i -e "s,/home/vagrant/.ssh/stanley_rsa,/home/stanley/.ssh/stanley_rsa," "${ST2_CONF}" + + sudo -E ./scripts/ci/add-itest-user-key.sh + - name: Permissions Workaround + run: | + sudo ST2_CI_REPO_PATH="${ST2_CI_REPO_PATH}" scripts/ci/permissions-workaround.sh + - name: Reconfigure RabbitMQ + # bitnami image allows (see bitnami/rabbitmq readme): + # Here we're copying a rabbitmq.config file which won't do anything. + # We need to switch to custom.conf or advanced.config. + timeout-minutes: 2 # may die if rabbitmq fails to start + run: | + ./scripts/github/configure-rabbitmq.sh + - name: Print versions + run: | + ./scripts/ci/print-versions.sh + - name: make + timeout-minutes: 14 # may die if rabbitmq fails to start + # use: script -e -c to print colors + run: | + script -e -c "make .ci-prepare-integration" && exit 0 + - name: Extend the path for upcoming tasks + run: | + echo ${HOME}/work/st2/st2/virtualenv/bin + echo ${HOME}/work/st2/st2/virtualenv/bin >> $GITHUB_PATH + - name: Create symlinks to find the binaries when running st2 actions + run: | + ln -s ${HOME}/work/st2/st2/virtualenv/bin/st2 /usr/local/bin/st2 + ln -s ${HOME}/work/st2/st2/virtualenv/bin/st2-run-pack-tests /usr/local/bin/st2-run-pack-tests + - name: Install st2client + timeout-minutes: 5 + run: | + cd ./st2client + pip3 install --upgrade pip + python3 setup.py develop + - name: Run self-verification script + env: + ST2_CONF: /home/runner/work/st2/st2/conf/st2.ci.conf + run: | + sudo -E ST2_AUTH_TOKEN=$(st2 auth testu -p 'testp' -t) PATH=${PATH} virtualenv/bin/st2-self-check + - name: Compress Service Logs Before upload + if: ${{ failure() }} + run: | + tar cvzpf logs.tar.gz logs/* + - name: Upload StackStorm services Logs + if: ${{ failure() }} + uses: actions/upload-artifact@v2 + with: + name: logs + path: logs.tar.gz + retention-days: 7 + - name: Stop Redis Service Container + if: "${{ always() }}" + run: docker rm --force redis || true + unit-tests: needs: pre_job # NOTE: We always want to run job on master since we run some additional checks there (code diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a267a04fed..e3d6e797e7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -43,6 +43,10 @@ Added * Python 3.9 support. #5730 Contributed by Amanda McGuinness (@amanda11 intive) +* Run the st2 self-check in Github Actions and support the environment variable `TESTS_TO_SKIP` to skip tests when running st2-self-check. #5609 + + Contributed by @winem + Changed ~~~~~~~ * Remove `distutils` dependencies across the project. #5992 diff --git a/st2common/bin/st2-self-check b/st2common/bin/st2-self-check index d7d1a0b85a..1240b13fc7 100755 --- a/st2common/bin/st2-self-check +++ b/st2common/bin/st2-self-check @@ -29,6 +29,7 @@ function usage() { RUN_ORQUESTA_TESTS=true RUN_WINDOWS_TESTS=false ST2_TESTS_BRANCH="master" +TESTS_TO_SKIP="${TESTS_TO_SKIP:-}" while getopts "b:wo" o do @@ -101,10 +102,15 @@ if [ ${EXIT_CODE} -ne 0 ]; then fi echo "Copying asserts, fixtures, tests and examples packs." -chown -R root:st2packs st2tests/packs/ -chmod -R 775 st2tests/packs/* +if [ -n "${GITHUB_ACTIONS}" ]; then + cp -Rf --preserve /home/runner/work/st2/st2/contrib/examples /opt/stackstorm/packs/ +else + chmod -R 775 st2tests/packs/* + cp -Rf --preserve /usr/share/doc/st2/examples /opt/stackstorm/packs/ + chown -R root:st2packs st2tests/packs/ +fi + cp -R --preserve st2tests/packs/* /opt/stackstorm/packs/ -cp -Rf --preserve /usr/share/doc/st2/examples /opt/stackstorm/packs/ echo "Installing asserts, fixtures, tests and examples packs." st2 run packs.setup_virtualenv packs=examples,tests,asserts,fixtures,webui @@ -136,6 +142,11 @@ do continue fi + if [[ " ${TESTS_TO_SKIP} " =~ " ${TEST} " ]]; then + echo "Skipping ${TEST}..." + continue + fi + echo -n "Attempting Test ${TEST}..." START_TS=$(date +%s) @@ -179,6 +190,9 @@ if [ $ERRORS -ne 0 ]; then echo "SELF CHECK FAILED!" echo "st2-self-check failed. See above. Also check the execution list for details." echo "st2 execution list" + if [ -n "${GITHUB_ACTIONS}" ]; then + exit 1 + fi else echo "SELF CHECK SUCCEEDED!" echo -e "st2-self-check succeeded." diff --git a/st2common/bin/st2ctl b/st2common/bin/st2ctl index 26b404e0eb..a26f7bfb09 100755 --- a/st2common/bin/st2ctl +++ b/st2common/bin/st2ctl @@ -15,12 +15,12 @@ # limitations under the License. COMPONENTS="st2actionrunner st2api st2stream st2auth st2garbagecollector st2notifier st2rulesengine st2sensorcontainer st2chatops st2timersengine st2workflowengine st2scheduler" -ST2_CONF="/etc/st2/st2.conf" +ST2_CONF="${ST2_CONF:-/etc/st2/st2.conf}" SYSTEMD_RELOADED="" -# Ensure global environment is sourced if exists +# Ensure global environment is sourced if exists and if not executed in the context of Github Actions # Does not happen consistently with all OSes we support. -[ -r /etc/environment ] && source /etc/environment +[ -z "${GITHUB_ACTIONS}" ] && [ -r /etc/environment ] && source /etc/environment # load in environment to allow override of COMPONENTS and ST2_CONF above # Ubuntu/Debian