From 0784e0a7a28245292d2dc89540fd420570ffa1c2 Mon Sep 17 00:00:00 2001 From: Tahmid Efaz Date: Fri, 11 Oct 2024 17:05:58 -0400 Subject: [PATCH 1/2] initial cronjob with basic functionalities --- .github/workflows/sync-apis.yml | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/sync-apis.yml diff --git a/.github/workflows/sync-apis.yml b/.github/workflows/sync-apis.yml new file mode 100644 index 00000000..4b4218dc --- /dev/null +++ b/.github/workflows/sync-apis.yml @@ -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: Sync 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 " From 34b0613f8742dd93fad0158b0981495097213f4e Mon Sep 17 00:00:00 2001 From: Tahmid Efaz Date: Wed, 16 Oct 2024 16:12:55 -0400 Subject: [PATCH 2/2] enabling publishing to npm with an alpha tag --- .github/release-alpha/action.yaml | 50 +++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 17 ++++++++++- .github/workflows/sync-apis.yml | 2 +- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 .github/release-alpha/action.yaml diff --git a/.github/release-alpha/action.yaml b/.github/release-alpha/action.yaml new file mode 100644 index 00000000..fbbff81b --- /dev/null +++ b/.github/release-alpha/action.yaml @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8214c6c6..279a1e8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 }} diff --git a/.github/workflows/sync-apis.yml b/.github/workflows/sync-apis.yml index 4b4218dc..b78e30c6 100644 --- a/.github/workflows/sync-apis.yml +++ b/.github/workflows/sync-apis.yml @@ -1,7 +1,7 @@ # 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: Sync APIs and Generating Clients +name: Syncing APIs and Generating Clients on: schedule: