2025-01-10 10:44:42 +00:00
|
|
|
name: Update .app-headers in /misc
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches: ["main"]
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
jobs:
|
2025-01-10 12:02:36 +00:00
|
|
|
update-and-create-pr:
|
2025-01-10 10:44:42 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
2025-01-10 11:04:38 +00:00
|
|
|
contents: write
|
|
|
|
pull-requests: write
|
|
|
|
|
2025-01-10 10:44:42 +00:00
|
|
|
steps:
|
2025-01-10 12:02:36 +00:00
|
|
|
# Step 1: Checkout repository
|
2025-01-10 10:44:42 +00:00
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
with:
|
2025-01-10 12:02:36 +00:00
|
|
|
fetch-depth: 0 # Ensure we have full access to all branches
|
2025-01-10 10:44:42 +00:00
|
|
|
|
2025-01-10 12:02:36 +00:00
|
|
|
# Step 2: Check if update-app-headers branch exists, create if not
|
|
|
|
- name: Check or Create update-app-headers branch
|
2025-01-10 10:44:42 +00:00
|
|
|
run: |
|
2025-01-10 11:04:38 +00:00
|
|
|
git fetch origin
|
2025-01-10 11:44:25 +00:00
|
|
|
if ! git show-ref --quiet refs/heads/update-app-headers; then
|
2025-01-10 12:02:36 +00:00
|
|
|
echo "Creating 'update-app-headers' branch."
|
2025-01-10 11:49:58 +00:00
|
|
|
git checkout -b update-app-headers origin/main
|
2025-01-10 11:44:25 +00:00
|
|
|
else
|
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
|
|
|
|
fi
|
2025-01-10 11:04:38 +00:00
|
|
|
|
2025-01-10 12:02:36 +00:00
|
|
|
# Step 3: Ensure .app-headers file exists (if missing, create it)
|
2025-01-10 11:52:59 +00:00
|
|
|
- name: Ensure .app-headers file exists
|
2025-01-10 11:19:11 +00:00
|
|
|
run: |
|
2025-01-10 11:52:59 +00:00
|
|
|
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."
|
|
|
|
fi
|
2025-01-10 11:49:58 +00:00
|
|
|
|
2025-01-10 12:02:36 +00:00
|
|
|
# Step 4: Compare .app-headers with main, commit if changes
|
|
|
|
- name: Compare with main and commit changes
|
2025-01-10 12:00:27 +00:00
|
|
|
run: |
|
|
|
|
git fetch origin
|
2025-01-10 12:02:36 +00:00
|
|
|
DIFF=$(git diff --quiet origin/main..origin/update-app-headers -- .app-headers || echo "Changes detected")
|
2025-01-10 12:00:27 +00:00
|
|
|
if [[ "$DIFF" == "Changes detected" ]]; then
|
2025-01-10 12:02:36 +00:00
|
|
|
echo "Changes detected in .app-headers. Committing changes."
|
|
|
|
git commit -am "[core]: update .app-headers to latest version"
|
|
|
|
git push origin update-app-headers --force
|
2025-01-10 12:00:27 +00:00
|
|
|
else
|
2025-01-10 12:02:36 +00:00
|
|
|
echo "No changes in .app-headers. Skipping commit."
|
2025-01-10 12:00:27 +00:00
|
|
|
fi
|
|
|
|
|
2025-01-10 12:02:36 +00:00
|
|
|
# Step 5: Create Pull Request if changes detected
|
|
|
|
- name: Create Pull Request if changes detected
|
2025-01-10 11:04:38 +00:00
|
|
|
run: |
|
|
|
|
PR_EXISTS=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
|
|
|
|
if [ -z "$PR_EXISTS" ]; then
|
2025-01-10 11:49:58 +00:00
|
|
|
echo "Creating a new PR."
|
2025-01-10 11:14:09 +00:00
|
|
|
gh pr create --title "[core]: update .app-headers to latest version" \
|
2025-01-10 12:02:36 +00:00
|
|
|
--body "This PR automatically updates the .app-headers file." \
|
2025-01-10 11:04:38 +00:00
|
|
|
--head update-app-headers \
|
2025-01-10 11:09:27 +00:00
|
|
|
--base main
|
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 12:02:36 +00:00
|
|
|
# Step 6: 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."
|
|
|
|
|