-
Notifications
You must be signed in to change notification settings - Fork 51
101 lines (90 loc) · 4.17 KB
/
zwe-doc-generation.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Update zwe documentation
on:
# Will run this on push when v2 is out
push:
branches:
- v2.x/rc
workflow_dispatch:
env:
DOCS_SITE_ZWE_COMMAND_REFERENCE_DIR: docs/appendix/zwe_server_command_reference
DOCS_SITE_TARGET_BRANCH: docs-staging
DOCS_SITE_COMMIT_BRANCH: auto-update-zwe-reference
ZWE_DOC_GENERATION_DIR: .dependency/zwe_doc_generation
jobs:
update-zwe-documentation:
name: Update zwe documentation on docs-site
runs-on: ubuntu-latest
steps:
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up git
run: |
git config --global user.email "[email protected]"
git config --global user.name "Zowe Robot"
git config --global pull.rebase false # configure to merge in changes from remote branches
- name: Clone docs site
run: git clone https://zowe-robot:${{ secrets.ZOWE_ROBOT_TOKEN }}@github.com/zowe/docs-site.git --depth 1 --branch ${{ env.DOCS_SITE_TARGET_BRANCH }}
- name: Generate zwe documentation
run: node ${{ env.ZWE_DOC_GENERATION_DIR }}
- name: Copy generated zwe documentation files to docs site
run: |
cd docs-site
# check out branch that will contain update and unsure there are no remote differences
git checkout -b ${{ env.DOCS_SITE_COMMIT_BRANCH }}
# if commit branch exists on remote then pull it in
git ls-remote | grep "^refs/heads/${{ env.DOCS_SITE_COMMIT_BRANCH }}$" &&
git pull origin ${{ env.DOCS_SITE_COMMIT_BRANCH }} --allow-unrelated-histories -X ours
cp -R ../${{ env.ZWE_DOC_GENERATION_DIR }}/generated/* ${{ env.DOCS_SITE_ZWE_COMMAND_REFERENCE_DIR }}
- name: Commit changes to branch and push
id: commitChanges
run: |
cd docs-site
git add ${{ env.DOCS_SITE_ZWE_COMMAND_REFERENCE_DIR }}
if git commit -s -m"Update zwe command reference";
then
echo ">>>>>Changes committed to ${{ env.DOCS_SITE_COMMIT_BRANCH }}, now pushing";
git push origin ${{ env.DOCS_SITE_COMMIT_BRANCH }}
echo "createPr=true" >> $GITHUB_OUTPUT
else
echo ">>>>>No update to documentation";
echo "createPr=false" >> $GITHUB_OUTPUT
fi
- name: Create PR if doesn't exist
if: ${{ steps.commitChanges.outputs.createPr == 'true' }}
uses: actions/github-script@v5
with:
github-token: ${{ secrets.ZOWE_ROBOT_TOKEN }}
script: |
const { data: pulls } = await github.rest.pulls.list({
owner: 'zowe',
repo: 'docs-site',
state: 'open',
head: 'zowe:${{ env.DOCS_SITE_COMMIT_BRANCH }}',
base: '${{ env.DOCS_SITE_TARGET_BRANCH }}'
});
if (pulls && pulls.length) {
const existingPr = pulls[0]; // PR exists, assume correct one is at index 0
const repoUrl = '${{ github.server_url }}/${{ github.repository }}';
await github.rest.issues.createComment({
owner: 'zowe',
repo: 'docs-site',
issue_number: existingPr.number,
body: `This PR has been updated with a new commit due to changes at: ${repoUrl}/tree/${{ github.ref }}/bin
Update by: ${repoUrl}/actions/runs/${{ github.run_id }}`
});
console.log(`>>>>>The pull request has been updated and is at: ${existingPr.html_url}`);
} else { // PR does not exist so create one
const { data: pr } = await github.rest.pulls.create({
owner: 'zowe',
repo: 'docs-site',
title: 'Update zwe server command reference',
body: 'Automatic update of the zwe server command reference',
head: '${{ env.DOCS_SITE_COMMIT_BRANCH }}',
base: '${{ env.DOCS_SITE_TARGET_BRANCH }}'
});
console.log(`>>>>>A new pull request was created and is at: ${pr.html_url}`);
}