diff --git a/.github/scripts/check-license-headers.py b/.github/scripts/check-license-headers.py index b46ebbd114..6e42e39149 100755 --- a/.github/scripts/check-license-headers.py +++ b/.github/scripts/check-license-headers.py @@ -126,11 +126,9 @@ def main(): violation_text = '\n'.join(violations) - # Set output for GitHub Actions - github_output = os.environ.get('GITHUB_OUTPUT') - if github_output: - with open(github_output, 'a') as f: - f.write(f"violations< - comment.user.type === 'Bot' && - comment.body.includes('License Header Violations Found') - ); - - if (botComment) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: body - }); - } else { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - body: body - }); - } - env: - VIOLATIONS: ${{ steps.license-check.outputs.violations }} - - - name: Update PR comment (all violations resolved) - if: success() - uses: actions/github-script@v8 + - name: Save PR number + if: always() + run: echo "${{ github.event.pull_request.number }}" > pr_number.txt + + - name: Upload results + if: always() + uses: actions/upload-artifact@v4 with: - script: | - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - }); - - const botComment = comments.find(comment => - comment.user.type === 'Bot' && - (comment.body.includes('License Header Violations Found') || comment.body.includes('License Header Check Passed')) - ); - - if (botComment) { - const successBody = [ - '## āœ… License Header Check Passed', - '', - 'All newly added files have proper license headers. Great work! šŸŽ‰' - ].join('\n'); - - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: successBody - }); - } \ No newline at end of file + name: license-check-results + path: | + pr_number.txt + violations.txt diff --git a/.github/workflows/license-header-comment.yml b/.github/workflows/license-header-comment.yml new file mode 100644 index 0000000000..efea14b001 --- /dev/null +++ b/.github/workflows/license-header-comment.yml @@ -0,0 +1,99 @@ +# +# Copyright OpenSearch Contributors +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# + +# Comments on PRs with license header check results. +# Triggered by the License Header Check workflow. + +name: License Header Comment + +on: + workflow_run: + workflows: ['License Header Check'] + types: [completed] + +permissions: + issues: write + pull-requests: write + +jobs: + comment: + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' + + steps: + - name: Download results + uses: actions/download-artifact@v4 + with: + name: license-check-results + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Read PR number + id: pr + run: echo "number=$(cat pr_number.txt)" >> "$GITHUB_OUTPUT" + + - name: Comment on PR + uses: actions/github-script@v8 + with: + script: | + const fs = require('fs'); + const prNumber = parseInt('${{ steps.pr.outputs.number }}'); + const failed = '${{ github.event.workflow_run.conclusion }}' === 'failure'; + const hasViolations = fs.existsSync('violations.txt'); + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + (comment.body.includes('License Header Violations Found') || comment.body.includes('License Header Check Passed')) + ); + + let body; + if (failed && hasViolations) { + const violations = fs.readFileSync('violations.txt', 'utf8').trim(); + body = [ + '## āš ļø License Header Violations Found', + '', + 'The following newly added files are missing required license headers:', + '', + violations, + '', + 'Please add the appropriate license header to each file and push your changes.', + '', + '**See the license header requirements:** https://github.com/opensearch-project/data-prepper/blob/main/CONTRIBUTING.md#license-headers' + ].join('\n'); + } else if (!failed && botComment) { + body = [ + '## āœ… License Header Check Passed', + '', + 'All newly added files have proper license headers. Great work! šŸŽ‰' + ].join('\n'); + } else { + return; + } + + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: body + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: body + }); + } diff --git a/data-prepper-api/src/test/java/org/opensearch/dataprepper/AnotherNewTest.java b/data-prepper-api/src/test/java/org/opensearch/dataprepper/AnotherNewTest.java new file mode 100644 index 0000000000..28ea4963de --- /dev/null +++ b/data-prepper-api/src/test/java/org/opensearch/dataprepper/AnotherNewTest.java @@ -0,0 +1,13 @@ +package org.opensearch.dataprepper; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class AnotherNewTest { + @Test + public void testSomething() { + assertThat(true, equalTo(true)); + } +} diff --git a/data-prepper-api/src/test/java/org/opensearch/dataprepper/NewTest.java b/data-prepper-api/src/test/java/org/opensearch/dataprepper/NewTest.java new file mode 100644 index 0000000000..5d1d0ca2fc --- /dev/null +++ b/data-prepper-api/src/test/java/org/opensearch/dataprepper/NewTest.java @@ -0,0 +1,13 @@ +package org.opensearch.dataprepper; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class NewTest { + @Test + public void testSomething() { + assertThat(true, equalTo(true)); + } +}