-
Notifications
You must be signed in to change notification settings - Fork 59
74 lines (56 loc) · 2.47 KB
/
build_publish.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
# If we tag the docs here we automatically create a PR to the public repo
name: Build and Publish
on:
push:
# We only deploy on tags and main branch
tags:
# Only run on tags that match the following regex
# This will match tags like v1.0.0, v1.0.1, etc.
- v[0-9]+.[0-9]+.[0-9]+
jobs:
create_pr_on_public:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.PUBLIC_DOCS_WRITE_TOKEN }}
- name: Pull public updates
env: # We cannot use the github bot token to push to the public repo, we have to use one with more permissions
GITHUB_TOKEN: ${{ secrets.PUBLIC_DOCS_WRITE_TOKEN }}
run: |
set -x
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git remote add public https://github.com/mistralai/platform-docs-public.git
git remote update
# Create a diff of the changes, ignoring the ci workflow
git merge public/main --no-commit --no-ff --no-edit --allow-unrelated-histories
# If there are changes, commit them
if ! git diff-index --cached --quiet HEAD; then
git commit -m "Update from public repo"
git push origin ${{github.ref}}
else
echo "No changes to apply"
fi
- name: Push to public repo
env:
GITHUB_TOKEN: ${{ secrets.PUBLIC_DOCS_WRITE_TOKEN }}
run: |
git checkout public/main
git checkout -b doc/${{github.ref_name}}
# write version number to version file
echo ${{github.ref_name}} > version.txt
git add .
git commit -m "Bump version file"
# create a diff of this ref and the public repo
git diff doc/${{github.ref_name}} ${{github.ref_name}} --binary -- . ':!.github' > changes.diff
# apply the diff to the current branch
git apply changes.diff
# commit the changes
git add .
git commit -m "Update version to ${{github.ref_name}}"
# push the changes
git push public doc/${{github.ref_name}}
# Create a PR from this branch to the public repo
gh pr create --title "Update docs to ${{github.ref_name}}" --body "This PR was automatically created by a GitHub Action" --base main --head doc/${{github.ref_name}} --repo mistralai/platform-docs-public