-
Notifications
You must be signed in to change notification settings - Fork 3
85 lines (78 loc) · 2.98 KB
/
update-refs-in-docs.yml
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
name: Update references in Docsite
on:
push:
branches:
- main
jobs:
generate-node-sdk-refs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: main
fetch-depth: 0
persist-credentials: false
- name: install modules
run: |
npm install
- name: Generate Node SDK references
run: |
npm run docs-gen
cd ../..
mkdir refs
cp -r skyflow-node/skyflow-node/docs/* refs/
cd skyflow-node/skyflow-node/
rm -r docs/
git checkout -- package-lock.json
echo "SHORT_SHA=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV
- name: Create a branch in skyflow-docs
env:
TOKEN: ${{ secrets.PAT_ACTIONS }}
REPO_OWNER: skyflowapi
REPO_NAME: skyflow-docs
ACTOR: ${{ github.actor }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create a new branch in skyflow-docs
cd $GITHUB_WORKSPACE
git remote add skyflow-docs https://${TOKEN}@github.com/${REPO_OWNER}/${REPO_NAME}.git
git fetch skyflow-docs main
BRANCH_NAME="SDK/node/${{ env.SHORT_SHA }}"
git remote set-url --push skyflow-docs https://${ACTOR}:${TOKEN}@github.com/${REPO_OWNER}/${REPO_NAME}.git
git checkout -b $BRANCH_NAME skyflow-docs/main
cp -r ../../refs/* src/pages/content/docs/sdks/skyflow-node/
- name: Push files and raise a PR
env:
TOKEN: ${{ secrets.PAT_ACTIONS }}
REPO_OWNER: skyflowapi
REPO_NAME: skyflow-docs
ACTOR: ${{ github.actor }}
run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
BRANCH_NAME="SDK/node/${{ env.SHORT_SHA }}"
git add .
# Check if there are changes to commit
if [[ -n "$(git status --porcelain)" ]]; then
git commit -m "SDK-${{ env.SHORT_SHA }} Updated Node SDK references"
git push skyflow-docs $BRANCH_NAME
# Raise a pull request
BASE_BRANCH="main"
BRANCH_NAME="SDK/node/${{ env.SHORT_SHA }}"
TITLE="SDK-${{ env.SHORT_SHA }}: Updated Node SDK references"
BODY="This pull request adds the latest Node SDK references. Commit id for reference: $GITHUB_SHA"
API_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls"
echo "API URL: $API_URL"
RESPONSE=$(curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $TOKEN" \
-d "{\"title\":\"$TITLE\",\"body\":\"$BODY\",\"head\":\"${BRANCH_NAME}\",\"base\":\"$BASE_BRANCH\"}" \
"$API_URL")
echo "Response Body: $RESPONSE"
PR_URL=$(echo "$RESPONSE" | jq -r '.html_url')
echo "Pull Request URL: $PR_URL"
else
echo "No changes to commit. Skipping push files and raise a PR."
exit 0
fi