Why my github action's cron is not working? - cron

I have written a github actions workflow yml file to schedule a job to run everyday at a particular time but it's not working. I have even used the cron written in official doc but still it is not working. Is it due to Indian TimeZone or some other reason??
name: run app.py
on:
schedule:
- cron: '30 4,17 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v3
- name: setup python
uses: actions/setup-python#v4
with:
python-version: '3.9' # install the python version needed
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: execute py script # run main.py
env:
DSA_SHEET: ${{ secrets.DSA_SHEET }}
run: python app.py
I have tried to change the cron many time but it was not working. It was only working when set to run every 5mins but when I set it to run everyday it is not working.

Github actions schedule is in UTC time.
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule

Related

Cron scheduling not working for Github Action yml file

I have the following yml that I have updated from a manual run:
name: run scrapper.py
# Controls when the workflow will run
on: [workflow_dispatch]
to the below (including cron schedule):
name: run scrapper.py
on:
schedule:
- cron: "40 16 * * *"
jobs:
build:
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout#v3
- uses: actions/setup-python#v4
with:
python-version: '3.10'
- name: Install dependencies
run: pip install -r requirements.txt || pip install --editable . || pip install .
- run: pip install safety
- run: safety check
- name: execute py script
run: python scrapper.py
env:
DB: ${{ secrets.DB }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASS: ${{ secrets.DB_PASS }}
It is looking (to me) as it should according to docs, but it's not triggering the python script. Any ideas?

Gitlab CI empty script

I'm trying to setup a simple CI/CD environment on gitlab. My code is a python app that needs an external service for testing. The service is a container that does not require any script to be run. My gitlab-ci.yml file is:
stages:
- dynamodb
- testing
build_dynamo:
stage: dynamodb
image: amazon/dynamodb-local:latest
unit_tests:
stage: testing
image: python:3.10.3
before_script:
- pip install -r requirements_tests.txt
- export PYTHONPATH="${PYTHONPATH}:./src"
script:
- python -m unittest discover -s ./tests -p '*test*.py'
For this config I get an error
Found errors in your .gitlab-ci.yml: jobs build_dynamo config should
implement a script: or a trigger: keyword
Hiow can I solve this or implement the setup I need?
Using service solved this
unit_tests:
image: python:3.10.3-slim-buster
services:
- name: amazon/dynamodb-local:latest
before_script:
- pip install -r requirements_tests.txt
- export PYTHONPATH="${PYTHONPATH}:./src"
script:
- python -m unittest discover -s ./tests -p '*test*.py'
endpoint for the service is amazon-dynamo-local:8000 since "/" are changed to "-".
Reference: https://docs.gitlab.com/ee/ci/services/#accessing-the-services

Github on-schedule action workflow executes in delay or not at all

I have 2 workflows inside my repository - one that is a CI that runs on each push and one that is supposed to execute a script on a scheduled time.
The scheduled workflow looks like that:
name: scheduled-run
on:
schedule:
# UTC time
- cron: "45 14 1,15,30 * *"
jobs:
build:
runs-on: ubuntu-latest
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
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Execute python script
env:
TELEGRAM_API_TOKEN: ${{ secrets.TELEGRAM_API_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
AWS_KEY_ID: ${{ secrets.AWS_KEY_ID }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
run: |
python cci.py -r
No matter how and to when I set the cron schedule - the workflow does not start! Sometimes it would start way after the supposed time but mostly it does not start. I have tried to recreate the workflow from scratch but it doesn't seem to help. What's going on here?
I tested your workflow with slightly changed cron
name: scheduled-run
on:
schedule:
# UTC time
- cron: "55 13,14,15 1,4,15,30 * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Python 3.7
uses: actions/setup-python#v2
with:
python-version: 3.7
And it works as expected:
Please try with sth smaller (like above) and with slightly different cron so you would not wait long to verify your changes.

How to define a test run in github-actions in a specific branch for a python script?

What I have so far is this code:
name: test run
on:
push:
branches:
- V2.0
jobs:
build:
runs-on: [windows-2019]
steps:
- uses: actions/checkout#v2
- name: Set up Python 3.8
uses: actions/setup-python#v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyautogui
pip install opencv-python
pip install numpy
pip install pynput
- name: Test
run: python Cristishor201/my_repo#V2.0/src/pytest.py
And I want to run pytest.py script which is inside my_repo repository, branch V2.0, and in folder src.
Does anyone have an idea how to do this ?
UPDATE 1:
I found this article when he put github.ref environment variable using if statement. The problem with this solution is that it skip the code, and I already filtered the branch in the trigger block.
name: my workflow
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Execute tests
run: exit 0
deploy:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/master'
steps:
- name: Deploy app
run: exit 0
I tried using env: instead if: but it didn't work.
Github action actions/checkout#v2 pulls the current branch for which this pipeline was triggered. Since you are specifically telling the pipeline to trigger on V2.0 then you don't need to specify a specific branch to checkout.
Now you are in the current working directory so you can just do the following to properly find your file in the path.
python .\src\pytest.py
Note: this assumes your repo directory structure contains src at the root level of your repo
src
└── pytest.py

Is it possible to use multiple docker images in bitbucket pipeline?

I have this pipeline file to unittest my project:
image: jameslin/python-test
pipelines:
default:
- step:
script:
- service mysql start
- pip install -r requirements/test.txt
- export DJANGO_CONFIGURATION=Test
- python manage.py test
but is it possible to switch to another docker image to deploy?
image: jameslin/python-deploy
pipelines:
default:
- step:
script:
- ansible-playbook deploy
I cannot seem to find any documentation saying either Yes or No.
You can specify an image for each step. Like that:
pipelines:
default:
- step:
name: Build and test
image: node:8.6
script:
- npm install
- npm test
- npm run build
artifacts:
- dist/**
- step:
name: Deploy
image: python:3.5.1
trigger: manual
script:
- python deploy.py
Finally found it:
https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html#Configurebitbucket-pipelines.yml-ci_stepstep(required)
step (required) Defines a build execution unit. Steps are executed in
the order in which they appear in the pipeline. Currently, each
pipeline can have only one step (one for the default pipeline and one
for each branch). You can override the main Docker image by specifying
an image in a step.
I have not found any information saying yes or no either so what I have assumed is that since this image can be configured with all the languages and technology you need I would suggest this method:
Create your docker image with all utilities you need for both default and deployment.
Use the branching method they show in their examples https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html#Configurebitbucket-pipelines.yml-ci_branchesbranches(optional)
Use shell scripts or other scripts to run specific tasks you need and
image: yourusername/your-image
pipelines:
branches:
master:
- step:
script: # Modify the commands below to build your repository.
- echo "Starting pipelines for master"
- chmod +x your-task-configs.sh #necessary to get shell script to run in BB Pipelines
- ./your-task-configs.sh
feature/*:
- step:
script: # Modify the commands below to build your repository.
- echo "Starting pipelines for feature/*"
- npm install
- npm install -g grunt-cli
- npm install grunt --save-dev
- grunt build

Resources