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

[RHCLOUD-34615] Cronjob to automatically generate clients and open a PR when API change is available #300

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 50 additions & 0 deletions .github/release-alpha/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Release alpha job
description: build affected packages and publish them to npm with an alpha tag
inputs:
npm_token:
description: 'NPM token'
required: true
gh_token:
description: 'Github token'
required: true
gh_name:
description: 'Github name'
required: true
gh_email:
description: 'Github email'
required: true
runs:
using: "composite"
steps:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- uses: './.github/actions/node-cache'
- name: Install deps
shell: bash
run: npm i
- name: git config
shell: bash
run: |
git config user.name "${{ inputs.gh_name }}"
git config user.email "${{ inputs.gh_email }}"
- name: Build
shell: bash
run: npx nx run-many -t build --exclude=@redhat-cloud-services/CLIENTNAME-client
- name: Set publish config
env:
NPM_TOKEN: ${{ inputs.npm_token }}
shell: bash
run: npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
- name: Version
shell: bash
env:
GH_TOKEN: ${{ inputs.gh_token }}
GITHUB_TOKEN: ${{ inputs.gh_token }}
run: npx nx affected --base=last-release --parallel=1 --target=version --postTargets=npm,github --trackDeps --releaseAs=prerelease --preid=alpha --exclude=@redhat-cloud-services/CLIENTNAME-client
- name: Tag last-release
shell: bash
run: |
git tag -f last-release
git push origin last-release --force
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
release:
runs-on: ubuntu-latest
needs: [install, lint, test, build]
if: github.event_name != 'pull_request'
if: ${{ github.event_name != 'pull_request' && !startsWith(github.event.head_commit.message, 'Syncing APIs and Generating Clients') }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -66,3 +66,18 @@ jobs:
npm_token: ${{ secrets.NPM_TOKEN }}
gh_name: ${{ secrets.GH_NAME }}
gh_email: ${{ secrets.GH_EMAIL }}
release-alpha:
runs-on: ubuntu-latest
needs: [install, lint, test, build]
if: startsWith(github.event.head_commit.message, 'Syncing APIs and Generating Clients')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: ${{ secrets.BOT_SSH_KEY}}
- uses: './.github/actions/release-alpha'
with:
gh_token: ${{ secrets.BOT_GH_TOKEN }}
npm_token: ${{ secrets.NPM_TOKEN }}
gh_name: ${{ secrets.GH_NAME }}
gh_email: ${{ secrets.GH_EMAIL }}
52 changes: 52 additions & 0 deletions .github/workflows/sync-apis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This workflow will review the current status of the APIs.
# If there are updates in the APIs, it will re-generate the clients and open a PR with the change.

name: Syncing APIs and Generating Clients

on:
schedule:
- cron: "0 0 * * *"
push:
branches: [ "main" ]


jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.BOT_GH_TOKEN }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install Java and Maven
uses: actions/setup-java@4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- run: npm install
- name: Generate clients
# TODO: NX only generate with alpha version tag!
run: npm run nx:reset && npm run generate
- name: Build packages
run: npm run build:no-cache
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.BOT_GH_TOKEN }}
title: Syncing APIs and Generating Clients
body: |
There were some changes in the contents of the APIs.

Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action
commit-message: Syncing API
delete-branch: true
author: "GitHub <[email protected]>"