-
Notifications
You must be signed in to change notification settings - Fork 19
83 lines (71 loc) · 3.24 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Create Pull Request to DevPortal's repo
on: workflow_dispatch
# push:
# branches:
# - main
# paths:
# - "apps/docs/pages/APIs/wallet-api/*"
# - "apps/docs/pages/docs/discover/*"
jobs:
syncAndCreatePR:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.DEVELOPER_PORTAL_CI }}
- name: Checkout repository
uses: actions/setup-node@v2
with:
node-version: "lts/*"
- 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/APIs/wallet-api"
SOURCE_FILE_PATH_2: "apps/docs/pages/docs/discover"
TARGET_REPO_NAME: "developer-portal"
TARGET_REPO: "github.com/LedgerHQ/developer-portal"
TARGET_FILE_PATH_1: "pages/APIs/wallet-api"
TARGET_FILE_PATH_2: "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://${SOURCE_REPO}
git clone --depth 1 https://${DEVELOPER_PORTAL_CI_TOKEN}@${TARGET_REPO}
PR_BRANCH_NAME=sync-discover-doc-$(date +%s)
cd ${TARGET_REPO_NAME}
git checkout -b ${PR_BRANCH_NAME}
git remote set-url origin https://${DEVELOPER_PORTAL_CI_TOKEN}@${TARGET_REPO}
# Replace files
cp -rT ../${SOURCE_REPO_NAME}/${SOURCE_FILE_PATH_1} ${TARGET_FILE_PATH_1}
cp -rT ../${SOURCE_REPO_NAME}/${SOURCE_FILE_PATH_2} ${TARGET_FILE_PATH_2}
# Push changes
git add ${TARGET_FILE_PATH_1}
git add ${TARGET_FILE_PATH_2}
git commit -m "${PR_COMMIT_MESSAGE}"
git push origin ${PR_BRANCH_NAME}
git push https://${DEVELOPER_PORTAL_CI_TOKEN}@${TARGET_REPO} ${PR_BRANCH_NAME}
# Create Pull Request
PR_RESPONSE=$(curl -X POST -H "Authorization: token ${DEVELOPER_PORTAL_CI_TOKEN}" \
-d '{"title":"${PR_TITLE}","head":"'"$PR_BRANCH_NAME}"'","base":"${TARGET_BRANCH}"}' \
${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_ISSUE_URL}/assignees