Skip to content

Commit c41c2c8

Browse files
authored
Add github action to auto update spec (dropbox#232)
* Add github action to auto update spec * Add correct generate script name * Fix mistake in generate_base_client when stone was removed as submodule
1 parent 2166a56 commit c41c2c8

File tree

2 files changed

+75
-16
lines changed

2 files changed

+75
-16
lines changed

.github/workflows/spec_update.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Spec Update
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: 0 0 * * *
6+
7+
jobs:
8+
Update:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Setup Python environment
13+
uses: actions/[email protected]
14+
with:
15+
python-version: 2.7
16+
- name: Get current time
17+
uses: 1466587594/get-current-time@v2
18+
id: current-time
19+
with:
20+
format: YYYY_MM_DD
21+
utcOffset: "-08:00"
22+
- name: Install SDK
23+
run: |
24+
npm install
25+
- name: Update Modules
26+
run: |
27+
git submodule init
28+
git submodule update --remote --recursive
29+
- name: Generate Branch Name
30+
id: git-branch
31+
run: |
32+
echo "::set-output name=branch::spec_update_${{ steps.current-time.outputs.formattedTime }}"
33+
- name: Generate Num Diffs
34+
id: git-diff-num
35+
run: |
36+
diffs=$(git diff --submodule spec | grep ">" | wc -l)
37+
echo "Number of Spec diffs: $diffs"
38+
echo "::set-output name=num-diff::$diffs"
39+
- name: Generate Diff
40+
id: git-diff
41+
run: |
42+
cd spec
43+
gitdiff=$(git log -n ${{ steps.git-diff-num.outputs.num-diff }} --pretty="format:%n %H %n%n %b")
44+
commit="Automated Spec Update $gitdiff"
45+
commit="${commit//'%'/'%25'}"
46+
commit="${commit//$'\n'/'%0A'}"
47+
commit="${commit//$'\r'/'%0D'}"
48+
echo "Commit Message: $commit"
49+
echo "::set-output name=commit::$commit"
50+
cd ..
51+
- name: Generate New Routes
52+
run: |
53+
python -m pip install --upgrade pip
54+
pip install -r requirements.txt
55+
python generate_base_client.py
56+
- name: Create Pull Request
57+
uses: peter-evans/[email protected]
58+
if: steps.git-diff-num.outputs.num-diff != 0
59+
with:
60+
token: ${{ secrets.SPEC_UPDATE_TOKEN }}
61+
commit-message: |
62+
${{ steps.git-diff.outputs.commit}}
63+
branch: ${{ steps.git-branch.outputs.branch }}
64+
delete-branch: true
65+
title: 'Automated Spec Update'
66+
body: |
67+
${{ steps.git-diff.outputs.commit}}
68+
base: 'master'
69+
team-reviewers: |
70+
owners
71+
maintainers
72+
draft: false

generate_base_client.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
type=str,
2525
help='Path to API specifications. Each must have a .stone extension.',
2626
)
27-
_cmdline_parser.add_argument(
28-
'-s',
29-
'--stone',
30-
type=str,
31-
help='Path to clone of stone repository.',
32-
)
3327

3428
def main():
3529
"""The entry point for the program."""
@@ -46,10 +40,6 @@ def main():
4640

4741
specs = [os.path.join(os.getcwd(), s) for s in specs]
4842

49-
stone_path = os.path.abspath('stone')
50-
if args.stone:
51-
stone_path = args.stone
52-
5343
dropbox_pkg_path = os.path.abspath(
5444
os.path.join(os.path.dirname(sys.argv[0]), 'dropbox'))
5545
if verbose:
@@ -60,25 +50,22 @@ def main():
6050
subprocess.check_output(
6151
(['python', '-m', 'stone.cli', 'python_types', dropbox_pkg_path] +
6252
specs + ['-a', 'host', '-a', 'style'] +
63-
['--', '-r', 'dropbox.dropbox.Dropbox.{ns}_{route}']),
64-
cwd=stone_path)
53+
['--', '-r', 'dropbox.dropbox.Dropbox.{ns}_{route}']))
6554

6655
if verbose:
6756
print('Generating Python client')
6857

6958
o = subprocess.check_output(
7059
(['python', '-m', 'stone.cli', 'python_client', dropbox_pkg_path] +
7160
specs + ['-a', 'host', '-a', 'style', '-a', 'auth'] +
72-
['--', '-w', 'user,app,noauth', '-m', 'base', '-c', 'DropboxBase', '-t', 'dropbox']),
73-
cwd=stone_path)
61+
['--', '-w', 'user,app,noauth', '-m', 'base', '-c', 'DropboxBase', '-t', 'dropbox']))
7462
if o:
7563
print('Output:', o)
7664

7765
o = subprocess.check_output(
7866
(['python', '-m', 'stone.cli', 'python_client', dropbox_pkg_path] +
7967
specs + ['-a', 'host', '-a', 'style', '-a', 'auth'] +
80-
['--', '-w', 'team', '-m', 'base_team', '-c', 'DropboxTeamBase', '-t', 'dropbox']),
81-
cwd=stone_path)
68+
['--', '-w', 'team', '-m', 'base_team', '-c', 'DropboxTeamBase', '-t', 'dropbox']))
8269
if o:
8370
print('Output:', o)
8471

0 commit comments

Comments
 (0)