2025-01-10 10:44:42 +00:00
|
|
|
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:
|
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 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
|
2025-01-10 10:44:42 +00:00
|
|
|
- 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 10:44:42 +00:00
|
|
|
|
2025-01-10 11:49:58 +00:00
|
|
|
# Step 3: Checkout repository
|
2025-01-10 10:44:42 +00:00
|
|
|
- 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 10:44:42 +00:00
|
|
|
|
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
|
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 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:57:42 +00:00
|
|
|
# Step 4.1: Configure Git user
|
|
|
|
- name: Configure Git user
|
|
|
|
run: |
|
|
|
|
git config --global user.name "github-actions[bot]"
|
|
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
|
|
|
|
# Step 5: Ensure .app-headers file exists
|
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
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2025-01-10 11:54:31 +00:00
|
|
|
# Step 8: Check for changes (ensure file is updated)
|
2025-01-10 11:52:59 +00:00
|
|
|
- name: Check for changes
|
2025-01-10 11:49:58 +00:00
|
|
|
run: |
|
|
|
|
git diff --exit-code || echo "Changes detected."
|
2025-01-10 11:52:59 +00:00
|
|
|
|
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"
|
|
|
|
|
2025-01-10 12:00:27 +00:00
|
|
|
# Step 11: Compare branches (Check for differences between main and update-app-headers)
|
|
|
|
- name: Compare branches (Check for differences between main and update-app-headers)
|
|
|
|
run: |
|
|
|
|
git fetch origin
|
|
|
|
DIFF=$(git diff --quiet origin/main..origin/update-app-headers || echo "Changes detected")
|
|
|
|
if [[ "$DIFF" == "Changes detected" ]]; then
|
|
|
|
echo "Changes found between main and update-app-headers. Proceeding with PR creation."
|
|
|
|
else
|
|
|
|
echo "No changes found between main and update-app-headers. Skipping PR creation."
|
|
|
|
exit 0 # Skip PR creation if no changes are found
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Step 12: 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 12:00:27 +00:00
|
|
|
if: steps.compare-branches.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 12:00:27 +00:00
|
|
|
# Step 13: 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 12:00:27 +00:00
|
|
|
# Step 14: 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 12:00:27 +00:00
|
|
|
# Step 15: 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 12:00:27 +00:00
|
|
|
# Step 16: 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:54:31 +00:00
|
|
|
echo "Workflow has completed successfully."
|