Add nvidia-optimus plugin #982
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Automatic Manifest Check | |
| on: | |
| pull_request_target: | |
| types: | |
| - opened | |
| - synchronize | |
| - reopened | |
| paths: | |
| - "**/manifest.json" | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| manifest-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Automatic Manifest Check | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| BASE_REF: ${{ github.base_ref }} | |
| HEAD_REF: ${{ github.head_ref }} | |
| run: | | |
| git fetch origin "$BASE_REF" | |
| diff_changes=$(git diff -U10000 origin/$BASE_REF...HEAD | | |
| awk '/^diff --git.*manifest\.json /{found=1} /^diff --git/{if(!/\.json /) found=0} found{print}' | | |
| grep -vE "^(index|\+\+\+|-)") || echo "No manifest.json file changed" | |
| if [ -z "$diff_changes" ]; then | |
| echo "No diff changes found!" | |
| echo "The base ref checking: $BASE_REF" | |
| echo "The head ref checking: $HEAD_REF" | |
| exit 0 | |
| fi | |
| comment_body=$(printf -- '### Automatic Manifest Check') | |
| issues=0 | |
| line_index=0 | |
| l_priority="[(L)]($PR_NUMBER 'Low priority, it is okay for this to remain unfixed before merging')" | |
| h_priority="[(H)]($PR_NUMBER 'High priority, this needs to be fixed for the PR to be merged')" | |
| function print_line() { | |
| check_file_title | |
| local priority=$1 | |
| local index=$2 | |
| local comment=$3 | |
| local code_line=$4 | |
| comment_body+=$(printf -- '\n- %s Line %d: %s\n```json\n%s\n```' "$priority" "$index" "$comment" "$code_line") | |
| } | |
| function print_missing_property() { | |
| check_file_title | |
| local priority=$1 | |
| local property=$2 | |
| local code_line=$3 | |
| comment_body+=$(printf -- '\n- %s Missing required property `%s`. For example:\n```json\n%s\n```' "$priority" "$property" "$code_line") | |
| } | |
| title_added=false | |
| file_title="" | |
| function check_file_title() { | |
| if [ "$title_added" = false ]; then | |
| title_added=true | |
| comment_body+="$file_title" | |
| fi | |
| } | |
| # Required Properties in Components | |
| inManifest=false | |
| hasId=false | |
| hasName=false | |
| hasVersion=false | |
| hasAuthor=false | |
| hasDescription=false | |
| hasRepository=false | |
| function reset_required_properties() { | |
| inManifest=false | |
| hasId=false | |
| hasName=false | |
| hasVersion=false | |
| hasAuthor=false | |
| hasDescription=false | |
| hasRepository=false | |
| } | |
| function print_required_properties() { | |
| if [ "$inManifest" = true ]; then | |
| if [ "$hasId" = false ]; then | |
| print_missing_property "$h_priority" 'id' '"id": "my-plugin"' | |
| issues=$((issues + 1)) | |
| fi | |
| if [ "$hasName" = false ]; then | |
| print_missing_property "$h_priority" 'name' '"name": "My Awesome Plugin"' | |
| issues=$((issues + 1)) | |
| fi | |
| if [ "$hasVersion" = false ]; then | |
| print_missing_property "$h_priority" 'version' '"version": "1.2.3"' | |
| issues=$((issues + 1)) | |
| fi | |
| if [ "$hasAuthor" = false ]; then | |
| print_missing_property "$h_priority" 'author' '"author": "John Doe"' | |
| issues=$((issues + 1)) | |
| fi | |
| if [ "$hasDescription" = false ]; then | |
| print_missing_property "$h_priority" 'description' '"description": "A very awesome plugin that does this and that!"' | |
| issues=$((issues + 1)) | |
| fi | |
| if [ "$hasRepository" = false ]; then | |
| print_missing_property "$h_priority" 'repository' '"repository": "https://github.com/noctalia-dev/noctalia-plugins"' | |
| issues=$((issues + 1)) | |
| fi | |
| fi | |
| } | |
| while IFS= read -r line; do | |
| if echo "$line" | grep -E "^diff --git" >/dev/null; then | |
| print_required_properties | |
| reset_required_properties | |
| title_added=false | |
| file_title=$(printf -- '\n---\n### File: %s' "$(echo "$line" | sed 's/diff --git a\/\(.*\) .*/\1/g')") | |
| echo "Checking file: $file_title" | |
| if [[ "$file_title" == *manifest.json ]]; then | |
| inManifest=true | |
| fi | |
| elif echo "$line" | grep -E "^@@" >/dev/null; then | |
| line_index=$(echo "$line" | grep -oE "\+[0-9]+" | grep -oE "[0-9]+") | |
| echo "Current line index reset: $line_index" | |
| else | |
| if echo "$line" | grep '"official": false' >/dev/null; then | |
| print_line "$h_priority" "$line_index" "Do not add the 'official' property. It's automatically false and is NOT needed!" "$line" | |
| issues=$((issues + 1)) | |
| fi | |
| if echo "$line" | grep -oE '"repository": ".*"' | grep -v '"repository": "https://github.com/noctalia-dev/noctalia-plugins"' >/dev/null; then | |
| print_line "$h_priority" "$line_index" 'The repository field needs to point to the "https://github.com/noctalia-dev/noctalia-plugins" github repository!' "$line" | |
| issues=$((issues + 1)) | |
| fi | |
| # Check for required properties | |
| if echo "$line" | grep '"id":' >/dev/null; then | |
| hasId=true | |
| if echo "$line" | grep -vE '"id": "[a-zA-Z\-]+"'; then | |
| print_line "$h_priority" "$line_index" 'The id can only contain small characters [a-z], numbers [0-9] and dashes [-]' "$line" | |
| fi | |
| fi | |
| if echo "$line" | grep '"name":' >/dev/null; then | |
| hasName=true | |
| fi | |
| if echo "$line" | grep '"version":' >/dev/null; then | |
| hasVersion=true | |
| fi | |
| if echo "$line" | grep '"author":' >/dev/null; then | |
| hasAuthor=true | |
| fi | |
| if echo "$line" | grep '"description":' >/dev/null; then | |
| hasDescription=true | |
| fi | |
| if echo "$line" | grep '"repository":' >/dev/null; then | |
| hasRepository=true | |
| fi | |
| line_index=$((line_index + 1)) | |
| fi | |
| done <<<"$diff_changes" | |
| # Print any required properties not printed on a new file found. | |
| print_required_properties | |
| if [[ "$issues" -ne 0 ]]; then | |
| gh pr comment "$PR_NUMBER" --body "$comment_body" | |
| fi |