Update auto-update-app-headers.yml

This commit is contained in:
CanbiZ 2025-01-14 14:48:47 +01:00 committed by GitHub
parent 8c54d25bf5
commit 910e767bb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,59 +6,52 @@ on:
- main - main
paths: paths:
- 'ct/**.sh' - 'ct/**.sh'
workflow_dispatch: workflow_dispatch: # Ermöglicht das manuelle Ausführen der Action
jobs: jobs:
auto-update: update-app-headers:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# Step 1: Checkout repository # Step 1: Checkout the repository
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
# Step 2: Set up Git user # Step 2: Set up Git user for committing changes
- name: Set up Git - name: Set up Git
run: | run: |
git config --global user.name "GitHub Actions" git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com" git config --global user.email "actions@github.com"
# Step 3: Reset update-app-headers to main # Step 3: Create a new branch from main
- name: Reset update-app-headers branch to main - name: Create a new branch based on main
run: | run: |
git checkout -B update-app-headers origin/main git fetch origin
echo "Branch update-app-headers reset to match main" git checkout main
git pull origin main
BRANCH_NAME="update-app-headers-$(date +'%Y-%m-%d-%H-%M-%S')"
git checkout -b "$BRANCH_NAME"
echo "Created and switched to branch $BRANCH_NAME"
# Step 4: Ensure .app-headers file exists # Step 4: Run the generate-app-headers.sh script to update .app-headers
- name: Ensure .app-headers file exists - name: Run generate-app-headers.sh to update .app-headers
run: | run: |
touch ct/.app-headers chmod +x .github/workflows/generate-app-headers.sh
.github/workflows/generate-app-headers.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Step 5: Update .app-headers with figlet output # Step 5: Push changes to the new branch
- name: Update .app-headers - name: Push changes to the new branch
run: | run: |
output_file="./ct/.app-headers" git add ./misc/.app-headers
> "$output_file" # Clear or create the file git commit -m "Update .app-headers file"
git push origin "$BRANCH_NAME"
current_date=$(date +"%m-%d-%Y") # Step 6: Delete the created branch locally and remotely after push
echo "### Generated on $current_date" >> "$output_file" - name: Delete the branch after push
echo "##################################################" >> "$output_file"
echo >> "$output_file"
find ./ct -type f -name "*.sh" | sort | while read -r script; do
app_name=$(grep -oP '^APP="\K[^"]+' "$script" 2>/dev/null)
if [[ -n "$app_name" ]]; then
figlet_output=$(figlet -f slant "$app_name" 2>/dev/null || echo "FIGLET ERROR: $app_name")
echo "### $(basename "$script")" >> "$output_file"
echo "APP=$app_name" >> "$output_file"
echo "$figlet_output" >> "$output_file"
echo >> "$output_file"
fi
done
# Step 6: Commit and push changes
- name: Commit and push changes
run: | run: |
git add ct/.app-headers git push origin --delete "$BRANCH_NAME" # Delete remote branch
git commit -m "Update .app-headers on $(date +"%Y-%m-%d")" || echo "No changes to commit" git checkout main
git push --force origin update-app-headers git branch -D "$BRANCH_NAME" # Delete local branch
echo "Branch $BRANCH_NAME deleted."