... I feel like an idiot right now...

This commit is contained in:
2024-12-19 12:21:33 -05:00
parent 4d0f5bb1f4
commit 951a4e9fd8
+94 -99
View File
@@ -18,114 +18,109 @@ jobs:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Find Current PR - name: Check if PR Exists
id: findPr id: check-pr
uses: jwalton/gh-find-current-pr@v1.3.3 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"
sonarqube-analysis:
name: SonarQube Analysis
runs-on: ubuntu-latest
needs: check-and-create-pr
steps:
- name: Checkout Code
uses: actions/checkout@v4
# - name: Start Gitea-Sonarqube Bot
# uses: docker://justusbunsi/gitea-sonarqube-bot:v0.3.3
# with:
# # Required inputs for the bot
# args: >
# --sonarqube-url ${{ secrets.SONARQUBE_URL }}
# --sonarqube-token ${{ secrets.SONARQUBE_TOKEN }}
# --git-provider github
# --git-api-url https://api.github.com
# --git-token ${{ secrets.GITHUB_TOKEN }}
# --repository my-org/my-repo
# --pull-request-id ${{ github.event.pull_request.number }}
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@v4.1.0
env:
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
- name: SonarQube Quality Gate
id: quality-gate
uses: sonarsource/sonarqube-quality-gate-action@v1.1.0
env:
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
- name: Custom Quality Gate Check
uses: DesarrolloORT/sonarqube-quality-gate-action@v1.0.1
id: quality-gate-check
with: with:
state: open sonar-project-key: rinoa-docker
# - name: Check if PR Exists sonar-host-url: ${{ secrets.SONARQUBE_HOST }}
# id: check-pr sonar-token: ${{ secrets.SONARQUBE_TOKEN }}
# 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 - name: JSON clean-up for proccessing...
# if: ${{ steps.check-pr.outputs.pr_status.state }} == 'closed' id: json-cleanup
# id: create-pr run: |
# run: | echo "Cleaning up quality gate response..."
# echo "Creating PR..." echo '${{ steps.quality-gate-check.outputs.quality-gate-result }}' > qg_input.txt
# curl ${{ vars.RINOA_GITEA_URL }}/api/v1/repos/${{ github.repository }}/pulls \ sed -E 's/([a-zA-Z0-9_]+):/\\"\1\\":/g; s/:([^",{}\[\]]+)/:"\1"/g' qg_input.txt > qg_raw.json
# -X 'POST' \ jq -c '.' qg_raw.json > qg_fixed_json.json
# -H 'Accept: application/json' \ projstatus=$(jq -r '.projectStatus.status' qg_fixed_json.json)
# -H 'Authorization: token ${{ secrets.BOT_GITEA_TOKEN }}' \ echo "${projstatus}"
# -H 'Content-Type: application/json' \ caycStatus=$(jq -r '.projectStatus.caycStatus' qg_fixed_json.json)
# -d '{ echo "${caycStatus}"
# "title": "PR: ${{ github.ref_name }} -> main", conditions=$(jq -c '.projectStatus.conditions' qg_fixed_json.json)
# "body": "This is an automated PR created by Gitea Actions.", echo "${conditions}"
# "base": "main", echo "projstatus=${projstatus}" >> $GITHUB_OUTPUT
# "head": "${{ github.ref_name }}" echo "caycStatus=${caycStatus}" >> $GITHUB_OUTPUT
# }' | jq '{index: .number}' > pr_created.json echo "conditions=${conditions}" >> $GITHUB_OUTPUT
# echo "pr_created=$(jq -c . pr_created.json)" >> "$GITHUB_OUTPUT" echo "qg_fixed_json=$(cat qg_fixed_json.json)" >> $GITHUB_ENV
# # Job 2: Run SonarQube Analysis - name: Convert JSON to Markdown Table
# sonarqube-analysis: id: convert-json-to-md
# name: SonarQube Analysis uses: buildingcash/json-to-markdown-table-action@v1.1.0
# runs-on: ubuntu-latest with:
# needs: check-and-create-pr json: ${{ steps.json-cleanup.outputs.conditions }}
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# # - name: Start Gitea-Sonarqube Bot
# # uses: docker://justusbunsi/gitea-sonarqube-bot:v0.3.3
# # with:
# # # Required inputs for the bot
# # args: >
# # --sonarqube-url ${{ secrets.SONARQUBE_URL }}
# # --sonarqube-token ${{ secrets.SONARQUBE_TOKEN }}
# # --git-provider github
# # --git-api-url https://api.github.com
# # --git-token ${{ secrets.GITHUB_TOKEN }}
# # --repository my-org/my-repo
# # --pull-request-id ${{ github.event.pull_request.number }}
# - name: SonarQube Scan
# uses: sonarsource/sonarqube-scan-action@v4.1.0
# env:
# SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
# SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
# - name: SonarQube Quality Gate
# id: quality-gate
# uses: sonarsource/sonarqube-quality-gate-action@v1.1.0
# env:
# SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
# SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
# - name: Custom Quality Gate Check
# uses: DesarrolloORT/sonarqube-quality-gate-action@v1.0.1
# id: quality-gate-check
# with:
# sonar-project-key: rinoa-docker
# sonar-host-url: ${{ secrets.SONARQUBE_HOST }}
# sonar-token: ${{ secrets.SONARQUBE_TOKEN }}
# - name: JSON clean-up for proccessing...
# id: json-cleanup
# run: |
# echo "Cleaning up quality gate response..."
# echo '${{ steps.quality-gate-check.outputs.quality-gate-result }}' > qg_input.txt
# sed -E 's/([a-zA-Z0-9_]+):/\\"\1\\":/g; s/:([^",{}\[\]]+)/:"\1"/g' qg_input.txt > qg_raw.json
# jq -c '.' qg_raw.json > qg_fixed_json.json
# projstatus=$(jq -r '.projectStatus.status' qg_fixed_json.json)
# echo "${projstatus}"
# caycStatus=$(jq -r '.projectStatus.caycStatus' qg_fixed_json.json)
# echo "${caycStatus}"
# conditions=$(jq -c '.projectStatus.conditions' qg_fixed_json.json)
# echo "${conditions}"
# echo "projstatus=${projstatus}" >> $GITHUB_OUTPUT
# echo "caycStatus=${caycStatus}" >> $GITHUB_OUTPUT
# echo "conditions=${conditions}" >> $GITHUB_OUTPUT
# echo "qg_fixed_json=$(cat qg_fixed_json.json)" >> $GITHUB_ENV
# - name: Convert JSON to Markdown Table
# id: convert-json-to-md
# uses: buildingcash/json-to-markdown-table-action@v1.1.0
# with:
# json: ${{ steps.json-cleanup.outputs.conditions }}
- name: Verify PR number - name: Verify PR number
run: | run: |
echo "PR number: ${{ steps.findPr.outputs.pr }}" echo "PR number: ${{ steps.create-pr.outputs.pr_created }}"
# - name: Post SonarQube Results as Comment # - name: Post SonarQube Results as Comment
# run: | # run: |
# curl ${{ vars.RINOA_GITEA_URL }}/api/v1/repos/${{ github.repository }}/pulls/${{ github.pull_request.number }}/reviews \ # curl ${{ vars.RINOA_GITEA_URL }}/api/v1/repos/${{ github.repository }}/pulls/${{ steps.create-pr.outputs.pr_created }}/reviews \
# -X POST \ # -X POST \
# -H 'Accept: application/json' \ # -H 'Accept: application/json' \
# -H 'Authorization: token ${{ secrets.BOT_GITEA_TOKEN }}' \ # -H 'Authorization: token ${{ secrets.BOT_GITEA_TOKEN }}' \