spec-updated #200
This file contains hidden or 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: Auto Proto Convert | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| opensearch_version: | |
| description: 'OpenSearch version. Leave empty to fetch latest.' | |
| required: false | |
| type: string | |
| repository_dispatch: | |
| types: [spec-updated] | |
| jobs: | |
| auto-proto-convert: | |
| runs-on: ubuntu-latest | |
| # if: github.repository == 'opensearch-project/opensearch-protobufs' | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 20 | |
| - name: Setup Java | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| - name: Download Release Assets | |
| uses: robinraju/release-downloader@v1 | |
| with: | |
| repository: 'lucy66hw/opensearch-api-specification' | |
| latest: true | |
| fileName: 'opensearch-openapi.yaml' | |
| tag: 'main-latest' | |
| preRelease: true | |
| - name: Get Latest Commit ID | |
| id: get_commit | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const owner = "opensearch-project"; | |
| const repo = "opensearch-api-specification"; | |
| const commits = await github.rest.repos.listCommits({ | |
| owner, | |
| repo, | |
| sha: "main", | |
| per_page: 1 | |
| }); | |
| const latestCommit = commits.data[0].sha; | |
| core.setOutput("latest_commit", latestCommit); | |
| console.log("Latest commit: " + latestCommit); | |
| - name: Get Latest OpenSearch Core Version | |
| id: get_opensearch_version | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| // Check if version was provided as input | |
| const inputVersion = "${{ inputs.opensearch_version }}"; | |
| if (inputVersion && inputVersion.trim() !== "") { | |
| core.setOutput("version", inputVersion.trim()); | |
| console.log("Using provided OpenSearch version: " + inputVersion.trim()); | |
| return; | |
| } | |
| // Otherwise fetch version from buildSrc/version.properties on main branch | |
| try { | |
| const response = await github.request( | |
| 'GET /repos/{owner}/{repo}/contents/{path}', | |
| { | |
| owner: 'opensearch-project', | |
| repo: 'OpenSearch', | |
| path: 'buildSrc/version.properties', | |
| ref: 'main' | |
| } | |
| ); | |
| // Decode the file content | |
| const content = Buffer.from(response.data.content, 'base64').toString('utf-8'); | |
| // Extract opensearch version (e.g., "opensearch = 3.4.0") | |
| const match = content.match(/opensearch\s*=\s*([^\s]+)/); | |
| if (match && match[1]) { | |
| const version = match[1].trim(); | |
| core.setOutput("version", version); | |
| console.log("Fetched OpenSearch version from source: " + version); | |
| } else { | |
| core.setFailed("Could not find opensearch version in gradle/libs.versions.toml"); | |
| } | |
| } catch (error) { | |
| core.setFailed("Could not fetch OpenSearch version: " + error.message); | |
| } | |
| - name: Run Proto Conversion | |
| env: | |
| OPENSEARCH_VERSION: ${{ steps.get_opensearch_version.outputs.version }} | |
| run: npm ci && npm run preprocessing -- --opensearch-version "$OPENSEARCH_VERSION" | |
| - name: Clone Protobuf Generator Repository | |
| run: | | |
| git clone https://github.com/OpenAPITools/openapi-generator cloned-repo | |
| cd cloned-repo | |
| git checkout 6699ecd9d2f4e0868f23bb36566ea03cd1230e6a | |
| - name: Build Protobuf Generator Tool | |
| run: | | |
| cd cloned-repo | |
| ./mvnw clean package | |
| - name: Convert protobuf | |
| run: | | |
| java -jar cloned-repo/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -c tools/proto-convert/src/config/protobuf-generator-config.yaml | |
| - name: Post Process Protobuf | |
| id: merge_report | |
| run: | | |
| npm run postprocessing:report | |
| if [ -f /tmp/merge-report.md ]; then | |
| # Escape for GitHub Actions multiline output | |
| REPORT=$(cat /tmp/merge-report.md) | |
| echo "report<<EOF" >> $GITHUB_OUTPUT | |
| echo "$REPORT" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| else | |
| echo "report=No changes detected." >> $GITHUB_OUTPUT | |
| fi | |
| - name: Configure Git User | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Check for changes | |
| id: check_changes | |
| run: | | |
| if [ -z "$(git status --porcelain)" ]; then | |
| echo "No changes detected." | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Changes detected." | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create Pull Request if changes exist | |
| if: steps.check_changes.outputs.changed == 'true' | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| branch: auto-pr-branch | |
| commit-message: "Protobuf schema change detected" | |
| title: "[Automated PR]: Update generated protobuf schema (OpenSearch: ${{ steps.get_opensearch_version.outputs.version }}, spec commit: ${{ steps.get_commit.outputs.latest_commit }})" | |
| signoff: true | |
| base: main | |
| delete-branch: true | |
| labels: skip-changelog | |
| body: | | |
| This pull request was automatically generated by GitHub Actions. | |
| **OpenSearch Version**: ${{ steps.get_opensearch_version.outputs.version }} | |
| **API Spec Commit**: ${{ steps.get_commit.outputs.latest_commit }} | |
| --- | |
| ${{ steps.merge_report.outputs.report }} |