ProxmoxVE/.github/workflows/generate-app-headers.yaml

145 lines
5.1 KiB
YAML
Raw Normal View History

name: Update .app-headers in /misc
on:
2025-01-10 12:44:13 +00:00
pull_request:
types:
- closed
branches:
- main
2025-01-10 12:46:37 +00:00
# Trigger nur, wenn der PR gemerged wurde
2025-01-10 12:44:13 +00:00
if: github.event.pull_request.merged == true
schedule:
- cron: "59 23 * * *" # Führen den Workflow täglich um 23:59 UTC aus
workflow_dispatch:
jobs:
2025-01-10 12:02:36 +00:00
update-and-create-pr:
runs-on: ubuntu-latest
permissions:
2025-01-10 11:04:38 +00:00
contents: write
pull-requests: write
steps:
2025-01-10 12:02:36 +00:00
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
with:
2025-01-10 12:42:55 +00:00
fetch-depth: 0 # Fetch all branches for full context
2025-01-10 12:42:55 +00:00
# Step 2: Set up Git user
- name: Configure Git user
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
# Step 3: Check or create update-app-headers branch
- name: Check or create update-app-headers branch
run: |
2025-01-10 11:04:38 +00:00
git fetch origin
2025-01-10 12:42:55 +00:00
if git show-ref --quiet refs/heads/update-app-headers; then
2025-01-10 12:02:36 +00:00
echo "Switching to 'update-app-headers' branch."
2025-01-10 11:44:25 +00:00
git checkout update-app-headers
2025-01-10 12:42:55 +00:00
else
echo "Creating 'update-app-headers' branch."
git checkout -b update-app-headers origin/main
2025-01-10 11:44:25 +00:00
fi
2025-01-10 11:04:38 +00:00
2025-01-10 12:42:55 +00:00
# Step 4: Merge main into update-app-headers
- name: Merge main into update-app-headers
run: |
git merge origin/main --no-edit || echo "No changes to merge from main."
2025-01-10 13:15:22 +00:00
# Step 5: Identify changes in .sh files
- name: Check for .sh files and extract app names
id: detect_sh_files
2025-01-10 11:19:11 +00:00
run: |
2025-01-10 13:15:22 +00:00
# Get the list of changed files in the PR
CHANGED_FILES=$(git diff --name-only HEAD origin/main)
# Find .sh files and extract app names
CHANGED_SH_FILES=$(echo "$CHANGED_FILES" | grep '\.sh$')
if [ -z "$CHANGED_SH_FILES" ]; then
echo "No .sh files changed."
exit 0
else
echo "Changed .sh files detected:"
echo "$CHANGED_SH_FILES"
# Extract app names from the file names or content
APP_NAMES=""
for FILE in $CHANGED_SH_FILES; do
# Assuming the app name is part of the file name (e.g., 'appName.sh')
APP_NAME=$(basename "$FILE" .sh)
APP_NAMES="$APP_NAMES$APP_NAME "
done
echo "App names to process: $APP_NAMES"
echo "::set-output name=app_names::$APP_NAMES"
fi
# Step 6: Process the app names and update .app-headers
- name: Process app names and update .app-headers
if: steps.detect_sh_files.outputs.app_names != ''
run: |
APP_NAMES="${{ steps.detect_sh_files.outputs.app_names }}"
# Ensure .app-headers file exists
2025-01-10 11:52:59 +00:00
if [ ! -f ".app-headers" ]; then
2025-01-10 12:42:55 +00:00
echo "Creating .app-headers file."
echo "Generated by CI on $(date)" > .app-headers
2025-01-10 11:52:59 +00:00
else
2025-01-10 12:42:55 +00:00
echo ".app-headers file already exists."
2025-01-10 11:52:59 +00:00
fi
2025-01-10 11:49:58 +00:00
2025-01-10 13:15:22 +00:00
# For each app name, run figlet and append to .app-headers
for APP_NAME in $APP_NAMES; do
echo "Processing app: $APP_NAME"
echo "$(figlet $APP_NAME)" >> .app-headers
done
# Step 7: Commit and push changes (if any)
2025-01-10 12:42:55 +00:00
- name: Commit and push changes
2025-01-10 12:06:06 +00:00
run: |
2025-01-10 12:11:02 +00:00
git diff --quiet -- .app-headers || git commit -am "[core]: update .app-headers to latest version"
2025-01-10 12:06:06 +00:00
git push origin update-app-headers --force
2025-01-10 12:00:27 +00:00
2025-01-10 13:15:22 +00:00
# Step 8: Create Pull Request if changes detected
2025-01-10 12:02:36 +00:00
- name: Create Pull Request if changes detected
2025-01-10 12:03:26 +00:00
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2025-01-10 11:04:38 +00:00
run: |
2025-01-10 12:45:36 +00:00
echo "Checking if PR exists."
PR_EXISTS=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
echo "PR_EXISTS: $PR_EXISTS"
2025-01-10 11:04:38 +00:00
if [ -z "$PR_EXISTS" ]; then
2025-01-10 11:49:58 +00:00
echo "Creating a new PR."
2025-01-10 12:45:36 +00: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 12:46:37 +00:00
--base main)
2025-01-10 12:45:36 +00:00
echo "PR created: $PR_URL"
2025-01-10 11:21:27 +00:00
else
2025-01-10 11:49:58 +00:00
echo "PR already exists."
2025-01-10 11:04:38 +00:00
fi
2025-01-10 13:15:22 +00:00
# Step 9: Automatically merge PR
2025-01-10 12:09:46 +00:00
- name: Automatically merge PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Attempting to merge PR."
2025-01-10 12:45:36 +00:00
PR_NUMBER=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
echo "Found PR number: $PR_NUMBER"
2025-01-10 12:09:46 +00: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 12:46:37 +00:00
2025-01-10 13:15:22 +00:00
# Step 10: Final status output
2025-01-10 11:49:58 +00:00
- name: Output final status
run: |
echo "Workflow completed successfully. Branch and PR status updated."