diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 732bd8a..6fb3bdc 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -91,21 +91,21 @@ jobs: htmlcov/ retention-days: 7 - - name: Send test results notification - if: always() + - name: Send test failure notification + if: failure() uses: appleboy/telegram-action@v1.0.0 with: to: ${{ secrets.TELEGRAM_CHAT_ID }} token: ${{ secrets.TELEGRAM_BOT_TOKEN }} message: | - ${{ job.status == 'success' && 'βœ…' || '❌' }} CI Tests: ${{ job.status }} + ❌ CI Tests Failed πŸ“¦ Repository: prod 🌿 Branch: ${{ github.ref_name }} πŸ“ Commit: ${{ github.sha }} πŸ‘€ Author: ${{ github.actor }} - ${{ job.status == 'success' && 'βœ… All tests passed! Pull request will be created.' || '❌ Tests failed! Deployment blocked.' }} + ❌ Tests failed! Deployment blocked. Please fix the issues and try again. πŸ”— View details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} continue-on-error: true @@ -174,49 +174,78 @@ jobs: - name: Create Pull Request if: steps.check-pr.outputs.exists == 'false' id: create-pr - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref_name }} - base: main - title: "Merge ${{ github.ref_name }} into main" - body: | - ## Changes - - This PR was automatically created after successful CI tests. - - - Branch: `${{ github.ref_name }}` - - Commit: `${{ github.sha }}` - - Author: @${{ github.actor }} - - ## Test Results - - βœ… All tests passed successfully! - - Please review the changes and merge when ready. - labels: | - automated - ready-for-review - draft: false - - - name: Get created PR number - if: steps.check-pr.outputs.exists == 'false' && steps.create-pr.outcome == 'success' - id: get-pr-number uses: actions/github-script@v6 with: script: | const branchName = context.ref.replace('refs/heads/', ''); - const { data: prs } = await github.rest.pulls.list({ - owner: context.repo.owner, - repo: context.repo.repo, - head: `${context.repo.owner}:${branchName}`, - base: 'main', - state: 'open' - }); - if (prs.length > 0) { - core.setOutput('number', prs[0].number); - core.setOutput('url', prs[0].html_url); + console.log(`πŸ“ Creating PR from ${branchName} to main...`); + + try { + const { data: pr } = await github.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: `Merge ${branchName} into main`, + head: branchName, + base: 'main', + body: `## Changes + +This PR was automatically created after successful CI tests. + +- Branch: \`${branchName}\` +- Commit: \`${{ github.sha }}\` +- Author: @${{ github.actor }} + +## Test Results + +βœ… All tests passed successfully! + +Please review the changes and merge when ready.`, + draft: false + }); + + // ДобавляСм labels + try { + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + labels: ['automated', 'ready-for-review'] + }); + } catch (labelError) { + console.log(`⚠️ Could not add labels: ${labelError.message}`); + } + + core.setOutput('number', pr.number.toString()); + core.setOutput('url', pr.html_url); + console.log(`βœ… PR #${pr.number} created successfully: ${pr.html_url}`); + + } catch (error) { + console.error(`❌ Failed to create PR: ${error.message}`); + if (error.status === 422) { + console.log('⚠️ PR might already exist or branch is up to date with base'); + // ΠŸΡ€ΠΎΠ±ΡƒΠ΅ΠΌ Π½Π°ΠΉΡ‚ΠΈ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ PR + const { data: prs } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + head: `${context.repo.owner}:${branchName}`, + base: 'main', + state: 'open' + }); + + if (prs.length > 0) { + const pr = prs[0]; + core.setOutput('number', pr.number.toString()); + core.setOutput('url', pr.html_url); + console.log(`βœ… Found existing PR #${pr.number}: ${pr.html_url}`); + } else { + core.setOutput('number', ''); + core.setOutput('url', `${{ github.server_url }}/${{ github.repository }}/pulls`); + throw error; + } + } else { + throw error; + } } - name: Send PR notification - PR exists @@ -252,9 +281,9 @@ jobs: πŸ“ Commit: ${{ github.sha }} πŸ‘€ Author: ${{ github.actor }} - βœ… All tests passed! Pull request #${{ steps.get-pr-number.outputs.number }} has been created and is ready for review. + ${{ steps.create-pr.outputs.number != '' && format('βœ… All tests passed! Pull request #{0} has been created and is ready for review.', steps.create-pr.outputs.number) || 'βœ… All tests passed! Pull request has been created and is ready for review.' }} - πŸ”— View PR: ${{ steps.get-pr-number.outputs.url }} + ${{ steps.create-pr.outputs.url != '' && format('πŸ”— View PR: {0}', steps.create-pr.outputs.url) || format('πŸ”— View PRs: {0}/{1}/pulls', github.server_url, github.repository) }} continue-on-error: true rollback: