I am trying to get a coverage report in GitHub Actions
but when I run the pipeline I gives me this error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock
Then I search around add added the sudo mysql start service and now I get this error, but I don't know were or have to write mit -root -password and the -host?
Access denied for user 'root'#'localhost' (using password: YES)")
how do I do that?
name: Django CI
on:
push:
branches: [ unittests ]
paths-ignore: '**/SkoleProtocol/attendanceCode/tests/test_selenium.py'
pull_request:
branches: [ unittests ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout#v2
- name: Set up Python 3.7
uses: actions/setup-python#v2
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Create test database
run: |
sudo service mysql start
- name: Coverage report
run: |
pip install coverage
coverage run manage.py test
coverage report
- name: Lint with flake8
run: |
pip install flake8
flake8 ./attendanceCode --exit-zero # Exit with status code "0" even if there are errors.
- name: Django Tests
run: |
python3 manage.py test
Two things that stand out.
Do you happen to have the credentials in an env file else where?
- name: Create test database
run: |
sudo service mysql start
You just happen to start the service rather than creating the database.
Try:
sudo /etc/init.d/mysql start // To start the service
mysql -uroot -proot -e "CREATE DATABASE __dbname__;"
Related
How do I specify whether to zappa deploy or zappa update my application in Github actions with some sort of if statement
My Workflow Actions as per below
name: Dev Deploy
on:
push:
branches:
- mybranch
jobs:
dev-deploy:
name: Deploy to Dev
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Set up Python 3.9.10
uses: actions/setup-python#v1
with:
python-version: 3.9.10
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest
pip install python-Levenshtein
pip install virtualenv
- name: Install zappa
run: pip install zappa
- name: Install Serverless
run: npm install -g serverless
- name: Configure Serverless for zappa Services
run: serverless config credentials --provider aws --key myAWSKey --secret myAWSSecret
- name: Deploy to Dev
run: |
python -m virtualenv envsp
source envsp/bin/activate
zappa deploy dev
If application already deployed once, I get the error
Error: This application is already deployed - did you mean to call update?
In which case I would want to run zappa update dev
On Github Action workflow main.yml, I did the following to add to PYTHONPATH
PWD=$(pwd)
export PYTHONPATH=$PWD/src:$PWD/tests:$PYTHONPATH
I verified the PYTHONPATH using the following command
echo "PYTHONPATH=$PYTHONPATH"
and the output is PYTHONPATH=/home/runner/work/my_api/my_api/src:/home/runner/work/my_api/my_api/tests
I have a module called my_api live under /home/runner/work/my_api/my_api/src
But now I'm getting ModuleNotFoundError: No module named 'my_api' It seems export PYTHONPATH has no impact on the system. Below is the complete workfile YML file.
name: Integration Test Run
env:
HISTORIC_DATA_FOLDER: /usr/my_api_historic_data
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install Python 3
uses: actions/setup-python#v1
with:
python-version: 3.6
- name: Filessytem Setup
run: |
pwd
mkdir my_api_historic_data_test
- name: Docker Compose
run: |
sudo docker-compose -f docker-compose-github.yml build
sudo docker-compose -f docker-compose-github.yml --verbose --env-file .env up &
- name: Intgration Test Setup
run: |
echo "-----pwd-----"
pwd
echo "-----ls-----"
ls
echo "-----ls src/-----"
ls src/
echo "----PYTHONPATH------"
PWD=$(pwd)
export PYTHONPATH=$PWD/src:$PWD/tests:$PYTHONPATH
echo "PYTHONPATH=$PYTHONPATH"
echo "-----HISTORIC PATH----"
export HISTORIC_DATA_FOLDER=/home/runner/work/my_api/my_api/my_api_historic_data_test
echo "HISTORIC_DATA_FOLDER=$HISTORIC_DATA_FOLDER"
- name: Integreation Test Run
run: |
sleep 30
pip install requests
sudo python -m unittest discover
As already said in comments, each step runs in it's own shell. You need to make sure your variable is exported properly, so that it's available in all subsequent steps.
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
See docs for more details.
When I was trying to run the git action to build a docker image, got the following error. Any insight into what went wrong? Thanks!
Here is the workflow yaml:
name: Python application
on:
push:
paths:
- 'python/*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Set up Python 3.7
uses: actions/setup-python#v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./python/requirements.txt
- name: Build & Push Image
run: |
cd ./python
echo "${{ secrets.DOCKERPW }}" | docker login -u "[your dockerhub login here]" --password-stdin
docker image build -t [your dockerhub username here]/gitops:hellov1.0 .
docker push [your docker hub username here]/gitops:hellov1.0
the error message in the log:
Run cd ./python
cd ./python
echo *** | docker login -u xsqian --password-stdin
docker image build -t xsqian/gitops:hellov1.0 .
docker push xsqian/gitops:hellov1.0
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.7.11/x64
/home/runner/work/_temp/30d82465-db58-4fc4-8139-ed8d8f5762d6.sh: line 2: unexpected EOF while looking for matching `"'
Error: Process completed with exit code 2.
I have a CodeIgniter Web app connected with Mysql that is developed in the docker. I would like to do some unit test in the GitHub action fo ci/cd pipeline. The problem is some of the function would require enquiry data from Mysql database. So may I know if there is a way to setup a MySQL instance on Github action and run some .sql file so that my test data is in the database?
You can use GitHub Actions service containers to connect to databases like mysql. You can find details at https://docs.github.com/en/actions/guides/about-service-containers
I think this script can help people to conduct unit test with MySQL database and a .sql script file to load table schema and data on Github action. I am using Codeigniter 4 with Mysql. But the process of setting up a database would be similar as long as you are using MySQL.
name: CI Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Build the Docker image
run: docker-compose build
- name: up mysql and apache container runs
run: docker-compose up -d
#I am using codeIgniter4
- name: install dependencies
run: docker exec CI4_1 php composer.phar install
- name: buffering time for db container
uses: jakejarvis/wait-action#master
with:
time: '30s'
#db_1 is the name of database
- name: load database
run: docker exec -i mysql_1 mysql -uroot -proot db_1< ./testDatabase.sql
- name: unit test
run: docker exec CI4_1 ./vendor/bin/phpunit
I have the following yaml file. It were working just fine until yesterday. Unfortunately starting from today received the below warning and followed by the following error.
Hope someone will be able to point me to solution to fixed this issue. Below is the yaml code
name: CI_dev
on:
pull_request:
branches: [ dev ]
jobs:
test_pipeline:
runs-on: ubuntu-latest
steps:
# Install Salesforce CLI
- name: Install Salesforce CLI
run: |
wget https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
mkdir sfdx-cli
tar xJf sfdx-linux-amd64.tar.xz -C sfdx-cli --strip-components 1
./sfdx-cli/install
#Checkout master
- name: 'checkout master'
uses: actions/checkout#master
#read secret, authenticate and deploy
- name: 'Populate auth file with SFDX_URL secret'
shell: bash
run: 'echo ${{ secrets.secret}} > ./secret.txt'
- name: 'Authenticate'
run: 'sfdx force:auth:sfdxurl:store --sfdxurlfile=./secret.txt -a secretAlias'
- name: 'Deploy'
run: "sfdx force:source:deploy --sourcepath ./force-app/main/default -l RunLocalTests -u secretAlias"
Below is the warning that appear on the authenticate step
Warning: force:auth:sfdxurl:store is not a sfdx command.
Did you mean auth:sfdxurl:store? [y/n]:
And below is the error that appear on the Deploy step
ERROR running force:source:deploy: No org configuration found for name secretAlias
Error: Process completed with exit code 1.
sfdx (at least linux distributions) have recently updated from 7.82.1 to 7.83.1 (January 2021)
since 7.83.1 it follows different syntax format.
You need to remove force: from your 'Authenticate' command line as it is advised in error message.
You can look your current version with:
sfdx --version
Busy Box was right. just need to remove force from force:auth and its alread working again. below is the updated yaml file as reference.
name: CI_dev
on:
pull_request:
branches: [ dev ]
jobs:
test_pipeline:
runs-on: ubuntu-latest
steps:
# Install Salesforce CLI
- name: Install Salesforce CLI
run: |
wget https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
mkdir sfdx-cli
tar xJf sfdx-linux-amd64.tar.xz -C sfdx-cli --strip-components 1
./sfdx-cli/install
#Checkout master
- name: 'checkout master'
uses: actions/checkout#master
#read secret, authenticate and deploy
- name: 'Populate auth file with SFDX_URL secret'
shell: bash
run: 'echo ${{ secrets.secret}} > ./secret.txt'
- name: 'Authenticate'
run: 'sfdx auth:sfdxurl:store --sfdxurlfile=./secret.txt -a secretAlias'
- name: 'Deploy'
run: "sfdx force:source:deploy --sourcepath ./force-app/main/default -l RunLocalTests -u secretAlias"