Files
rinoa-docker/.gitea/workflows/branch-sonarscan-pr-merge.yml
T

103 lines
3.7 KiB
YAML

name: Gitea Branch PR, SonarQube Analyze, and Merge Workflow
on:
push:
branches-ignore:
- main
create:
branches:
- '**'
jobs:
# Job 1: Check if PR exists and create one if the branch is new
check-and-create-pr:
name: Check and Create PR
runs-on: ubuntu-latest
outputs:
pr_created: ${{ steps.check-pr.outputs.pr_created }}
pr_index: ${{ steps.create-pr.outputs.pr_index }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Check if PR Exists
id: check-pr
run: |
echo "Checking for existing PR..."
curl ${{ vars.RINOA_GITEA_URL }}/api/v1/repos/${{ github.repository }}/pulls/main/${{ github.ref_name }} \
-X 'GET' \
-H 'Accept: application/json' \
-H 'Authorization: token ${{ secrets.BOT_GITEA_TOKEN }}' \
-s | jq '{index: .number, state: .state}' > pr_status.json
echo "pr_status=$(jq -c . pr_status.json)" >> "$GITHUB_OUTPUT"
- name: Create PR in Gitea
if: ${{ steps.check-pr.outputs.pr_status.state }} == 'closed'
id: create-pr
run: |
echo "Creating PR..."
curl ${{ vars.RINOA_GITEA_URL }}/api/v1/repos/${{ github.repository }}/pulls \
-X 'POST' \
-H 'Accept: application/json' \
-H 'Authorization: token ${{ secrets.BOT_GITEA_TOKEN }}' \
-H 'Content-Type: application/json' \
-d '{
"title": "PR: ${{ github.ref_name }} -> main",
"body": "This is an automated PR created by Gitea Actions.",
"base": "main",
"head": "${{ github.ref_name }}"
}' | jq '{index: .number}' > pr_created.json
echo "pr_created=$(jq -c . pr_created.json)" >> "$GITHUB_OUTPUT"
# # Job 2: Run SonarQube Analysis
# sonarqube-analysis:
# runs-on: ubuntu-latest
# needs: check-and-create-pr
# outputs:
# quality_gate_status: ${{ steps.quality-gate.outputs.quality-gate-status }}
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# # Step 1: Run SonarQube Scan
# - name: SonarQube Scan
# uses: sonarsource/sonarqube-scan-action@v4.1.0
# env:
# SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
# SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
# # Step 2: SonarQube Quality Gate Check
# - name: SonarQube Quality Gate
# id: quality-gate
# uses: sonarsource/sonarqube-quality-gate-action@v1
# env:
# SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
# SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
# - name: Log Quality Gate Result
# run: |
# echo "Quality Gate Status: ${{ steps.quality-gate.outputs.quality-gate-status }}"
# # Job 3: Merge PR if Quality Gate passes
# merge-pr:
# runs-on: ubuntu-latest
# needs: [check-and-create-pr, sonarqube-analysis]
# if: needs.sonarqube-analysis.outputs.quality_gate_status == 'PASSED'
# steps:
# - name: Merge PR in Gitea
# uses: prasiman/gocurl@v1
# with:
# url: "${{ secrets.GITEA_INSTANCE_URL }}/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/pulls/${{ needs.check-and-create-pr.outputs.pr_index }}"
# method: "POST"
# headers: '{ "Authorization": "token ${{ secrets.GITEA_API_TOKEN }}", "Content-Type": "application/json" }'
# params: >-
# {
# "Do": "merge",
# "delete_branch_after_merge": true,
# "force_merge": true,
# "merge_when_checks_succeed": true
# }
# - name: Confirm Merge
# run: echo "PR has been successfully merged into main."