-
Notifications
You must be signed in to change notification settings - Fork 18
67 lines (54 loc) · 2.67 KB
/
sync_doc_devportal.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
name: Create Pull Request to DevPortal's repo
on:
push:
branches:
- main
paths:
- "apps/docs/pages/docs/discover/*"
jobs:
syncAndCreatePR:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.DEVELOPER_PORTAL_CI }}
- name: Set up Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Sync files to the other repository and create Pull Request
env:
DEVELOPER_PORTAL_CI_TOKEN: ${{ secrets.DEVELOPER_PORTAL_CI }}
SOURCE_REPO_NAME: "wallet-api"
SOURCE_REPO: "github.com/LedgerHQ/wallet-api"
SOURCE_FILE_PATH_1: "apps/docs/pages/docs/discover"
TARGET_REPO_NAME: "developer-portal"
TARGET_REPO: "github.com/LedgerHQ/developer-portal"
TARGET_FILE_PATH_1: "pages/docs/discover"
TARGET_BRANCH: "main"
TARGET_PR_API_URL: "https://api.github.com/repos/LedgerHQ/developer-portal/pulls"
PR_TITLE: "Merging documentation from wallet-api"
PR_COMMIT_MESSAGE: "doc: add new changes from wallet-api doc"
PR_REVIEWERS: '{"reviewers": ["cfranceschi-ledger"]}'
PR_ASSIGN: '{"assignees": ["ramyeb"]}'
run: |
git clone --depth 1 https://${DEVELOPER_PORTAL_CI_TOKEN}@${SOURCE_REPO}
git clone --depth 1 https://ldg-github-ci:${DEVELOPER_PORTAL_CI_TOKEN}@${TARGET_REPO}
PR_BRANCH_NAME=sync-discover-doc-$(date +%d-%m-%H-%M)
cd ${TARGET_REPO_NAME}
git checkout -b ${PR_BRANCH_NAME}
# Replace files
cp -rT ../${SOURCE_REPO_NAME}/${SOURCE_FILE_PATH_1} ${TARGET_FILE_PATH_1}
# Push changes
git add ${TARGET_FILE_PATH_1}
git commit -m "${PR_COMMIT_MESSAGE}" || echo "No changes to commit"
git push origin ${PR_BRANCH_NAME}
# Create Pull Request
JSON_PAYLOAD="{\"title\":\"${PR_TITLE}-$(date +%d-%m-%H-%M)\",\"head\":\"${PR_BRANCH_NAME}\",\"base\":\"${TARGET_BRANCH}\"}"
PR_RESPONSE=$(curl -X POST -H "Authorization: token ${DEVELOPER_PORTAL_CI_TOKEN}" -d "$JSON_PAYLOAD" ${TARGET_PR_API_URL})
PR_URL=$(echo $PR_RESPONSE | jq -r '.url')
PR_ISSUE_URL=$(echo $PR_RESPONSE | jq -r '.issue_url')
# Assign Reviewers
curl -s -X POST -H "Authorization: token ${DEVELOPER_PORTAL_CI_TOKEN}" -d "$PR_REVIEWERS" ${PR_URL}/requested_reviewers
# Assign Users to the Pull Request
curl -s -X POST -H "Authorization: token ${DEVELOPER_PORTAL_CI_TOKEN}" -d "$PR_ASSIGN" ${PR_URL}/assignees