Skip to content

Commit

Permalink
Merge branch 'refs/heads/beta' into fork/catgirlseraid/farming-stuff
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt
  • Loading branch information
CalMWolfs committed Nov 12, 2024
2 parents e79aa5b + 2049030 commit cbba35f
Show file tree
Hide file tree
Showing 534 changed files with 9,620 additions and 5,510 deletions.
39 changes: 39 additions & 0 deletions .github/scripts/process_detekt_output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = require('fs');
const path = require('path');

const PR_SHA = process.env.PR_SHA;
const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;

// Read detekt_output.txt
const detektOutput = fs.readFileSync('detekt_output.txt', 'utf8');

let comment = '### One or more Detekt Failures were detected:\n\n';

const lines = detektOutput.split('\n');
lines.forEach((line) => {
if (!line.trim()) return; // Skip empty lines

// Extract file path and line number
const filePathMatch = line.match(/file=([^,]+)/);
const lineNumberMatch = line.match(/line=(\d+)/);
if (!filePathMatch || !lineNumberMatch) return;

const filePath = filePathMatch[1];
const lineNumber = lineNumberMatch[1];

// Remove everything before 'src/' in the file path (if it exists)
const srcIndex = filePath.indexOf('src/');
const cleanedFilePath = srcIndex !== -1 ? filePath.substring(srcIndex) : filePath;

// Extract file name
const fileName = path.basename(cleanedFilePath);

// Clean up the line to remove everything between '::' and '::' (inclusive)
const cleanMessage = line.replace(/::.*?::/g, '');

// Append to comment
comment += `- [${fileName}#L${lineNumber}](https://github.com/${GITHUB_REPOSITORY}/blob/${PR_SHA}/${cleanedFilePath}#L${lineNumber}): ${cleanMessage}\n`;
});

// Write comment to file
fs.writeFileSync('detekt_comment.txt', comment);
9 changes: 5 additions & 4 deletions .github/scripts/process_detekt_sarif.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# This script processes the Detekt SARIF file and outputs results in a format
# suitable for annotation in CI/CD systems.
# suitable for annotation in CI/CD systems, with the file paths fixed.

SARIF_FILE="$1"

Expand All @@ -11,11 +11,12 @@ if [ ! -f "$SARIF_FILE" ]; then
exit 1
fi

# Define jq command to parse SARIF file
# Define jq command to parse SARIF file and fix the file path
read -r -d '' jq_command <<'EOF'
.runs[].results[] |
{
"full_path": .locations[].physicalLocation.artifactLocation.uri | sub("file://$(pwd)/"; ""),
# Adjust the path to remove the runner workspace prefix
"full_path": (.locations[].physicalLocation.artifactLocation.uri | sub("file://.*/SkyHanni/"; "")),
"file_name": (.locations[].physicalLocation.artifactLocation.uri | split("/") | last),
"l": .locations[].physicalLocation,
"level": .level,
Expand All @@ -29,7 +30,7 @@ read -r -d '' jq_command <<'EOF'
",title=" + (.ruleId) +
",col=" + (.l.region.startColumn|tostring) +
",endColumn=" + (.l.region.endColumn|tostring) +
"::" + (.message.text)
"::" + (.message)
)
EOF

Expand Down
20 changes: 1 addition & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,6 @@ jobs:
with:
name: "Test Results"
path: versions/1.8.9/build/reports/tests/test/
#detekt:
# name: Run detekt
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - uses: ./.github/actions/setup-normal-workspace
# # detektMain is a LOT slower than detekt, but it does type analysis
# - name: Run detekt main (w/typing analysis)
# run: |
# ./gradlew detektMain --stacktrace
# - name: Annotate detekt failures
# if: ${{ !cancelled() }}
# run: |
# chmod +x .github/scripts/process_detekt_sarif.sh
# ./.github/scripts/process_detekt_sarif.sh versions/1.8.9/build/reports/detekt/main.sarif


preprocess:
runs-on: ubuntu-latest
Expand All @@ -67,4 +49,4 @@ jobs:
mkdir -p .gradle
echo skyhanni.multi-version=preprocess-only > .gradle/private.properties
- name: Build with Gradle
run: ./gradlew build --stacktrace
run: ./gradlew build --stacktrace -PskipDetekt=true
124 changes: 124 additions & 0 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Detekt

on:
pull_request_target:
branches:
- "*"
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
detekt:
name: Run detekt
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
outputs:
sarif_exists: ${{ steps.check_sarif.outputs.exists }}
steps:
- name: Checkout PR code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- uses: ./.github/actions/setup-normal-workspace
- name: Run detekt main (w/ typing analysis)
run: |
./gradlew detektMain --stacktrace
- name: Check if SARIF file exists
if: always()
id: check_sarif
run: |
if [ -f "versions/1.8.9/build/reports/detekt/main.sarif" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Add label if detekt fails
if: failure()
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'Detekt'
- name: Remove label if detekt passes
if: success()
uses: actions-ecosystem/action-remove-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'Detekt'

- name: Annotate detekt failures
if: ${{ !cancelled() && steps.check_sarif.outputs.exists == 'true' }}
run: |
chmod +x .github/scripts/process_detekt_sarif.sh
./.github/scripts/process_detekt_sarif.sh versions/1.8.9/build/reports/detekt/main.sarif | tee detekt_output.txt
- name: Upload detekt output as artifact
if: ${{ !cancelled() && steps.check_sarif.outputs.exists == 'true' }}
uses: actions/upload-artifact@v4
with:
name: detekt-output
path: detekt_output.txt

detekt_comment:
name: Comment detekt failures on PR
runs-on: ubuntu-latest
needs: detekt
if: ${{ needs.detekt.outputs.sarif_exists == 'true' && failure() }}
permissions:
pull-requests: write
steps:
- name: Checkout base repo code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Download detekt output
uses: actions/download-artifact@v4
with:
name: detekt-output
path: .
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '>=21'
- name: Process detekt output and create comment
env:
PR_SHA: ${{ github.event.pull_request.head.sha }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
node .github/scripts/process_detekt_output.js
- name: Check if this is the latest workflow run
id: check_latest
run: |
PR_LATEST_SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r '.head.sha')
echo "Latest commit SHA from PR: $PR_LATEST_SHA"
echo "Current workflow SHA: ${{ github.event.pull_request.head.sha }}"
# Compare the SHAs and set a result variable
if [[ "${PR_LATEST_SHA}" == "${{ github.event.pull_request.head.sha }}" ]]; then
echo "is_latest=true" >> $GITHUB_ENV
else
echo "is_latest=false" >> $GITHUB_ENV
fi
- name: Add comment to PR
if: env.is_latest == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const commentBody = fs.readFileSync('detekt_comment.txt', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
34 changes: 34 additions & 0 deletions .github/workflows/detekt_beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Run detekt on push

on:
push:
branches:
- "beta"
paths-ignore:
- ".gitignore"
jobs:
detekt:
name: Run detekt
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout PR code
uses: actions/checkout@v4
- uses: ./.github/actions/setup-normal-workspace
- name: Run detekt main (w/ typing analysis)
run: |
./gradlew detektMain --stacktrace
- name: Check if SARIF file exists
id: check_sarif
run: |
if [ -f "versions/1.8.9/build/reports/detekt/main.sarif" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Annotate detekt failures
if: ${{ !cancelled() && steps.check_sarif.outputs.exists == 'true' }}
run: |
chmod +x .github/scripts/process_detekt_sarif.sh
./.github/scripts/process_detekt_sarif.sh versions/1.8.9/build/reports/detekt/main.sarif
35 changes: 28 additions & 7 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ name: "PR Changelog Verification"

on:
pull_request_target:
types: [ opened, edited ]
types: [ opened, edited, ready_for_review ]

jobs:
verify-changelog:
if: github.event.pull_request.state == 'open' && '511310721' == github.repository_id
if: github.event.pull_request.state == 'open' && '511310721' == github.repository_id && github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- uses: ./.github/actions/setup-normal-workspace

Expand Down Expand Up @@ -39,8 +42,26 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'Wrong Title/Changelog'

- name: Add comment to PR if changelog verification fails
- name: Check if this is the latest workflow run
if: failure()
id: check_latest
run: |
PR_LATEST_SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r '.head.sha')
echo "Latest commit SHA from PR: $PR_LATEST_SHA"
echo "Current workflow SHA: ${{ github.event.pull_request.head.sha }}"
# Compare the SHAs and set a result variable
if [[ "${PR_LATEST_SHA}" == "${{ github.event.pull_request.head.sha }}" ]]; then
echo "is_latest=true" >> $GITHUB_ENV
else
echo "is_latest=false" >> $GITHUB_ENV
fi
- name: Add comment to PR if changelog verification fails
if: ${{ failure() && env.is_latest == 'true' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -50,8 +71,8 @@ jobs:
const commentBody = `${test}`
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
5 changes: 5 additions & 0 deletions .idea/dictionaries/default_user.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cbba35f

Please sign in to comment.