diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c900510 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,39 @@ +name: CI-CD Pipeline + +on: + push: + branches: [ "main", "feature/*" ] + pull_request: + branches: [ "main" ] + +jobs: + test-and-deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # --- STEP 1: UNIT TESTING --- + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install dependencies + run: pip install pytest + + - name: Run Pytest + run: pytest + + # --- STEP 2: DOCKER HUB DEPLOY (Only on Main Branch) --- + - name: Login to Docker Hub + if: github.ref == 'refs/heads/main' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and Push + if: github.ref == 'refs/heads/main' + run: | + docker build -t skalgleb2devops/testing:latest . + docker push skalgleb2devops/testing:latest diff --git a/app.py b/app.py index c398fc5..f68dcdf 100644 --- a/app.py +++ b/app.py @@ -4,3 +4,4 @@ def welcome_message(): def calculate_uptime(days): return days * 24 # Converts days to hours +print('Version 2.0')