|
| 1 | +name: Stellar Price API CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + test: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v3 |
| 15 | + |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v4 |
| 18 | + with: |
| 19 | + python-version: '3.10' |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + python -m pip install --upgrade pip |
| 24 | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 25 | + pip install pytest pytest-cov flake8 |
| 26 | + |
| 27 | + - name: Lint with flake8 |
| 28 | + run: | |
| 29 | + # stop the build if there are Python syntax errors or undefined names |
| 30 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 31 | + # exit-zero treats all errors as warnings |
| 32 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 33 | +
|
| 34 | + docker: |
| 35 | + needs: test |
| 36 | + runs-on: ubuntu-latest |
| 37 | + if: github.event_name != 'pull_request' |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v3 |
| 40 | + |
| 41 | + - name: Set up Docker Buildx |
| 42 | + uses: docker/setup-buildx-action@v2 |
| 43 | + |
| 44 | + - name: Build and export |
| 45 | + uses: docker/build-push-action@v4 |
| 46 | + with: |
| 47 | + context: . |
| 48 | + file: ./Dockerfile |
| 49 | + load: true |
| 50 | + tags: stellar-price-api:latest |
| 51 | + |
| 52 | + - name: Test image |
| 53 | + run: docker run --rm stellar-price-api:latest python -c "import flask; import stellar_sdk; print('Dependencies loaded successfully')" |
| 54 | + |
| 55 | + deploy: |
| 56 | + needs: docker |
| 57 | + runs-on: ubuntu-latest |
| 58 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' |
| 59 | + steps: |
| 60 | + - name: Deploy to server |
| 61 | + run: echo "Add your deployment steps here" |
| 62 | + # Example deployment steps: |
| 63 | + # - Install SSH key |
| 64 | + # - Connect to server |
| 65 | + # - Pull latest code |
| 66 | + # - Restart service |
0 commit comments