[Github Actions] Copy OpenAPI spec v3.156.0 from monorepo #166
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: Update NodeJS SDK | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| reason: | |
| description: 'Reason for manual trigger' | |
| required: false | |
| default: 'Manual trigger' | |
| repository_dispatch: | |
| types: [oas-updated] | |
| jobs: | |
| update-sdk: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Dump GitHub context # Makes it much easier to retrospectively debug all sorts of workflow issues. Does NOT expose secrets. | |
| env: | |
| GITHUB_CONTEXT: ${{ toJson(github) }} | |
| run: echo "$GITHUB_CONTEXT" | |
| - name: Generate Neynar CI Bot token | |
| id: generate-token | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.NEYNAR_CI_BOT_APP_ID }} | |
| private-key: ${{ secrets.NEYNAR_CI_BOT_PRIVATE_KEY }} | |
| owner: "neynarxyz" | |
| repositories: "nodejs-sdk" | |
| - name: Checkout OAS repository | |
| uses: actions/checkout@v3 | |
| - name: Checkout nodejs-sdk repository | |
| uses: actions/checkout@v3 | |
| with: | |
| repository: "neynarxyz/nodejs-sdk.git" | |
| ref: "main" | |
| path: "nodejs-sdk" | |
| token: ${{ steps.generate-token.outputs.token }} | |
| submodules: recursive | |
| persist-credentials: true | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: ">=19.9.0" | |
| - name: Update OAS submodule and package version in nodejs-sdk | |
| run: | | |
| # Get the author information from the OAS commit | |
| AUTHOR_NAME=$(git log -1 --format='%an') | |
| AUTHOR_EMAIL=$(git log -1 --format='%ae') | |
| cd nodejs-sdk | |
| # Update OAS submodule | |
| git submodule update --remote oas | |
| # Set Git config using OAS commit author | |
| git config user.name "$AUTHOR_NAME (via Neynar CI Bot)" | |
| git config user.email "$AUTHOR_EMAIL" | |
| # Parse version from OAS | |
| # Install yq for YAML parsing | |
| sudo wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/v4.24.5/yq_linux_amd64 | |
| sudo chmod +x /usr/bin/yq | |
| SDK_VERSION=$(yq e '.info."version"' oas/src/api/spec.yaml) | |
| echo "SDK Version: $SDK_VERSION" | |
| # Check if SDK_VERSION is empty | |
| if [ -z "$SDK_VERSION" ]; then | |
| echo "Error: version not found in OAS file." | |
| exit 1 | |
| fi | |
| # Generate code | |
| yarn install | |
| yarn generate:all | |
| yarn build | |
| # Update package.json version | |
| npm version --no-git-tag-version "$SDK_VERSION" || true | |
| # Stage and commit any changes | |
| if git diff --quiet; then | |
| echo "No changes to commit." | |
| exit 0 | |
| fi | |
| git add . | |
| git commit -m "[GitHub Actions] Generate NodeJS SDK v$SDK_VERSION from OAS repo" | |
| # Push directly to main using the bot credentials | |
| git push origin main | |
| shell: bash |