From 14ddfc4a8703d38f58e9513e8ec8e87a6c42258a Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 17 Sep 2020 17:15:26 -0700 Subject: [PATCH 1/4] Add github action to auto update spec --- .github/workflows/spec_update.yml | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/spec_update.yml diff --git a/.github/workflows/spec_update.yml b/.github/workflows/spec_update.yml new file mode 100644 index 00000000..ac0084f3 --- /dev/null +++ b/.github/workflows/spec_update.yml @@ -0,0 +1,73 @@ +name: Spec Update +on: + workflow_dispatch: + pull_request: + schedule: + - cron: 0 0 * * * + +jobs: + Update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python environment + uses: actions/setup-python@v2.1.2 + with: + python-version: 2.7 + - name: Get current time + uses: 1466587594/get-current-time@v2 + id: current-time + with: + format: YYYY_MM_DD + utcOffset: "-08:00" + - name: Install SDK + run: | + npm install + - name: Update Modules + run: | + git submodule init + git submodule update --remote --recursive + - name: Generate Branch Name + id: git-branch + run: | + echo "::set-output name=branch::spec_update_${{ steps.current-time.outputs.formattedTime }}" + - name: Generate Num Diffs + id: git-diff-num + run: | + diffs=$(git diff --submodule spec | grep ">" | wc -l) + echo "Number of Spec diffs: $diffs" + echo "::set-output name=num-diff::$diffs" + - name: Generate Diff + id: git-diff + run: | + cd spec + gitdiff=$(git log -n ${{ steps.git-diff-num.outputs.num-diff }} --pretty="format:%n %H %n%n %b") + commit="Automated Spec Update $gitdiff" + commit="${commit//'%'/'%25'}" + commit="${commit//$'\n'/'%0A'}" + commit="${commit//$'\r'/'%0D'}" + echo "Commit Message: $commit" + echo "::set-output name=commit::$commit" + cd .. + - name: Generate New Routes + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + python generate_routes.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3.3.0 + if: steps.git-diff-num.outputs.num-diff != 0 + with: + token: ${{ secrets.SPEC_UPDATE_TOKEN }} + commit-message: | + ${{ steps.git-diff.outputs.commit}} + branch: ${{ steps.git-branch.outputs.branch }} + delete-branch: true + title: 'Automated Spec Update' + body: | + ${{ steps.git-diff.outputs.commit}} + base: 'master' + team-reviewers: | + owners + maintainers + draft: false \ No newline at end of file From fd0d4502ede3176d7da952960ca1e3dce7b02b83 Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 17 Sep 2020 17:23:36 -0700 Subject: [PATCH 2/4] Add correct generate script name --- .github/workflows/spec_update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/spec_update.yml b/.github/workflows/spec_update.yml index ac0084f3..1f3c6c57 100644 --- a/.github/workflows/spec_update.yml +++ b/.github/workflows/spec_update.yml @@ -53,7 +53,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - python generate_routes.py + python generate_base_client.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3.3.0 if: steps.git-diff-num.outputs.num-diff != 0 From 57721d4597189b8ef06868bed651ce6e4064f3b9 Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 17 Sep 2020 17:29:25 -0700 Subject: [PATCH 3/4] Fix mistake in generate_base_client when stone was removed as submodule --- generate_base_client.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/generate_base_client.py b/generate_base_client.py index eb8b2359..f9b5b38a 100755 --- a/generate_base_client.py +++ b/generate_base_client.py @@ -24,12 +24,6 @@ type=str, help='Path to API specifications. Each must have a .stone extension.', ) -_cmdline_parser.add_argument( - '-s', - '--stone', - type=str, - help='Path to clone of stone repository.', -) def main(): """The entry point for the program.""" @@ -46,10 +40,6 @@ def main(): specs = [os.path.join(os.getcwd(), s) for s in specs] - stone_path = os.path.abspath('stone') - if args.stone: - stone_path = args.stone - dropbox_pkg_path = os.path.abspath( os.path.join(os.path.dirname(sys.argv[0]), 'dropbox')) if verbose: @@ -60,8 +50,7 @@ def main(): subprocess.check_output( (['python', '-m', 'stone.cli', 'python_types', dropbox_pkg_path] + specs + ['-a', 'host', '-a', 'style'] + - ['--', '-r', 'dropbox.dropbox.Dropbox.{ns}_{route}']), - cwd=stone_path) + ['--', '-r', 'dropbox.dropbox.Dropbox.{ns}_{route}'])) if verbose: print('Generating Python client') @@ -69,16 +58,14 @@ def main(): o = subprocess.check_output( (['python', '-m', 'stone.cli', 'python_client', dropbox_pkg_path] + specs + ['-a', 'host', '-a', 'style', '-a', 'auth'] + - ['--', '-w', 'user,app,noauth', '-m', 'base', '-c', 'DropboxBase', '-t', 'dropbox']), - cwd=stone_path) + ['--', '-w', 'user,app,noauth', '-m', 'base', '-c', 'DropboxBase', '-t', 'dropbox'])) if o: print('Output:', o) o = subprocess.check_output( (['python', '-m', 'stone.cli', 'python_client', dropbox_pkg_path] + specs + ['-a', 'host', '-a', 'style', '-a', 'auth'] + - ['--', '-w', 'team', '-m', 'base_team', '-c', 'DropboxTeamBase', '-t', 'dropbox']), - cwd=stone_path) + ['--', '-w', 'team', '-m', 'base_team', '-c', 'DropboxTeamBase', '-t', 'dropbox'])) if o: print('Output:', o) From 9323d5611f054427598d5cd6b48a447d3e64cf9f Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 17 Sep 2020 17:35:26 -0700 Subject: [PATCH 4/4] Remove on pr --- .github/workflows/spec_update.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/spec_update.yml b/.github/workflows/spec_update.yml index 1f3c6c57..daeab9ed 100644 --- a/.github/workflows/spec_update.yml +++ b/.github/workflows/spec_update.yml @@ -1,7 +1,6 @@ name: Spec Update on: workflow_dispatch: - pull_request: schedule: - cron: 0 0 * * *