mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-04-19 05:18:06 +00:00
Update generate-app-headers.yaml
This commit is contained in:
parent
84042b7508
commit
bd5cd844bf
102
.github/workflows/generate-app-headers.yaml
vendored
102
.github/workflows/generate-app-headers.yaml
vendored
@ -13,6 +13,14 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
# 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
|
- name: Generate a token
|
||||||
id: generate-token
|
id: generate-token
|
||||||
uses: actions/create-github-app-token@v1
|
uses: actions/create-github-app-token@v1
|
||||||
@ -20,74 +28,80 @@ jobs:
|
|||||||
app-id: ${{ secrets.CREATE_HEADER_APP_ID }}
|
app-id: ${{ secrets.CREATE_HEADER_APP_ID }}
|
||||||
private-key: ${{ secrets.CREATE_HEADER_SECRET }}
|
private-key: ${{ secrets.CREATE_HEADER_SECRET }}
|
||||||
|
|
||||||
|
# Step 3: Checkout repository
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0 # Fetch all history to ensure we have full access to the repo history
|
||||||
|
|
||||||
- name: Set up Figlet (Optional, for decoration)
|
# Step 4: Check or Update Branch (Create or update the update-app-headers branch)
|
||||||
|
- name: Check or Update Branch
|
||||||
|
run: |
|
||||||
|
git fetch origin
|
||||||
|
if ! git show-ref --quiet refs/heads/update-app-headers; then
|
||||||
|
echo "Creating the 'update-app-headers' branch as it does not exist."
|
||||||
|
git checkout -b update-app-headers origin/main
|
||||||
|
else
|
||||||
|
echo "Switching to the existing 'update-app-headers' branch."
|
||||||
|
git checkout update-app-headers
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Step 5: Check if there are changes before
|
||||||
|
- name: Check if there are any changes before making any modifications
|
||||||
|
run: |
|
||||||
|
git fetch origin
|
||||||
|
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
|
run: sudo apt-get install -y figlet
|
||||||
|
|
||||||
|
# Step 7: Run generate-app-headers script
|
||||||
- name: Run generate-app-headers script
|
- name: Run generate-app-headers script
|
||||||
run: |
|
run: |
|
||||||
bash .github/workflows/generate-app-headers.sh
|
bash .github/workflows/generate-app-headers.sh
|
||||||
|
|
||||||
- name: Create or update branch
|
# Step 8: Check if changes are available (Check if the app-headers file has been modified)
|
||||||
run: |
|
- name: Check if changes are available
|
||||||
# Check if the branch exists, create it if it doesn't exist
|
|
||||||
git fetch origin
|
|
||||||
if ! git show-ref --quiet refs/heads/update-app-headers; then
|
|
||||||
git checkout -b update-app-headers
|
|
||||||
else
|
|
||||||
git checkout update-app-headers
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configure Git user info
|
|
||||||
git config --global user.name "github-actions[bot]"
|
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Commit the changes if there are any
|
|
||||||
git diff --quiet || git commit -am "[core]: update .app-headers to latest version"
|
|
||||||
|
|
||||||
# Push changes to the branch if there are any
|
|
||||||
git push origin update-app-headers --force || echo "No changes to push"
|
|
||||||
|
|
||||||
- name: Check if there are changes before creating PR
|
|
||||||
id: check-changes
|
id: check-changes
|
||||||
run: |
|
run: |
|
||||||
# Check if there are any changes between 'main' and 'update-app-headers'
|
git diff --exit-code || echo "Changes detected."
|
||||||
git fetch origin
|
|
||||||
git diff --quiet origin/main..update-app-headers
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "No changes detected, skipping PR creation."
|
|
||||||
echo "skip_pr_creation=true" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "Changes detected, proceeding with PR creation."
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Create pull request
|
# Step 9: Create Pull Request (If changes exist, create a PR)
|
||||||
|
- name: Create PR
|
||||||
id: create-pr
|
id: create-pr
|
||||||
if: env.skip_pr_creation != 'true' # Only create PR if changes are detected
|
if: steps.check-changes.outcome == 'success'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
PR_EXISTS=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
|
PR_EXISTS=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
|
||||||
if [ -z "$PR_EXISTS" ]; then
|
if [ -z "$PR_EXISTS" ]; then
|
||||||
# Create the pull request if it doesn't exist
|
echo "Creating a new PR."
|
||||||
gh pr create --title "[core]: update .app-headers to latest version" \
|
gh pr create --title "[core]: update .app-headers to latest version" \
|
||||||
--body "This PR automatically updates the app-headers file." \
|
--body "This PR automatically updates the app-headers file." \
|
||||||
--head update-app-headers \
|
--head update-app-headers \
|
||||||
--base main
|
--base main
|
||||||
else
|
else
|
||||||
echo "PR already exists, skipping creation."
|
echo "PR already exists."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Final Status
|
# Step 10: Final status (Output status to console)
|
||||||
|
- name: Output final status
|
||||||
run: |
|
run: |
|
||||||
echo "Workflow completed successfully."
|
echo "Workflow completed successfully. Branch and PR status updated."
|
||||||
|
|
||||||
|
# Step 11: Post checkout repo (Make sure to clean up the repository state)
|
||||||
|
- name: Post checkout repo
|
||||||
|
run: |
|
||||||
|
echo "Repository check complete."
|
||||||
|
git status
|
||||||
|
|
||||||
|
# Step 12: Post generate token (Output generated token for logging purposes)
|
||||||
|
- name: Post generate token
|
||||||
|
run: |
|
||||||
|
echo "Generated token: ${GITHUB_TOKEN}"
|
||||||
|
|
||||||
|
# Step 13: Complete (Final confirmation that workflow has finished)
|
||||||
|
- name: Complete
|
||||||
|
run: |
|
||||||
|
echo "Workflow has completed successfully."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user