-
-
Notifications
You must be signed in to change notification settings - Fork 805
105 lines (95 loc) · 3.66 KB
/
generate-app-headers.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Update .app-headers in /misc
on:
pull_request:
types:
- closed
branches:
- main
# Stellen sicher, dass nur gemergte PRs den Workflow auslösen
# Triggern nur wenn der PR gemerged wurde
if: github.event.pull_request.merged == true
schedule:
- cron: "59 23 * * *" # Führen den Workflow täglich um 23:59 UTC aus
workflow_dispatch:
jobs:
update-and-create-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all branches for full context
# Step 2: Set up Git user
- name: Configure Git user
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
# Step 3: Check or create update-app-headers branch
- name: Check or create update-app-headers branch
run: |
git fetch origin
if git show-ref --quiet refs/heads/update-app-headers; then
echo "Switching to 'update-app-headers' branch."
git checkout update-app-headers
else
echo "Creating 'update-app-headers' branch."
git checkout -b update-app-headers origin/main
fi
# Step 4: Merge main into update-app-headers
- name: Merge main into update-app-headers
run: |
git merge origin/main --no-edit || echo "No changes to merge from main."
# Step 5: Ensure .app-headers file exists
- name: Ensure .app-headers file exists
run: |
if [ ! -f ".app-headers" ]; then
echo "Creating .app-headers file."
echo "Generated by CI on $(date)" > .app-headers
else
echo ".app-headers file already exists."
fi
# Step 6: Commit and push changes (if any)
- name: Commit and push changes
run: |
git diff --quiet -- .app-headers || git commit -am "[core]: update .app-headers to latest version"
git push origin update-app-headers --force
# Step 7: Create Pull Request if changes detected
- name: Create Pull Request if changes detected
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Checking if PR exists."
PR_EXISTS=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
echo "PR_EXISTS: $PR_EXISTS"
if [ -z "$PR_EXISTS" ]; then
echo "Creating a new PR."
PR_URL=$(gh pr create --title "[core]: update .app-headers to latest version" \
--body "This PR automatically updates the .app-headers file." \
--head update-app-headers \
--base main -q .url)
echo "PR created: $PR_URL"
else
echo "PR already exists."
fi
# Step 8: Automatically merge PR
- name: Automatically merge PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Attempting to merge PR."
PR_NUMBER=$(gh pr list --head "update-app-headers" --json number --jq '.[].number')
echo "Found PR number: $PR_NUMBER"
if [ -n "$PR_NUMBER" ]; then
gh pr merge "$PR_NUMBER" --merge --admin --delete-branch
echo "PR merged successfully."
else
echo "No PR found to merge."
fi
# Step 9: Final status output
- name: Output final status
run: |
echo "Workflow completed successfully. Branch and PR status updated."