Skip to content

Commit

Permalink
Merge pull request #1781 from jplag/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
tsaglam authored May 23, 2024
2 parents e1b4d6e + a8e6f99 commit 1646516
Show file tree
Hide file tree
Showing 138 changed files with 4,334 additions and 3,172 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/closeDevIssues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Close linked issue on PR merge

on:
pull_request:
types:
- closed

jobs:
close_issues:
if: github.event.pull_request.merged == true && github.base_ref == 'develop'
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Run script
working-directory: .github/workflows/scripts
run: |
pip install requests
python closeDevIssues.py ${{ secrets.GITHUB_TOKEN }} jplag JPlag ${{ github.event.pull_request.number }}
160 changes: 160 additions & 0 deletions .github/workflows/complete-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Builds JPlag and then runs Datasets and Report Viewer e2e tests on multiple OS
name: Complete e2e Test

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
paths:
- ".github/workflows/complete-e2e.yml"
- "report-viewer/**"
- "**/pom.xml"
- "**.java"
- "**.g4"

jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
concurrent_skipping: 'same_content_newer'
skip_after_successful_duplicate: 'true'

build_jar:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'

- uses: actions/setup-node@v4
with:
node-version: "18"

- name: Build Assembly
run: mvn -Pwith-report-viewer -DskipTests clean package assembly:single

- name: Rename Jar
run: mv cli/target/jplag-*-jar-with-dependencies.jar cli/target/jplag.jar

- name: Upload Assembly
uses: actions/upload-artifact@v4
with:
name: "JPlag"
path: "cli/target/jplag.jar"
retention-days: 30

run_jplag:
needs: build_jar
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
dataset: [
{zip: "progpedia.zip", name: "progpedia", folder: "ACCEPTED", language: "java", cliArgs: "-bc base"},
{zip: "fileSingleRoot.zip", name: "fileSingleRoot", folder: "fileSingleRoot", language: "java", cliArgs: ""},
{zip: "folderSingleRoot.zip", name: "folderSingleRoot", folder: "folderSingleRoot", language: "java", cliArgs: ""},
{zip: "fileMultiRoot.zip", name: "fileMultiRoot", folder: "f0", language: "java", cliArgs: "--new f1"},
{zip: "folderMultiRoot.zip", name: "folderMultiRoot", folder: "f0", language: "java", cliArgs: "--new f1"},
{zip: "mixedMultiRoot.zip", name: "mixedBaseFile", folder: "f0", language: "java", cliArgs: "--new f1"},
{zip: "mixedMultiRoot.zip", name: "mixedBaseFolder", folder: "f1", language: "java", cliArgs: "--new f0"},
{zip: "cpp.zip", name: "cpp", folder: "./cpp", language: "cpp", cliArgs: ""},
{zip: "csharp.zip", name: "csharp", folder: "./csharp", language: "csharp", cliArgs: ""},
{zip: "python.zip", name: "python", folder: "./python", language: "python3", cliArgs: ""}
]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'

- name: Get JAR
uses: actions/download-artifact@v4
with:
name: JPlag

- name: Copy and unzip dataset windows
if: ${{ matrix.os == 'windows-latest' }}
run: |
Expand-Archive -LiteralPath .github/workflows/files/${{ matrix.dataset.zip }} -DestinationPath ./
- name: Copy and unzip dataset macos and ubuntu
if: ${{ matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest'}}
run: |
unzip .github/workflows/files/${{ matrix.dataset.zip }}
- name: Run JPlag
run: |
java -jar jplag.jar ${{ matrix.dataset.folder }} -l ${{ matrix.dataset.language }} -r ${{ matrix.dataset.name }}-report ${{ matrix.dataset.cliArgs }}
- name: Upload result
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.dataset.name }}-${{ matrix.os }}"
path: "${{ matrix.dataset.name }}-report.zip"
retention-days: 30

e2e_test:
needs: run_jplag
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "18"

- name: Install and Build
working-directory: report-viewer
run: |
npm install
npm run build
- name: Install playwright
working-directory: report-viewer
run: npx playwright install --with-deps

- name: Download JPlag Reports
uses: actions/download-artifact@v4
with:
pattern: "*-${{ matrix.os }}"
path: "report-viewer/tests/e2e/assets"
merge-multiple: true

- name: Run tests
working-directory: report-viewer
run: |
npm run test:e2e
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: "test-results-${{ matrix.os }}"
path: |
report-viewer/test-results
report-viewer/playwright-report
retention-days: 30
Binary file added .github/workflows/files/cpp.zip
Binary file not shown.
Binary file added .github/workflows/files/csharp.zip
Binary file not shown.
Binary file added .github/workflows/files/fileMultiRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/fileSingleRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/folderMultiRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/folderSingleRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/mixedMultiRoot.zip
Binary file not shown.
Binary file added .github/workflows/files/python.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Upload Assembly
uses: actions/upload-artifact@v4
with:
name: "JPlag"
path: "jplag.cli/target/jplag-*-jar-with-dependencies.jar"
name: "JPlag Jar"
path: "cli/target/jplag-*-jar-with-dependencies.jar"


4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to Maven Central & GitHub
on:
workflow_dispatch:
release:
types: [created]
types: [created, published]
jobs:
publish-maven-central:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
run: mvn -Pwith-report-viewer -U -B clean package assembly:single

- name: Attach CLI to Release on GitHub
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: cli/target/jplag-*-jar-with-dependencies.jar
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
npm run build-demo
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.5.0
uses: JamesIves/github-pages-deploy-action@v4.6.1
with:
branch: gh-pages
folder: report-viewer/dist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
npm run build-dev
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.5.0
uses: JamesIves/github-pages-deploy-action@v4.6.1
with:
branch: gh-pages
folder: report-viewer/dist
Expand Down
58 changes: 0 additions & 58 deletions .github/workflows/report-viewer-e2e.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/report-viewer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
npm run build-prod
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.5.0
uses: JamesIves/github-pages-deploy-action@v4.6.1
with:
branch: gh-pages
folder: report-viewer/dist
76 changes: 76 additions & 0 deletions .github/workflows/scripts/closeDevIssues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import requests
import re
import sys

headers = {"Authorization": f"Bearer {sys.argv[1]}"}

owner = sys.argv[2]
repo = sys.argv[3]
pr_number = int(sys.argv[4])

query = f"""
{{
repository(owner: "{owner}", name: "{repo}") {{
pullRequest(number: {pr_number}) {{
merged
baseRefName
body
closingIssuesReferences (first: 50) {{
nodes {{
number
}}
}}
}}
}}
}}
"""

def run_query(query):
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
if request.status_code == 200:
return request.json()
else:
raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query))


closing_keywords = [
'closes', 'close', 'closed', 'fix', 'fixes', 'fixed', 'resolves', 'resolve', 'resolved'
]

# checks all subsequeces of the pr body for closing keywords and extracts the coresponidng issue numbers
def subsequences_matching_regex(input_string, regex):
matches = []
for i in range(len(input_string)):
for j in range(i+1, len(input_string)+1):
subsequence = input_string[i:j]
match = re.fullmatch(regex, subsequence)
if match:
matches.append(int(match.group(1)))
return matches

# gets all issues linked to pr either via the closing keywords or the sidebar
def get_linked_issues(result):
issue_body = result['body'].lower() + "." # we append a dot to the end of the body to make sure the last word is checked with the regex
closing_issues = []
for keyword in closing_keywords:
closing_issues.extend(subsequences_matching_regex(issue_body, f'{keyword} #([0-9]+)[^0-9]'))
for k in result['closingIssuesReferences']['nodes']:
closing_issues.append(k['number'])
return list(set(closing_issues))

result = run_query(query)['data']['repository']['pullRequest']
issues = get_linked_issues(result)

def close_issue(issue_number):
requests.post(f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}/comments", json={"body": f"Closed by #{pr_number}."}, headers=headers)
requests.patch(f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}", json={"state": "closed"}, headers=headers)

if result['baseRefName'] != "develop":
print("PR not merged to develop, not closing issues")
elif result['merged']:
print(f"Closing issues: {issues}")
for issue in issues:
close_issue(issue)
print(f"Closed issue {issue}")
else:
print("PR not merged, not closing issues")
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.jplag/jplag/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.jplag/jplag)
[![License](https://img.shields.io/github/license/jplag/jplag.svg)](https://github.com/jplag/jplag/blob/main/LICENSE)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/jplag/JPlag)](https://github.com/jplag/JPlag/pulse)
[![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=jplag_JPlag&metric=coverage)](https://sonarcloud.io/component_measures/metric/coverage/list?id=jplag_JPlag)
[![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=jplag_JPlag&metric=coverage)](https://sonarcloud.io/component_measures?metric=Coverage&view=list&id=jplag_JPlag)
[![Report Viewer](https://img.shields.io/badge/report%20viewer-online-b80025)](https://jplag.github.io/JPlag/)
[![Java Version](https://img.shields.io/badge/java-SE%2021-yellowgreen)](#download-and-installation)

Expand All @@ -32,7 +32,7 @@ All supported languages and their supported versions are listed below.
| [C](https://isocpp.org) | 11 | c | legacy | JavaCC |
| [C++](https://isocpp.org) | 14 | cpp | beta | ANTLR 4 |
| [C#](https://docs.microsoft.com/en-us/dotnet/csharp/) | 6 | csharp | mature | ANTLR 4 |
| [Python](https://www.python.org) | 3.6 | python3 | legacy | ANTLR 4 |
| [Python](https://www.python.org) | 3.6 | python3 | beta | ANTLR 4 |
| [JavaScript](https://www.javascript.com/) | ES6 | javascript | beta | ANTLR 4 |
| [TypeScript](https://www.typescriptlang.org/) | [~5](https://github.com/antlr/grammars-v4/tree/master/javascript/typescript/README.md) | typescript | beta | ANTLR 4 |
| [Go](https://go.dev) | 1.17 | golang | beta | ANTLR 4 |
Expand Down
Loading

0 comments on commit 1646516

Please sign in to comment.