|
| 1 | +name: DevOps-OS CI/CD |
| 2 | +'on': |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + environment: |
| 12 | + description: Environment to deploy to |
| 13 | + required: true |
| 14 | + default: dev |
| 15 | + type: choice |
| 16 | + options: |
| 17 | + - dev |
| 18 | + - test |
| 19 | + - staging |
| 20 | + - prod |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + container: |
| 25 | + image: ghcr.io/yourorg/devops-os:latest |
| 26 | + options: --user root |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v3 |
| 30 | + - name: Set up build environment |
| 31 | + run: echo 'Setting up build environment for DevOps-OS' |
| 32 | + - name: Install Python dependencies |
| 33 | + run: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 34 | + - name: Build Python package |
| 35 | + run: if [ -f setup.py ]; then pip install -e .; elif [ -f pyproject.toml ]; |
| 36 | + then pip install -e .; fi |
| 37 | + - name: Install Node.js dependencies |
| 38 | + run: if [ -f package.json ]; then npm ci; fi |
| 39 | + - name: Build JavaScript/TypeScript |
| 40 | + run: if [ -f package.json ]; then npm run build --if-present; fi |
| 41 | + - name: Upload build artifacts |
| 42 | + uses: actions/upload-artifact@v3 |
| 43 | + with: |
| 44 | + name: build-artifacts |
| 45 | + path: dist/ |
| 46 | + retention-days: 1 |
| 47 | + test: |
| 48 | + needs: |
| 49 | + - build |
| 50 | + runs-on: ubuntu-latest |
| 51 | + container: |
| 52 | + image: ghcr.io/yourorg/devops-os:latest |
| 53 | + options: --user root |
| 54 | + steps: |
| 55 | + - name: Checkout code |
| 56 | + uses: actions/checkout@v3 |
| 57 | + - name: Set up test environment |
| 58 | + run: echo 'Setting up test environment for DevOps-OS' |
| 59 | + - name: Install Python dependencies |
| 60 | + run: if [ -f requirements.txt ]; then pip install -r requirements.txt pytest |
| 61 | + pytest-cov; fi |
| 62 | + - name: Run Python tests |
| 63 | + run: if [ -d tests ]; then python -m pytest --cov=./ --cov-report=xml; fi |
| 64 | + - name: Run Pylint |
| 65 | + run: if command -v pylint &> /dev/null; then pylint --disable=C0111 **/*.py; |
| 66 | + fi |
| 67 | + - name: Install Node.js dependencies |
| 68 | + run: if [ -f package.json ]; then npm ci; fi |
| 69 | + - name: Run JavaScript tests |
| 70 | + run: if [ -f package.json ]; then npm test; fi |
| 71 | + - name: Run ESLint |
| 72 | + run: if [ -f package.json ] && grep -q eslint package.json; then npm run lint; |
| 73 | + fi |
| 74 | + - name: Upload test results |
| 75 | + uses: actions/upload-artifact@v3 |
| 76 | + with: |
| 77 | + name: test-results |
| 78 | + path: test-reports/ |
| 79 | + retention-days: 1 |
| 80 | + - name: Upload coverage reports |
| 81 | + uses: codecov/codecov-action@v3 |
| 82 | + with: |
| 83 | + files: ./coverage.xml,./coverage/lcov.info |
| 84 | + fail_ci_if_error: false |
| 85 | + deploy: |
| 86 | + needs: |
| 87 | + - test |
| 88 | + if: github.ref == 'refs/heads/main' |
| 89 | + runs-on: ubuntu-latest |
| 90 | + container: |
| 91 | + image: ghcr.io/yourorg/devops-os:latest |
| 92 | + options: --user root |
| 93 | + steps: |
| 94 | + - name: Checkout code |
| 95 | + uses: actions/checkout@v3 |
| 96 | + - name: Set up deployment environment |
| 97 | + run: echo 'Setting up deployment environment for DevOps-OS' |
| 98 | + - name: Build and Push Docker Image |
| 99 | + if: github.ref == 'refs/heads/main' |
| 100 | + run: 'echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ghcr.io -u ${{ github.actor |
| 101 | + }} --password-stdin |
| 102 | +
|
| 103 | + docker build -t ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name |
| 104 | + }}:latest . |
| 105 | +
|
| 106 | + docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name |
| 107 | + }}:latest' |
0 commit comments