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

118 lines
4.0 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:
2025-01-10 11:49:58 +00:00
# Step 1: Setup job (Check environment & install dependencies)
- name: Setup environment
run: |
echo "Setting up the environment for the workflow."
sudo apt-get update
sudo apt-get install -y figlet gh jq
# Step 2: Generate Token
- 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 }}
2025-01-10 11:49:58 +00:00
# Step 3: Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
with:
2025-01-10 11:49:58 +00:00
fetch-depth: 0 # Fetch all history to ensure we have full access to the repo history
2025-01-10 11:49:58 +00:00
# Step 4: Check or Update Branch (Create or update the update-app-headers branch)
- name: Check or Update Branch
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 11:49:58 +00:00
echo "Creating the 'update-app-headers' branch as it does not exist."
git checkout -b update-app-headers origin/main
2025-01-10 11:44:25 +00:00
else
2025-01-10 11:49:58 +00:00
echo "Switching to the existing '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 11:49:58 +00:00
# Step 5: Check if there are changes before
- name: Check if there are any changes before making any modifications
2025-01-10 11:19:11 +00:00
run: |
git fetch origin
2025-01-10 11:49:58 +00:00
git diff --exit-code || echo "There are changes to commit."
# Step 6: Setup Figlet (Install and set up Figlet for text generation)
- name: Set up Figlet
run: sudo apt-get install -y figlet
2025-01-10 11:19:11 +00:00
2025-01-10 11:49:58 +00:00
# Step 7: Run generate-app-headers script
- name: Run generate-app-headers script
run: |
bash .github/workflows/generate-app-headers.sh
# Step 8: Check if changes are available (Check if the app-headers file has been modified)
- name: Check if changes are available
id: check-changes
run: |
git diff --exit-code || echo "Changes detected."
2025-01-10 11:51:19 +00:00
# Step 9: Commit changes if any
- name: Commit changes if any
run: |
git diff --exit-code || git commit -am "[core]: update .app-headers to latest version"
# Step 10: Push changes to the branch
- name: Push changes to the branch
run: |
git push origin update-app-headers --force || echo "No changes to push"
# Step 11: Create Pull Request (If changes exist, create a PR)
2025-01-10 11:49:58 +00:00
- name: Create PR
2025-01-10 11:04:38 +00:00
id: create-pr
2025-01-10 11:49:58 +00:00
if: steps.check-changes.outcome == 'success'
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: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 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
2025-01-10 11:49:58 +00:00
echo "PR already exists."
2025-01-10 11:04:38 +00:00
fi
2025-01-10 11:51:19 +00:00
# Step 12: Final status (Output status to console)
2025-01-10 11:49:58 +00:00
- name: Output final status
run: |
echo "Workflow completed successfully. Branch and PR status updated."
2025-01-10 11:51:19 +00:00
# Step 13: Post checkout repo (Make sure to clean up the repository state)
2025-01-10 11:49:58 +00:00
- name: Post checkout repo
run: |
echo "Repository check complete."
git status
2025-01-10 11:51:19 +00:00
# Step 14: Post generate token (Output generated token for logging purposes)
2025-01-10 11:49:58 +00:00
- name: Post generate token
run: |
echo "Generated token: ${GITHUB_TOKEN}"
2025-01-10 11:51:19 +00:00
# Step 15: Complete (Final confirmation that workflow has finished)
2025-01-10 11:49:58 +00:00
- name: Complete
2025-01-10 11:21:27 +00:00
run: |
2025-01-10 11:49:58 +00:00
echo "Workflow has completed successfully."