-
Notifications
You must be signed in to change notification settings - Fork 123
82 lines (75 loc) · 2.91 KB
/
Copy pathupdate-submodule.yml
File metadata and controls
82 lines (75 loc) · 2.91 KB
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
name: Update Submodule
on:
repository_dispatch:
types: [update-submodule-request]
jobs:
update-submodule:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
with:
token: ${{ secrets.PUBLIC_DOCS_WRITE_TOKEN }}
submodules: true
- name: Set Git Config
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "clement.choupault@mistral.ai"
- name: Check if Branch Exists
id: check_branch
run: |
if git ls-remote --exit-code --heads origin update-cookbook-submodule > /dev/null 2>&1; then
echo "branch_exists=true" >> $GITHUB_OUTPUT
else
echo "branch_exists=false" >> $GITHUB_OUTPUT
fi
- name: Check if PR Exists
id: check_pr
env:
GITHUB_TOKEN: ${{ secrets.PUBLIC_DOCS_WRITE_TOKEN }}
run: |
PR_COUNT=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/pulls?head=update-cookbook-submodule&state=open" | jq '. | length')
if [ "$PR_COUNT" -gt 0 ]; then
echo "pr_exists=true" >> $GITHUB_OUTPUT
else
echo "pr_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create or Checkout Branch
run: |
git fetch
if [ "${{ steps.check_branch.outputs.branch_exists }}" = "true" ]; then
git checkout update-cookbook-submodule
else
git checkout -b update-cookbook-submodule
fi
- name: Update Submodule
run: |
git submodule init
git submodule update --remote
cd static/cookbooks
git pull origin main
cd ../..
git add static/cookbooks
git commit -m "Update cookbook submodule to latest version"
- name: Push Changes
run: |
if [ "${{ steps.check_branch.outputs.branch_exists }}" = "false" ]; then
git push --set-upstream origin update-cookbook-submodule
else
git push origin update-cookbook-submodule
fi
- name: Create Pull Request via API
if: steps.check_pr.outputs.pr_exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.PUBLIC_DOCS_WRITE_TOKEN }}
run: |
PR_TITLE="Update cookbook submodule to latest version"
PR_BODY="This PR updates the cookbook submodule to the latest version."
PR_HEAD="update-cookbook-submodule"
PR_BASE="main"
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls \
-d "{\"title\":\"$PR_TITLE\",\"body\":\"$PR_BODY\",\"head\":\"$PR_HEAD\",\"base\":\"$PR_BASE\"}"