name: Update .app-headers in /misc on: push: paths: - 'ct/*' # Action wird ausgelöst, wenn sich etwas in ct/ ändert branches: - main workflow_dispatch: jobs: update-and-create-pr: runs-on: ubuntu-latest permissions: contents: write pull-requests: write steps: # Step 1: Checkout repository - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 # Ensure we have full access to all branches # Step 2: Configure git user - name: Configure Git user run: | git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" # Step 3: Merge main into update-app-headers - name: Merge main into update-app-headers run: | git fetch origin git checkout update-app-headers || git checkout -b update-app-headers git merge origin/main --no-ff --no-edit git push origin update-app-headers --force # Step 4: Ensure .app-headers file exists and initialize it - name: Initialize .app-headers file run: | if [ ! -f "ct/.app-headers" ]; then echo "Creating .app-headers file" touch ct/.app-headers fi # Step 5: Loop through ct/ scripts and execute figlet if APP= is found - name: Update .app-headers with figlet output run: | echo "Updating .app-headers with figlet output." for file in ct/*.sh; do if grep -q "APP=" "$file"; then APP_NAME=$(grep -oP 'APP=\K.*' "$file") echo "Processing $file for APP: $APP_NAME" figlet "$APP_NAME" >> ct/.app-headers fi done # Step 6: Commit the changes to .app-headers - name: Commit updated .app-headers run: | git diff --quiet -- ct/.app-headers || git commit -am "[core]: update .app-headers to latest version" git push origin update-app-headers --force # Step 7: Create Pull Request to merge changes into main - name: Create Pull Request if changes detected env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | PR_EXISTS=$(gh pr list --head "update-app-headers" --json number --jq '.[].number') if [ -z "$PR_EXISTS" ]; then echo "Creating a new PR." PR_URL=$(gh pr create --title "[core]: update .app-headers to latest version" \ --body "This PR automatically updates the .app-headers file." \ --head update-app-headers \ --base main --no-edit -q .url) echo "PR created: $PR_URL" else echo "PR already exists." fi # Step 8: Automatically merge PR - name: Automatically merge PR env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo "Attempting to merge PR." PR_NUMBER=$(gh pr list --head "update-app-headers" --json number --jq '.[].number') if [ -n "$PR_NUMBER" ]; then gh pr merge "$PR_NUMBER" --merge --admin --delete-branch echo "PR merged successfully." else echo "No PR found to merge." fi # Step 9: Final status output - name: Output final status run: | echo "Workflow completed successfully. Branch and PR status updated."