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

94 lines
3.2 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
2025-01-10 11:46:07 +00:00
- name: Set up Figlet (Optional, for decoration)
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:44:25 +00:00
# Check if the branch exists, create it if it doesn't exist
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
git checkout -b update-app-headers
else
git checkout update-app-headers
fi
2025-01-10 11:04:38 +00:00
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:44:25 +00:00
# Check if the file exists, and if not, create it
if [ ! -f "./misc/.app-headers" ]; then
echo "File .app-headers not found, creating it."
touch ./misc/.app-headers
fi
2025-01-10 11:46:07 +00:00
# Commit the changes if there are any
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
2025-01-10 11:39:51 +00:00
git diff --quiet origin/main..update-app-headers
if [ $? -eq 0 ]; then
2025-01-10 11:19:11 +00:00
echo "No changes detected, skipping PR creation."
2025-01-10 11:39:51 +00:00
echo "skip_pr_creation=true" >> $GITHUB_ENV
else
echo "Changes detected, proceeding with PR creation."
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:39:51 +00:00
if: env.skip_pr_creation != 'true' # 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:21:27 +00:00
- name: Final Status
run: |
2025-01-10 11:37:52 +00:00
echo "Workflow completed successfully."