updated #48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update OpenSearch API | |
on: [push] | |
jobs: | |
update-api: | |
if: ${{ github.repository == 'saimedhi/opensearch-py' }} | |
runs-on: ubuntu-latest | |
permissions: | |
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 | |
if: ${{ github.repository == 'saimedhi/opensearch-py' }} | |
id: github_app_token | |
uses: tibdex/github-app-token@v2.1.0 | |
with: | |
app_id: ${{ secrets.CI_APP_ID }} | |
private_key: ${{ secrets.CI_APP_PRIVATE_KEY }} | |
- name: Create pull request | |
id: cpr | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
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/saimedhi/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 <noreply@github.com> | |
author: opensearchpy-api-update-bot <noreply@github.com> | |
- name: printed | |
run: | | |
echo "Checking find pattern in CHANGELOG.md..." | |
grep -n "Your contribution here." CHANGELOG.md || echo "Pattern not found." | |
- name: Update CHANGELOG | |
uses: jacobtomlinson/gha-find-replace@v3 | |
if: ${{ steps.cpr.outputs.pull-request-number != '' }} | |
with: | |
branch: automated-api-update | |
find: "Your contribution here." | |
replace: "12345678910" | |
include: "**CHANGELOG.md" | |
- name: Commit and Push | |
if: ${{ steps.cpr.outputs.pull-request-number != '' }} | |
env: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --local user.name 'opensearchpy-api-update-bot' | |
git config --local user.email 'noreply@github.com' | |
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}" | |
add_output=$(git add CHANGELOG.md) | |
commit_output=$(git commit --amend --no-edit) | |
cat CHANGELOG.md | |
PUSH_OUTPUT=$(gh pr merge ${{ steps.cpr.outputs.pull-request-number }} --squash --merge --auto) | |
echo "Git Add Output: $add_output" | |
echo "Git Commit Output: $commit_output" | |
echo "PUSHED_OUTPUT: $PUSH_OUTPUT" | |
- name: List modified files for automated-api-update branch | |
run: | | |
branch_commit=$(git rev-parse automated-api-update) | |
modified_files=$(git diff --name-only $branch_commit ${{ github.sha }}) | |
echo "Modified files for branch automated-api-update:" | |
echo "$modified_files" |