diff --git a/.github/actions/verify-standards-violation/action.yaml b/.github/actions/verify-standards-violation/action.yaml deleted file mode 100644 index 56f048698..000000000 --- a/.github/actions/verify-standards-violation/action.yaml +++ /dev/null @@ -1,89 +0,0 @@ -name: 'Standards Violation Info' -description: 'Action for verifying and adding comment to current PR about violated standards' - -inputs: - github_token: - description: 'GitHub token' - required: true - -runs: - using: 'composite' - steps: - - name: Verify Docs - if: always() - run: | - set -e - - FAIL_REASON="" - - echo "Verifying documentation..." - make docs 1>/dev/null - DOCS_CHANGES=$(git status --porcelain) - - if [ -n "$DOCS_CHANGES" ]; then - cat >> ${REASON_FILE} << EOF - * ❌ Documentation is out of date: - \`\`\`bash - $(echo -e "$DOCS_CHANGES" | sed 's/^/ /') - \`\`\` - Please run \`make docs\` and commit the changes. - EOF - exit 1 - fi - env: - REASON_FILE: ${{ runner.temp }}/failed_reason.txt - shell: bash - - - name: Verify Code Standards - if: always() - run: | - set +e - echo "Verifying code standard output usage..." - CODE_STD_OUT_USAGE=$(grep -r -E 'fmt\.Print|os\.Stdout|os\.Stderr' ./internal | grep --invert-match '^./internal/out') - - if [ -n "$CODE_STD_OUT_USAGE" ]; then - cat >> ${REASON_FILE} << EOF - * ❌ Found usage of \`os.Stdout\`, \`os.Stderr\` or \`fmt.Print\` in code: - \`\`\`bash - $(echo -e "$CODE_STD_OUT_USAGE" | sed 's/^/ /') - \`\`\` - Please use the \`internal/out\` package for output handling instead. - EOF - exit 1 - fi - env: - REASON_FILE: ${{ runner.temp }}/failed_reason.txt - shell: bash - - - name: Comment - if: always() - run: | - set +e - FLAGS="" - - # Determine which message to post based on validation result - FAIL_REASON=$(cat ${REASON_FILE}) - if [ -n "$FAIL_REASON" ]; then - echo "Standards violation detected" - TMP_FILE=$(mktemp) - MSG_TMPL=$(cat .github/actions/verify-standards-violation/violation-message_tmpl.md) - eval "echo -e \"${MSG_TMPL}\"" > $TMP_FILE - FLAGS="${FLAGS} --body-file ${TMP_FILE}" - else - echo "No standards violation detected" - FLAGS="${FLAGS} --body-file .github/actions/verify-standards-violation/no-violation-message.md" - fi - - # Check for existing comment by github-actions and edit if found - LAST_COMMENT_ID=$(gh pr view ${{ github.event.pull_request.number }} -R kyma-project/cli --json "comments" \ - | jq --raw-output '.comments[] | select(.author.login=="github-actions") | .id') - if [ -n "$LAST_COMMENT_ID" ]; then - echo "Editing last comment with ID: $LAST_COMMENT_ID" - FLAGS="${FLAGS} --edit-last" - fi - - gh pr comment ${{ github.event.pull_request.number }} -R kyma-project/cli $FLAGS - env: - GITHUB_TOKEN: ${{ inputs.github_token }} - REASON_FILE: ${{ runner.temp }}/failed_reason.txt - shell: bash diff --git a/.github/actions/verify-standards-violation/no-violation-message.md b/.github/actions/verify-standards-violation/no-violation-message.md deleted file mode 100644 index 9b014966e..000000000 --- a/.github/actions/verify-standards-violation/no-violation-message.md +++ /dev/null @@ -1,5 +0,0 @@ -# ✅ Proposed changes verification passed - -This pull request comes with up-to-date documentation and no illegal standard output usages. - -Find more detailed information in the `verify / standards (pull_request_target)` action. diff --git a/.github/actions/verify-standards-violation/violation-message_tmpl.md b/.github/actions/verify-standards-violation/violation-message_tmpl.md deleted file mode 100644 index f19df1107..000000000 --- a/.github/actions/verify-standards-violation/violation-message_tmpl.md +++ /dev/null @@ -1,9 +0,0 @@ -# ⚠️ Proposed changes verification failed - -This message means some of your changes may interrupt repository standards. - -Follow these requirements: - -${FAIL_REASON} - -Find more detailed information in the \`verify / standards (pull_request_target)\` action. diff --git a/.github/workflows/verify-pr-code.yml b/.github/workflows/verify-pr-code.yml new file mode 100644 index 000000000..ef7fe3025 --- /dev/null +++ b/.github/workflows/verify-pr-code.yml @@ -0,0 +1,104 @@ +name: verify-pr-code + +on: + pull_request: + types: [ opened, edited, synchronize, reopened, ready_for_review ] + +permissions: + contents: read + +jobs: + standards: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/setup-go + + - name: Verify Docs + if: always() + run: | + set -e + echo "Verifying documentation..." + make docs 1>/dev/null + DOCS_CHANGES=$(git status --porcelain) + + if [ -n "$DOCS_CHANGES" ]; then + cat >> "${REASON_FILE}" << EOF + * ❌ Documentation is out of date: + \`\`\`bash + $(echo -e "$DOCS_CHANGES" | sed 's/^/ /') + \`\`\` + Please run \`make docs\` and commit the changes. + EOF + exit 1 + fi + env: + REASON_FILE: ${{ runner.temp }}/failed_reason.txt + shell: bash + + - name: Verify Code Standards + if: always() + run: | + set +e + echo "Verifying code standard output usage..." + CODE_STD_OUT_USAGE=$(grep -r -E 'fmt\.Print|os\.Stdout|os\.Stderr' --exclude-dir=out ./internal) + + if [ -n "$CODE_STD_OUT_USAGE" ]; then + cat >> "${REASON_FILE}" << EOF + * ❌ Found usage of \`os.Stdout\`, \`os.Stderr\` or \`fmt.Print\` in code: + \`\`\`bash + $(echo -e "$CODE_STD_OUT_USAGE" | sed 's/^/ /') + \`\`\` + Please use the \`internal/out\` package for output handling instead. + EOF + exit 1 + fi + env: + REASON_FILE: ${{ runner.temp }}/failed_reason.txt + shell: bash + + - name: Prepare comment artifact + if: always() + run: | + set +e + FAIL_REASON=$(cat "${REASON_FILE}" 2>/dev/null || echo "") + + if [ -n "$FAIL_REASON" ]; then + echo "Standards violation detected" + cat > "${ARTIFACT_DIR}/comment-body.md" << EOF + # ⚠️ Proposed changes verification failed + + This message means some of your changes may interrupt repository standards. + + Follow these requirements: + + ${FAIL_REASON} + + Find more detailed information in the \`verify-pr-code / standards\` action. + EOF + else + echo "No standards violation detected" + cat > "${ARTIFACT_DIR}/comment-body.md" << 'EOF' + # ✅ Proposed changes verification passed + + This pull request comes with up-to-date documentation and no illegal standard output usages. + + Find more detailed information in the `verify-pr-code / standards` action. + EOF + fi + + echo "${{ github.event.pull_request.number }}" > "${ARTIFACT_DIR}/pr_number.txt" + env: + REASON_FILE: ${{ runner.temp }}/failed_reason.txt + ARTIFACT_DIR: ${{ runner.temp }} + shell: bash + + - name: Upload artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: standards-check-result + path: | + ${{ runner.temp }}/comment-body.md + ${{ runner.temp }}/pr_number.txt diff --git a/.github/workflows/verify-pr-comment.yml b/.github/workflows/verify-pr-comment.yml new file mode 100644 index 000000000..b440f5862 --- /dev/null +++ b/.github/workflows/verify-pr-comment.yml @@ -0,0 +1,60 @@ +name: verify-pr-comment + +on: + workflow_run: + workflows: ["verify-pr-code"] + types: [completed] + +permissions: {} + +jobs: + comment: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Download artifact + id: download + uses: actions/download-artifact@v4 + with: + name: standards-check-result + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + continue-on-error: true + + - name: Check artifact downloaded + if: steps.download.outcome == 'failure' + run: | + echo "Artifact not found — workflow may have been cancelled. Skipping comment." + shell: bash + + - name: Read PR number + if: steps.download.outcome == 'success' + id: pr + run: | + PR_NUMBER=$(cat pr_number.txt 2>/dev/null | tr -d '[:space:]') + if [ -z "$PR_NUMBER" ]; then + echo "pr_number.txt is empty or missing" + exit 1 + fi + echo "number=${PR_NUMBER}" >> "$GITHUB_OUTPUT" + shell: bash + + - name: Post or edit PR comment + if: steps.download.outcome == 'success' && steps.pr.outcome == 'success' + run: | + FLAGS="--body-file comment-body.md" + + LAST_COMMENT_ID=$(gh pr view "${{ steps.pr.outputs.number }}" -R kyma-project/cli --json "comments" \ + | jq --raw-output '.comments[] | select(.author.login=="github-actions[bot]") | .databaseId' \ + | tail -1) + + if [ -n "$LAST_COMMENT_ID" ]; then + echo "Editing last comment with ID: ${LAST_COMMENT_ID}" + FLAGS="${FLAGS} --edit-last" + fi + + gh pr comment "${{ steps.pr.outputs.number }}" -R kyma-project/cli $FLAGS + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml deleted file mode 100644 index ba3174819..000000000 --- a/.github/workflows/verify.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: verify - -on: - pull_request_target: - types: [ opened, edited, synchronize, reopened, ready_for_review ] - -permissions: - # Permission to post comments on pull requests - pull-requests: write - -jobs: - standards: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - with: - ref: ${{ github.event.pull_request.head.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} - - uses: ./.github/actions/setup-go - - name: Comment PR on violated standards - if: always() - uses: ./.github/actions/verify-standards-violation - with: - github_token: ${{ secrets.GITHUB_TOKEN }}