Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anirud/lc GitHub actions #44

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9111a8a
Anirud/front end UI changes (#21)
anirudTT Aug 13, 2024
e42099e
Anirud/license headers (#25)
anirudTT Sep 10, 2024
d64e9c3
add lc header github actions checker
anirudTT Sep 15, 2024
f3a2072
also run github actions on staging branch
anirudTT Sep 15, 2024
c2c709b
move into workflows folder
anirudTT Sep 16, 2024
f75b44a
remove and check github actions
anirudTT Sep 17, 2024
c763a8a
move check_copyright_config file location
anirudTT Sep 17, 2024
d37607c
try recursive pattern
anirudTT Sep 17, 2024
7045ac3
remove lc header on docker utils
anirudTT Sep 17, 2024
f149356
add more file types to check
anirudTT Sep 17, 2024
e313ba1
re try the file types
anirudTT Sep 17, 2024
bdb747c
re try recursive pattern
anirudTT Sep 17, 2024
f10142a
try again
anirudTT Sep 17, 2024
14c5b75
test react project github actions
anirudTT Sep 18, 2024
f9e9a46
run on staging PR also
anirudTT Sep 18, 2024
8c601d3
adjust working directory
anirudTT Sep 18, 2024
a887cce
try and fix wrk diretcory
anirudTT Sep 18, 2024
432a8cc
remove duplicated path
anirudTT Sep 18, 2024
7f056c8
do not exit prematurely if errors or warnings are found
anirudTT Sep 18, 2024
4907dbd
try again
anirudTT Sep 18, 2024
3b5f469
try again
anirudTT Sep 18, 2024
bad2f31
updated the workflow:
anirudTT Sep 18, 2024
0c314ae
show file name
anirudTT Sep 18, 2024
82e600e
add missing }
anirudTT Sep 18, 2024
a45ff51
remove links to the file
anirudTT Sep 18, 2024
c6f4f3d
fix syntax errors
anirudTT Sep 18, 2024
f701ba8
more fixes
anirudTT Sep 18, 2024
f9b5a22
more fixes
anirudTT Sep 18, 2024
8029bfc
more better pr comments
anirudTT Sep 18, 2024
fc84ce4
more fixes
anirudTT Sep 18, 2024
a62bff7
avoid same file
anirudTT Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .github/workflows/license-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Check SPDX Licenses

on:
workflow_dispatch:
workflow_call:
pull_request:
branches:
- "main"
- "staging"
types:
- opened
- reopened
- synchronize
- assigned
- review_requested

jobs:
check-spdx-licenses:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
cache: "pip"
python-version: "3.8"
- name: Install copyright check tool
run: pip install git+https://github.com/espressif/check-copyright.git@master
- name: Check SPDX licenses
id: check_spdx_licenses
run: |
set +e
output=$(python -m check_copyright --verbose --dry-run --config ./check_copyright_config.yaml . 2>&1)
exit_code=$?
clean_output=$(echo "$output" | sed 's/\x1b\[[0-9;]*m//g')
echo "CLEAN_OUTPUT<<EOF" >> $GITHUB_ENV
echo "$clean_output" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV
exit 0
- name: Debug Extracted Files
run: |
echo "Extracted Files:"
echo "$CLEAN_OUTPUT"
- name: Extract Files
id: extract_files
run: |
set +e
files=$(echo "$CLEAN_OUTPUT" | awk '
/Files which failed the copyright check:/, /Additional information about this hook and copyright headers may be found here:/ {
if ($0 !~ /Files which failed the copyright check:/ && $0 !~ /Additional information about this hook and copyright headers may be found here:/) print
}
/Some files are without a copyright note and a license header needs to be added:/, /Additional information about this hook and copyright headers may be found here:/ {
if ($0 !~ /Some files are without a copyright note and a license header needs to be added:/ && $0 !~ /Additional information about this hook and copyright headers may be found here:/) print
}' | sed 's/^ *//' | sed '/^$/d' | grep '^.')
echo "FILES<<EOF" >> $GITHUB_ENV
echo "$files" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "Extracted Files: $files"
exit 0
- name: Debug Extracted Files
run: |
echo "Extracted Files:"
echo "$FILES"
- name: Extract File Paths
if: env.FILES != ''
run: |
# Extract lines starting with './' but ignore any paths following "Modified files:" until a stop marker
files_clean=$(echo "$FILES" | awk '/^Modified files:/ {ignore = 1} /^Above is a list of files/ {ignore = 0} !ignore && /^\.\// {print}' | sort | uniq)
# Save the cleaned files into a new environment variable 'FILES_CLEAN'
echo "FILES_CLEAN<<EOF" >> $GITHUB_ENV
echo "$files_clean" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "Extracted Paths: $files_clean"
- name: Debug Extracted Paths
run: |
echo "Extracted Paths:"
echo "$FILES_CLEAN"
echo "---------------------------------"
- name: Comment on PR or Issue
if: env.FILES_CLEAN != ''
uses: actions/github-script@v7
with:
script: |
const formattedOutput = process.env.FILES_CLEAN;
const issueNumber = context.issue.number || context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
if (formattedOutput) {
const commentBody = `Our automated SPDX license verification process has discovered that the following files are missing a license header:\n\`\`\`\n${formattedOutput}\n\`\`\`\nPlease ensure each indicated file includes a valid SPDX license identifier. This is essential for maintaining licensing compliance. Your attention and cooperation in updating these files are greatly appreciated. Thank you.`;
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: owner,
repo: repo,
body: commentBody
});
core.setFailed("SPDX license issues found.");
} else {
console.log("No SPDX license issues found.");
}
113 changes: 113 additions & 0 deletions .github/workflows/lint-and-license-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Lint and License Check

on:
push:
branches:
- main
pull_request:
branches:
- "main"
- "staging"
types:
- opened
- reopened
- synchronize
- assigned
- review_requested

jobs:
lint:
runs-on: ubuntu-latest

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

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies
working-directory: app/frontend # Adjust path according to your repo structure
run: npm install

- name: Run ESLint and Capture Output
working-directory: app/frontend
id: run_eslint
run: |
set +e
output=$(npm run lint --silent 2>&1)
exit_code=$?
echo "$output"
clean_output=$(echo "$output" | sed 's/\x1b\[[0-9;]*m//g') # Remove ANSI escape codes
echo "CLEAN_OUTPUT<<EOF" >> $GITHUB_ENV
echo "$clean_output" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

# Process output to group errors under file paths with separators
grouped_errors=""
current_file=""
errors_for_file=""
has_errors=false

while IFS= read -r line; do
if echo "$line" | grep -q '^\s*\/'; then
# Detected a file path line, add to grouped_errors if it contains errors
if [ "$has_errors" = true ]; then
grouped_errors+="$current_file\n$errors_for_file\n---\n"
errors_for_file="" # Reset error collection for next file
has_errors=false # Reset error flag for the next file
fi
current_file="$line"
elif echo "$line" | grep -q 'error'; then
# Detected an error line, associate with the current file
errors_for_file+=" $line\n"
has_errors=true # Mark that this file has errors
fi
done <<< "$clean_output"

# Add any remaining errors after the loop
if [ "$has_errors" = true ]; then
grouped_errors+="$current_file\n$errors_for_file\n"
fi

# Store grouped errors in environment variable
if [ -n "$grouped_errors" ]; then
echo "Errors found."
echo "GROUPED_ERRORS<<EOF" >> $GITHUB_ENV
echo -e "$grouped_errors" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "HAS_ERRORS=true" >> $GITHUB_ENV
else
echo "No relevant errors found."
echo "HAS_ERRORS=false" >> $GITHUB_ENV
fi

exit 0 # Always exit with 0 to avoid failing the step

- name: Comment on PR with ESLint Errors
if: env.HAS_ERRORS == 'true'
uses: actions/github-script@v7
with:
script: |
const lintErrors = process.env.GROUPED_ERRORS;
const issueNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;

if (lintErrors && issueNumber) {
const commentBody = `## Frontend Project: ESLint Errors\n\`\`\`\n${lintErrors}\n\`\`\`\nPlease review and resolve the ESLint errors.`;
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: owner,
repo: repo,
body: commentBody
});
} else {
console.log("No relevant errors to report.");
}

- name: Fail if Errors Exist
if: env.HAS_ERRORS == 'true'
run: exit 1 # Fail the workflow if errors exist
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ db.sqlite3

# unignore
!requirements.txt
!app/frontend/third-party-licenses.txt
Loading
Loading