1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-02-02 08:31:51 +00:00
ProxmoxVE/.github/workflows/generate-app-headers.yaml

100 lines
3.4 KiB
YAML
Raw Normal View History

name: Update .app-headers in /misc
on:
2025-01-10 14:28:50 +01:00
push:
paths:
- 'ct/*' # Action wird ausgelöst, wenn sich etwas in ct/ ändert
2025-01-10 13:44:13 +01:00
branches:
- main
workflow_dispatch:
jobs:
2025-01-10 13:02:36 +01:00
update-and-create-pr:
runs-on: ubuntu-latest
permissions:
2025-01-10 12:04:38 +01:00
contents: write
pull-requests: write
steps:
2025-01-10 13:02:36 +01:00
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
with:
2025-01-10 14:28:50 +01:00
fetch-depth: 0 # Ensure we have full access to all branches
2025-01-10 14:30:04 +01:00
# 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
2025-01-10 13:42:55 +01:00
- name: Merge main into update-app-headers
run: |
2025-01-10 14:28:50 +01:00
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
2025-01-10 13:42:55 +01:00
2025-01-10 14:30:04 +01:00
# Step 4: Ensure .app-headers file exists and initialize it
2025-01-10 14:28:50 +01:00
- name: Initialize .app-headers file
2025-01-10 12:19:11 +01:00
run: |
2025-01-10 14:28:50 +01:00
if [ ! -f "ct/.app-headers" ]; then
echo "Creating .app-headers file"
touch ct/.app-headers
2025-01-10 14:15:22 +01:00
fi
2025-01-10 14:30:04 +01:00
# Step 5: Loop through ct/ scripts and execute figlet if APP= is found
2025-01-10 14:28:50 +01:00
- name: Update .app-headers with figlet output
2025-01-10 14:15:22 +01:00
run: |
2025-01-10 14:28:50 +01:00
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
2025-01-10 14:15:22 +01:00
done
2025-01-10 14:28:50 +01:00
2025-01-10 14:30:04 +01:00
# Step 6: Commit the changes to .app-headers
2025-01-10 14:28:50 +01:00
- name: Commit updated .app-headers
2025-01-10 13:06:06 +01:00
run: |
2025-01-10 14:28:50 +01:00
git diff --quiet -- ct/.app-headers || git commit -am "[core]: update .app-headers to latest version"
git push origin update-app-headers --force
2025-01-10 13:00:27 +01:00
2025-01-10 14:30:04 +01:00
# Step 7: Create Pull Request to merge changes into main
2025-01-10 13:02:36 +01:00
- name: Create Pull Request if changes detected
2025-01-10 13:03:26 +01:00
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2025-01-10 12:04:38 +01:00
run: |
2025-01-10 13:45:36 +01:00
PR_EXISTS=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
2025-01-10 12:04:38 +01:00
if [ -z "$PR_EXISTS" ]; then
2025-01-10 12:49:58 +01:00
echo "Creating a new PR."
2025-01-10 13:45:36 +01:00
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 \
2025-01-10 14:28:50 +01:00
--base main --no-edit -q .url)
2025-01-10 13:45:36 +01:00
echo "PR created: $PR_URL"
2025-01-10 12:21:27 +01:00
else
2025-01-10 12:49:58 +01:00
echo "PR already exists."
2025-01-10 12:04:38 +01:00
fi
2025-01-10 14:30:04 +01:00
# Step 8: Automatically merge PR
2025-01-10 13:09:46 +01:00
- name: Automatically merge PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Attempting to merge PR."
2025-01-10 13:45:36 +01:00
PR_NUMBER=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
2025-01-10 13:09:46 +01:00
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
2025-01-10 13:46:37 +01:00
2025-01-10 14:30:04 +01:00
# Step 9: Final status output
2025-01-10 12:49:58 +01:00
- name: Output final status
run: |
echo "Workflow completed successfully. Branch and PR status updated."