diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml deleted file mode 100644 index 40493c8..0000000 --- a/.github/workflows/build-and-push.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: build-and-push - -on: - workflow_run: - workflows: ["tests-and-merge"] - types: [completed] - push: - branches: [main] - -permissions: - contents: read - packages: write - -jobs: - build: - if: ${{ github.event_name == 'push' || github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'neutral' }} - runs-on: ubuntu-latest - - steps: - - name: Checkout tested commit - uses: actions/checkout@v4 - with: - ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }} - fetch-depth: 0 - - - name: Log in to GHCR - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Owner in lowercase - id: vars - run: | - OWNER_LC=$(echo "${GITHUB_REPOSITORY%/*}" | tr '[:upper:]' '[:lower:]') - echo "owner=${OWNER_LC}" >> "$GITHUB_OUTPUT" - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ghcr.io/${{ steps.vars.outputs.owner }}/science-helper:latest diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..2c2f403 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,59 @@ +name: CI Pipeline + +on: + push: + branches: [ '**' ] # На все пуши (включая main) + pull_request: + branches: [ main ] # На PR в main + +permissions: + contents: read + packages: write # нужно для Docker push в GHCR + +jobs: + test: + name: Run Pytest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install pytest + + - name: Run tests + run: pytest + + docker: + name: Build and push Docker image + runs-on: ubuntu-latest + needs: test # Выполняется только если тесты прошли + if: github.event_name == 'pull_request' + steps: + - uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set lowercase owner + id: vars + run: | + OWNER_LC=$(echo "${GITHUB_REPOSITORY%/*}" | tr '[:upper:]' '[:lower:]') + echo "owner=${OWNER_LC}" >> "$GITHUB_OUTPUT" + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ghcr.io/${{ steps.vars.outputs.owner }}/science-helper:latest diff --git a/.github/workflows/tests-and-merge.yml b/.github/workflows/tests-and-merge.yml deleted file mode 100644 index 69a86bf..0000000 --- a/.github/workflows/tests-and-merge.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: test-and-automerge - -on: - push: - branches-ignore: [main] # Любая ветка, кроме main - -permissions: - contents: write # нужно для слияния веток - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pytest - - - name: Run tests - run: pytest - - merge: - needs: test - runs-on: ubuntu-latest - if: ${{ success() }} - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Merge to main - run: | - git config user.name "github-actions" - git config user.email "actions@github.com" - git checkout main - git merge --no-ff ${{ github.ref_name }} -m "Auto-merge from ${{ github.ref_name }}" - git push origin main