From f29cbe5b46297577930c9f1cda60d992dac40866 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:03:59 +0100 Subject: [PATCH] [Core] Better Creation of App Headers for next feature (#1719) * Update Function to crawl app Headers * Update Function to crawl app Headers --- .github/workflows/auto-update-app-headers.yml | 32 +++++++--------- .../workflows/scripts/generate-app-headers.sh | 37 ++++++++----------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/.github/workflows/auto-update-app-headers.yml b/.github/workflows/auto-update-app-headers.yml index b02c3e61..15f7ee04 100644 --- a/.github/workflows/auto-update-app-headers.yml +++ b/.github/workflows/auto-update-app-headers.yml @@ -1,4 +1,4 @@ -name: Auto Update .app-headers +name: Auto Update .app-files on: push: @@ -9,7 +9,7 @@ on: workflow_dispatch: # Ermöglicht das manuelle Ausführen der Action jobs: - update-app-headers: + update-app-files: runs-on: ubuntu-latest permissions: @@ -31,15 +31,15 @@ jobs: - name: Install figlet run: sudo apt-get install -y figlet - # Step 4: Run the generate-app-headers.sh script to update .app-headers - - name: Run generate-app-headers.sh to update .app-headers + # Step 4: Run the updated generate-app-files.sh script + - name: Run generate-app-files.sh run: | chmod +x .github/workflows/scripts/generate-app-headers.sh .github/workflows/scripts/generate-app-headers.sh env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Step 5: Check if there are any changes + # Step 5: Check for changes - name: Check if there are any changes id: verify-diff run: | @@ -51,16 +51,15 @@ jobs: run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - git add ./misc/.app-headers - git commit -m "Update .app-headers file" - # Create a temporary branch for the PR - git checkout -b pr-update-app-headers - git push origin pr-update-app-headers --force - + git add ct/*.app + git commit -m "Update .app files" + git checkout -b pr-update-app-files + git push origin pr-update-app-files --force + # Create PR against main - gh pr create --title "[core] update .app-headers file" \ - --body "This PR is auto-generated by a Github Action to update the .app-headers file." \ - --head pr-update-app-headers \ + gh pr create --title "[core] update .app files" \ + --body "This PR is auto-generated by a Github Action to update the .app files." \ + --head pr-update-app-files \ --base main \ --label "automated pr" env: @@ -71,12 +70,9 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - PR_NUMBER=$(gh pr list --head "pr-update-app-headers" --json number --jq '.[].number') - # Check if the PR was created by the bot (skip review if so) + PR_NUMBER=$(gh pr list --head "pr-update-app-files" --json number --jq '.[].number') PR_AUTHOR=$(gh pr view "$PR_NUMBER" --json author --jq '.author.login') if [ "$PR_AUTHOR" != "github-actions[bot]" ]; then gh pr review "$PR_NUMBER" --approve else echo "PR was created by the bot, skipping review." - fi - diff --git a/.github/workflows/scripts/generate-app-headers.sh b/.github/workflows/scripts/generate-app-headers.sh index c548b0fc..4d92951f 100644 --- a/.github/workflows/scripts/generate-app-headers.sh +++ b/.github/workflows/scripts/generate-app-headers.sh @@ -1,33 +1,28 @@ #!/usr/bin/env bash -output_file="./misc/.app-headers" -> "$output_file" # Clear or create the file - -current_date=$(date +"%m-%d-%Y") -# Header with date -{ - echo "### Generated on $current_date" - echo "##################################################" - echo -} >> "$output_file" - -# Find only regular .sh files in ./ct, sort them alphabetically +# Find all .sh files in ./ct directory, sorted alphabetically find ./ct -type f -name "*.sh" | sort | while read -r script; do # Extract the APP name from the APP line app_name=$(grep -oP '^APP="\K[^"]+' "$script" 2>/dev/null) if [[ -n "$app_name" ]]; then - # Generate figlet output - figlet_output=$(figlet -f slant "$app_name") - { - echo "### $(basename "$script")" - echo "APP=$app_name" - echo "$figlet_output" - echo - } >> "$output_file" + # Define the output file name based on the .sh file + output_file="${script%.sh}.app" + + # Check if the output file already exists + if [[ ! -f "$output_file" ]]; then + # Generate figlet output + figlet_output=$(figlet -f slant "$app_name") + + # Write the figlet output to the file + echo "$figlet_output" > "$output_file" + echo "Generated: $output_file" + else + echo "Skipped: $output_file already exists" + fi else echo "No APP name found in $script, skipping." fi done -echo "Generated combined file at $output_file" +echo "Completed processing .sh files."