diff --git a/.gitea/workflows/pr-check.yaml b/.gitea/workflows/pr-check.yaml index 2d89269..da0df5c 100644 --- a/.gitea/workflows/pr-check.yaml +++ b/.gitea/workflows/pr-check.yaml @@ -66,99 +66,99 @@ jobs: run: | ansible-lint -handle_failures: - runs-on: ubuntu-latest - needs: [leak_test, lint_test] - if: needs.leak_test.result != 'success' || needs.lint_test.result != 'success' + handle_failures: + runs-on: ubuntu-latest + needs: [leak_test, lint_test] + if: needs.leak_test.result != 'success' || needs.lint_test.result != 'success' - steps: - - name: Comment, label, and close PR - run: | - API="${{ vars.GIT_SERVER_URL }}/api/v1/repos/${{ github.repository }}" - PR="${{ github.event.pull_request.number }}" - TOKEN="${{ secrets.GITEA_TOKEN }}" + steps: + - name: Comment, label, and close PR + run: | + API="${{ vars.GIT_SERVER_URL }}/api/v1/repos/${{ github.repository }}" + PR="${{ github.event.pull_request.number }}" + TOKEN="${{ secrets.GITEA_TOKEN }}" - COMMENT_BODY="❌ CI checks failed.\n\nLeak test: ${{ needs.leak_test.result }}\nLint: ${{ needs.lint_test.result }}" + COMMENT_BODY="❌ CI checks failed.\n\nLeak test: ${{ needs.leak_test.result }}\nLint: ${{ needs.lint_test.result }}" - # Find existing comment - EXISTING_COMMENT_ID=$(curl -s -H "Authorization: token $TOKEN" \ - "$API/issues/$PR/comments" \ - | jq -r '.[] | select(.body | test("")) | .id') + # Find existing comment + EXISTING_COMMENT_ID=$(curl -s -H "Authorization: token $TOKEN" \ + "$API/issues/$PR/comments" \ + | jq -r '.[] | select(.body | test("")) | .id') - # Update or create comment - if [ -n "$EXISTING_COMMENT_ID" ]; then + # Update or create comment + if [ -n "$EXISTING_COMMENT_ID" ]; then + curl -s -X PATCH \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"body\":\"\n$COMMENT_BODY\"}" \ + "$API/issues/$PR/comments/$EXISTING_COMMENT_ID" + else + curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"body\":\"\n$COMMENT_BODY\"}" \ + "$API/issues/$PR/comments" + fi + + # Add label if missing + LABELS=$(curl -s -H "Authorization: token $TOKEN" "$API/issues/$PR/labels" | jq -r '.[] | .name') + if ! echo "$LABELS" | grep -q "^ci-failed$"; then + curl -s -X POST \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d '["ci-failed"]' \ + "$API/issues/$PR/labels" + fi + + # Close PR curl -s -X PATCH \ -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ - -d "{\"body\":\"\n$COMMENT_BODY\"}" \ - "$API/issues/$PR/comments/$EXISTING_COMMENT_ID" - else - curl -s -X POST \ - -H "Authorization: token $TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"body\":\"\n$COMMENT_BODY\"}" \ - "$API/issues/$PR/comments" - fi - - # Add label if missing - LABELS=$(curl -s -H "Authorization: token $TOKEN" "$API/issues/$PR/labels" | jq -r '.[] | .name') - if ! echo "$LABELS" | grep -q "^ci-failed$"; then - curl -s -X POST \ - -H "Authorization: token $TOKEN" \ - -H "Content-Type: application/json" \ - -d '["ci-failed"]' \ - "$API/issues/$PR/labels" - fi - - # Close PR - curl -s -X PATCH \ - -H "Authorization: token $TOKEN" \ - -H "Content-Type: application/json" \ - -d '{"state":"closed"}' \ - "$API/pulls/$PR" - -handle_success: - runs-on: ubuntu-latest - needs: [leak_test, lint_test] - if: needs.leak_test.result == 'success' && needs.lint_test.result == 'success' - - steps: - - name: Update comment, remove label, reopen PR - run: | - API="${{ vars.GIT_SERVER_URL }}/api/v1/repos/${{ github.repository }}" - PR="${{ github.event.pull_request.number }}" - TOKEN="${{ secrets.GITEA_TOKEN }}" - - COMMENT_BODY="✅ All CI checks passed.\n\nLeak test: ${{ needs.leak_test.result }}\nLint: ${{ needs.lint_test.result }}" - - # Find existing comment - EXISTING_COMMENT_ID=$(curl -s -H "Authorization: token $TOKEN" \ - "$API/issues/$PR/comments" \ - | jq -r '.[] | select(.body | test("")) | .id') - - # Update comment if exists - if [ -n "$EXISTING_COMMENT_ID" ]; then - curl -s -X PATCH \ - -H "Authorization: token $TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"body\":\"\n$COMMENT_BODY\"}" \ - "$API/issues/$PR/comments/$EXISTING_COMMENT_ID" - fi - - # Remove label if exists - LABELS=$(curl -s -H "Authorization: token $TOKEN" "$API/issues/$PR/labels" | jq -r '.[] | .name') - if echo "$LABELS" | grep -q "^ci-failed$"; then - curl -s -X DELETE \ - -H "Authorization: token $TOKEN" \ - "$API/issues/$PR/labels/ci-failed" - fi - - # Reopen PR if closed - PR_STATE=$(curl -s -H "Authorization: token $TOKEN" "$API/pulls/$PR" | jq -r '.state') - if [ "$PR_STATE" = "closed" ]; then - curl -s -X PATCH \ - -H "Authorization: token $TOKEN" \ - -H "Content-Type: application/json" \ - -d '{"state":"open"}' \ + -d '{"state":"closed"}' \ "$API/pulls/$PR" - fi + + handle_success: + runs-on: ubuntu-latest + needs: [leak_test, lint_test] + if: needs.leak_test.result == 'success' && needs.lint_test.result == 'success' + + steps: + - name: Update comment, remove label, reopen PR + run: | + API="${{ vars.GIT_SERVER_URL }}/api/v1/repos/${{ github.repository }}" + PR="${{ github.event.pull_request.number }}" + TOKEN="${{ secrets.GITEA_TOKEN }}" + + COMMENT_BODY="✅ All CI checks passed.\n\nLeak test: ${{ needs.leak_test.result }}\nLint: ${{ needs.lint_test.result }}" + + # Find existing comment + EXISTING_COMMENT_ID=$(curl -s -H "Authorization: token $TOKEN" \ + "$API/issues/$PR/comments" \ + | jq -r '.[] | select(.body | test("")) | .id') + + # Update comment if exists + if [ -n "$EXISTING_COMMENT_ID" ]; then + curl -s -X PATCH \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"body\":\"\n$COMMENT_BODY\"}" \ + "$API/issues/$PR/comments/$EXISTING_COMMENT_ID" + fi + + # Remove label if exists + LABELS=$(curl -s -H "Authorization: token $TOKEN" "$API/issues/$PR/labels" | jq -r '.[] | .name') + if echo "$LABELS" | grep -q "^ci-failed$"; then + curl -s -X DELETE \ + -H "Authorization: token $TOKEN" \ + "$API/issues/$PR/labels/ci-failed" + fi + + # Reopen PR if closed + PR_STATE=$(curl -s -H "Authorization: token $TOKEN" "$API/pulls/$PR" | jq -r '.state') + if [ "$PR_STATE" = "closed" ]; then + curl -s -X PATCH \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d '{"state":"open"}' \ + "$API/pulls/$PR" + fi