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

95 lines
3.4 KiB
YAML
Raw Normal View History

name: Update .app-headers in /misc
on:
push:
branches: ["main"]
workflow_dispatch:
jobs:
2025-01-10 11:04:38 +00:00
update-and-merge-pr:
runs-on: ubuntu-latest
permissions:
2025-01-10 11:04:38 +00:00
contents: write
pull-requests: write
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.CREATE_HEADER_APP_ID }}
2025-01-10 11:04:38 +00:00
private-key: ${{ secrets.CREATE_HEADER_SECRET }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Figlet
run: sudo apt-get install -y figlet
- name: Run generate-app-headers script
run: |
bash .github/workflows/generate-app-headers.sh
2025-01-10 11:04:38 +00:00
- name: Create or update branch
run: |
2025-01-10 11:17:44 +00:00
# Check if the branch exists, and create it if not
2025-01-10 11:04:38 +00:00
git fetch origin
git checkout -b update-app-headers || git checkout update-app-headers
2025-01-10 11:06:37 +00:00
# Configure Git user info
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2025-01-10 11:17:44 +00:00
# Make sure there are changes to commit
2025-01-10 11:15:52 +00:00
git diff --quiet || git commit -am "[core]: update .app-headers to latest version"
2025-01-10 11:04:38 +00:00
2025-01-10 11:17:44 +00:00
# Push changes to the branch if there are any
2025-01-10 11:15:52 +00:00
git push origin update-app-headers --force || echo "No changes to push"
2025-01-10 11:04:38 +00:00
2025-01-10 11:19:11 +00:00
- name: Check if there are changes before creating PR
id: check-changes
run: |
2025-01-10 11:22:57 +00:00
# Check if there are any changes between 'main' and 'update-app-headers'
2025-01-10 11:19:11 +00:00
git fetch origin
git diff --quiet origin/main..update-app-headers || echo "Changes detected" > changes.txt
if [ ! -f changes.txt ]; then
echo "No changes detected, skipping PR creation."
2025-01-10 11:22:57 +00:00
exit 0 # Exit successfully if no changes are found
2025-01-10 11:19:11 +00:00
fi
2025-01-10 11:04:38 +00:00
- name: Create pull request
id: create-pr
2025-01-10 11:22:57 +00:00
if: steps.check-changes.outcome == 'success' # Only create PR if changes are detected
2025-01-10 11:08:30 +00:00
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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:17:44 +00:00
# Create the pull request if it doesn't exist
2025-01-10 11:14:09 +00:00
gh pr create --title "[core]: update .app-headers to latest version" \
2025-01-10 11:04:38 +00:00
--body "This PR automatically updates the app-headers file." \
--head update-app-headers \
2025-01-10 11:09:27 +00:00
--base main
2025-01-10 11:21:27 +00:00
else
echo "PR already exists, skipping creation."
2025-01-10 11:04:38 +00:00
fi
2025-01-10 11:14:09 +00:00
- name: Merge pull request (Squash and Merge)
2025-01-10 11:04:38 +00:00
if: steps.create-pr.outputs.pr_exists == 'true'
2025-01-10 11:08:30 +00:00
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
2025-01-10 11:17:44 +00:00
# Get the PR number and merge it if it exists
2025-01-10 11:04:38 +00:00
PR_NUMBER=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
if [ -n "$PR_NUMBER" ]; then
2025-01-10 11:17:44 +00:00
# Squash and merge the PR automatically
2025-01-10 11:14:09 +00:00
gh pr merge $PR_NUMBER --squash --auto --delete-branch
2025-01-10 11:04:38 +00:00
fi
2025-01-10 11:21:27 +00:00
- name: Final Status
if: steps.check-changes.outcome != 'success'
run: |
echo "No changes detected or already merged, workflow completed successfully."