Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an automated api update bot for opensearch-py #664

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/update_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Update API
on:
workflow_dispatch:
schedule:
- cron: "30 3 * * *"
jobs:
update-api:
if: ${{ github.repository == 'opensearch-project/opensearch-py' }}
runs-on: ubuntu-latest
permissions:
saimedhi marked this conversation as resolved.
Show resolved Hide resolved
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Config git to rebase
run: git config --global pull.rebase true
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install dependencies
run: |
python3.7 -m pip install nox
- name: Generate API
run: nox -s generate
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: GitHub App token
id: github_app_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
installation_id: 22958780
- name: Create pull request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
saimedhi marked this conversation as resolved.
Show resolved Hide resolved
commit-message: Updated opensearch-py to reflect the latest OpenSearch API spec (${{ steps.date.outputs.date }})
title: Updated opensearch-py to reflect the latest OpenSearch API spec
body: |
Updated [opensearch-py](https://github.com/opensearch-project/opensearch-py) to reflect the latest [OpenSearch API spec](https://github.com/opensearch-project/opensearch-api-specification/blob/main/OpenSearch.openapi.json)
Date: ${{ steps.date.outputs.date }}
branch: automated-api-update
base: main
committer: opensearchpy-api-update-bot <[email protected]>
author: opensearchpy-api-update-bot <[email protected]>
saimedhi marked this conversation as resolved.
Show resolved Hide resolved
- name: Check out update branch
if: ${{ steps.cpr.outputs.pull-request-number != '' }}
run: |
git fetch origin automated-api-update
git checkout automated-api-update
- name: Update CHANGELOG
uses: jacobtomlinson/gha-find-replace@v3
if: ${{ steps.cpr.outputs.pull-request-number != '' }}
with:
find: "- Your contribution here."
replace: "- Updated opensearch-py to reflect the latest OpenSearch API spec ([#${{steps.cpr.outputs.pull-request-number}}](https://github.com/opensearch-project/opensearch-py/pull/${{steps.cpr.outputs.pull-request-number}}))\n- Your contribution here."
include: "**CHANGELOG.md"
- name: Commit and Push
if: ${{ steps.cpr.outputs.pull-request-number != '' }}
run: |
git config --local user.name 'opensearchpy-api-update-bot'
saimedhi marked this conversation as resolved.
Show resolved Hide resolved
git config --local user.email '[email protected]'
git config --local --unset-all http.https://github.com/.extraheader || true
AUTH=$(echo -n "x-access-token:${{ steps.github_app_token.outputs.token || secrets.GITHUB_TOKEN }}" | base64)
echo "::add-mask::${AUTH}"
git config --local http.https://github.com/.extraheader "AUTHORIZATION: basic ${AUTH}"
git add CHANGELOG.md
git commit --amend --no-edit
git push origin automated-api-update -f
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added a log collection guide ([#579](https://github.com/opensearch-project/opensearch-py/pull/579))
- Added GHA release ([#614](https://github.com/opensearch-project/opensearch-py/pull/614))
- Incorporated API generation into CI workflow and fixed 'generate' nox session ([#660](https://github.com/opensearch-project/opensearch-py/pull/660))
- Added an automated api update bot for opensearch-py ([#664](https://github.com/opensearch-project/opensearch-py/pull/664))
### Changed
- Updated the `get_policy` API in the index_management plugin to allow the policy_id argument as optional ([#633](https://github.com/opensearch-project/opensearch-py/pull/633))
- Updated the `point_in_time.md` guide with examples demonstrating the usage of the new APIs as alternatives to the deprecated ones. ([#661](https://github.com/opensearch-project/opensearch-py/pull/661))
Expand All @@ -21,6 +22,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
- Fix KeyError when scroll return no hits ([#616](https://github.com/opensearch-project/opensearch-py/pull/616))
- Fix reuse of `OpenSearch` using `Urllib3HttpConnection` and `AsyncOpenSearch` after calling `close` ([#639](https://github.com/opensearch-project/opensearch-py/pull/639))
### Automated API Update
- Your contribution here.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line Your contribution here needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line Your contribution here needed?

Yes, to update changelog, find and replace is used. We can change the text if required.

Copy link
Member

@dblock dblock Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could reuse the title line, then you don't need the misleading "Your contribution here.", "### Automated API Update". Maybe call it "Updated APIs" to match the other sections language?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Trying to find a way to update only in ## [Unreleased] section.

  • If "### Updated APIs" is used for finding, it will be present in changelog at several places in future after next release.

  • Action jacobtomlinson/gha-find-replace@v3 will not help if ### Updated APIs is present in several places.

- name: Update CHANGELOG
        uses: jacobtomlinson/gha-find-replace@v3
        with:
          find: "### Updated APIs"
          replace: "### Updated APIs\n- Updated opensearch-py to reflect the latest OpenSearch API spec."
          include: "**CHANGELOG.md"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I think that action could use a "replace first occurrence" feature, I took a look at the project and started with adding some unit tests - jacobtomlinson/gha-find-replace#61. Will follow up with that feature if it gets merged.

### Security
### Dependencies
- Bumps `pytest-asyncio` from <=0.21.1 to <=0.23.4
Expand Down
Loading