ProxmoxVE/.github/workflows/generate-app-headers.yaml
2025-01-10 13:09:46 +01:00

90 lines
3.3 KiB
YAML

name: Update .app-headers in /misc
on:
push:
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: Check or Create update-app-headers branch
- name: Check or Create update-app-headers branch
run: |
git fetch origin
if ! git show-ref --quiet refs/heads/update-app-headers; then
echo "Creating 'update-app-headers' branch."
git checkout -b update-app-headers origin/main
else
echo "Switching to 'update-app-headers' branch."
git checkout update-app-headers
fi
# Step 3: Ensure .app-headers file exists and verify content
- name: Ensure .app-headers file exists and verify content
run: |
if [ ! -f ".app-headers" ]; then
echo "The .app-headers file does not exist. Creating it."
echo "Generated by CI" > .app-headers
else
echo ".app-headers already exists. Checking if there are any changes."
fi
# Verifying if there are changes in .app-headers file content
git diff --quiet -- .app-headers || echo "Changes detected in .app-headers"
# Step 4: Commit changes if detected
- name: Commit changes if detected
if: ${{ steps.verify_changes.outputs.changes_detected == 'true' }}
run: |
git commit -am "[core]: update .app-headers to latest version"
git push origin update-app-headers --force
# Step 5: Create Pull Request if changes detected
- 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 --json url -q .url)
echo "PR created: $PR_URL"
else
echo "PR already exists."
fi
# Step 6: Automatically merge the PR if no conflicts
- name: Automatically merge PR
if: ${{ steps.verify_changes.outputs.changes_detected == 'true' }}
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 7: Final status output
- name: Output final status
run: |
echo "Workflow completed successfully. Branch and PR status updated."