From 45b03bbcb08a185eaacc8064efbd48aad5a086fc Mon Sep 17 00:00:00 2001 From: Klemen Tusar Date: Sun, 30 Jul 2023 20:07:12 +0100 Subject: [PATCH] :construction_worker: update CI (#56) --- .github/workflows/codeql-analysis.yml | 4 -- .github/workflows/publish.yml | 5 +- .github/workflows/test.yml | 90 ++++++++++++++++----------- ci/db_credentials.json | 7 --- 4 files changed, 56 insertions(+), 50 deletions(-) delete mode 100644 ci/db_credentials.json diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ad1745e..ccc21fa 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,20 +13,16 @@ jobs: analyze: name: Analyze runs-on: ubuntu-latest - strategy: fail-fast: false matrix: language: [ 'python' ] - steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} - - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9e2090d..df1c69b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -37,11 +37,14 @@ jobs: - name: Install build dependencies id: install_build_dependencies run: | + set -e python3 -m pip install --upgrade pip pip install build setuptools wheel - name: Build a binary wheel and a source tarball id: build - run: python3 -m build --sdist --wheel --outdir dist/ . + run: | + set -e + python3 -m build --sdist --wheel --outdir dist/ . - name: Publish distribution package to Test PyPI id: publish_test uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 86ddcce..0f8816e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: "3.x" - name: Install dependencies @@ -30,6 +30,7 @@ jobs: test: needs: analyze runs-on: ubuntu-latest + environment: test strategy: matrix: include: @@ -422,9 +423,7 @@ jobs: legacy_db: 0 experimental: false py: "3.11" - continue-on-error: ${{ matrix.experimental }} - services: mysql: image: "${{ matrix.db }}" @@ -433,73 +432,88 @@ jobs: env: MYSQL_ALLOW_EMPTY_PASSWORD: yes options: "--name=mysqld" - steps: - - name: Fix MySQL GA - run: | - sudo apt-get update - sudo apt-get remove mysql* && sudo apt-get install -y mysql-server libmysqlclient-dev - - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.py }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.py }} - - uses: actions/cache@v3 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-1 restore-keys: | ${{ runner.os }}-pip- - - name: Install dependencies run: | + set -e python -m pip install --upgrade pip python -m pip install -U codecov tox-gh-actions pip install -r requirements_dev.txt - - name: Set up MySQL env: DB: ${{ matrix.db }} + MYSQL_USER: ${{ secrets.MYSQL_USER }} + MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} + MYSQL_DATABASE: ${{ vars.MYSQL_DATABASE }} + MYSQL_HOST: ${{ vars.MYSQL_HOST }} + MYSQL_PORT: ${{ vars.MYSQL_PORT }} run: | + set -e while : do - sleep 1 - mysql -h127.0.0.1 -uroot -e 'select version()' && break + sleep 1 + mysql -h127.0.0.1 -uroot -e 'select version()' && break done - if [ $DB == 'mysql:8.0' ]; then - WITH_PLUGIN='with mysql_native_password' - mysql -h127.0.0.1 -uroot -e "SET GLOBAL local_infile=on" - docker cp mysqld:/var/lib/mysql/public_key.pem "${HOME}" - docker cp mysqld:/var/lib/mysql/ca.pem "${HOME}" - docker cp mysqld:/var/lib/mysql/server-cert.pem "${HOME}" - docker cp mysqld:/var/lib/mysql/client-key.pem "${HOME}" - docker cp mysqld:/var/lib/mysql/client-cert.pem "${HOME}" - mysql -uroot -h127.0.0.1 -e ' - CREATE USER - user_sha256 IDENTIFIED WITH "sha256_password" BY "pass_sha256", - nopass_sha256 IDENTIFIED WITH "sha256_password", - user_caching_sha2 IDENTIFIED WITH "caching_sha2_password" BY "pass_caching_sha2", - nopass_caching_sha2 IDENTIFIED WITH "caching_sha2_password" - PASSWORD EXPIRE NEVER;' - mysql -uroot -h127.0.0.1 -e 'GRANT RELOAD ON *.* TO user_caching_sha2;' + if [ "$DB" == 'mysql:8.0' ]; then + WITH_PLUGIN='with mysql_native_password' + mysql -h127.0.0.1 -uroot -e "SET GLOBAL local_infile=on" + docker cp mysqld:/var/lib/mysql/public_key.pem "${HOME}" + docker cp mysqld:/var/lib/mysql/ca.pem "${HOME}" + docker cp mysqld:/var/lib/mysql/server-cert.pem "${HOME}" + docker cp mysqld:/var/lib/mysql/client-key.pem "${HOME}" + docker cp mysqld:/var/lib/mysql/client-cert.pem "${HOME}" + mysql -uroot -h127.0.0.1 -e ' + CREATE USER + user_sha256 IDENTIFIED WITH "sha256_password" BY "pass_sha256", + nopass_sha256 IDENTIFIED WITH "sha256_password", + user_caching_sha2 IDENTIFIED WITH "caching_sha2_password" BY "pass_caching_sha2", + nopass_caching_sha2 IDENTIFIED WITH "caching_sha2_password" + PASSWORD EXPIRE NEVER;' + mysql -uroot -h127.0.0.1 -e 'GRANT RELOAD ON *.* TO user_caching_sha2;' else - WITH_PLUGIN='' + WITH_PLUGIN='' fi - mysql -h127.0.0.1 -uroot -e 'create database test_db DEFAULT CHARACTER SET utf8mb4' - mysql -h127.0.0.1 -uroot -e "create user tester identified ${WITH_PLUGIN} by 'testpass'; grant all on test_db.* to tester;" - mysql -h127.0.0.1 -uroot -e "create user tester@localhost identified ${WITH_PLUGIN} by 'testpass'; grant all on test_db.* to tester@localhost;" - cp ci/db_credentials.json tests/db_credentials.json - + mysql -h127.0.0.1 -uroot -e "create database $MYSQL_DATABASE DEFAULT CHARACTER SET utf8mb4" + mysql -h127.0.0.1 -uroot -e "create user $MYSQL_USER identified $WITH_PLUGIN by '${MYSQL_PASSWORD}'; grant all on ${MYSQL_DATABASE}.* to ${MYSQL_USER};" + mysql -h127.0.0.1 -uroot -e "create user ${MYSQL_USER}@localhost identified $WITH_PLUGIN by '${MYSQL_PASSWORD}'; grant all on ${MYSQL_DATABASE}.* to ${MYSQL_USER}@localhost;" + - name: Create db_credentials.json + env: + MYSQL_USER: ${{ secrets.MYSQL_USER }} + MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} + MYSQL_DATABASE: ${{ vars.MYSQL_DATABASE }} + MYSQL_HOST: ${{ vars.MYSQL_HOST }} + MYSQL_PORT: ${{ vars.MYSQL_PORT }} + run: | + set -e + jq -n \ + --arg mysql_user "$MYSQL_USER" \ + --arg mysql_password "$MYSQL_PASSWORD" \ + --arg mysql_database "$MYSQL_DATABASE" \ + --arg mysql_host "$MYSQL_HOST" \ + --arg mysql_port $MYSQL_PORT \ + '$ARGS.named' > tests/db_credentials.json - name: Test with tox - run: tox env: LEGACY_DB: ${{ matrix.legacy_db }} - + run: tox - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: files: ./coverage.xml env_vars: OS,PYTHON verbose: true + - name: Cleanup + if: ${{ always() }} + run: | + rm -rf tests/db_credentials.json diff --git a/ci/db_credentials.json b/ci/db_credentials.json deleted file mode 100644 index d259209..0000000 --- a/ci/db_credentials.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "mysql_user": "tester", - "mysql_password": "testpass", - "mysql_database": "test_db", - "mysql_host": "0.0.0.0", - "mysql_port": 3306 -}