diff --git a/.github/workflows/generate-client-node.yaml b/.github/workflows/generate-client-node.yaml index 1ff151799..2e328108b 100644 --- a/.github/workflows/generate-client-node.yaml +++ b/.github/workflows/generate-client-node.yaml @@ -1,4 +1,4 @@ -name: Node.js Client Generation +name: Generate / Node SDK permissions: contents: write @@ -17,42 +17,23 @@ jobs: generate: runs-on: ubuntu-latest steps: - - uses: actions/create-github-app-token@v1 - id: app-token + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: - app-id: ${{ vars.BOT_APP_ID }} - private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }} - - uses: actions/checkout@v4 - with: - token: ${{ steps.app-token.outputs.token }} ref: ${{ github.head_ref }} - # Make sure the value of GITHUB_TOKEN will not be persisted in repo's config - persist-credentials: false - - uses: pnpm/action-setup@v3 - with: - version: 8 - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: "20" - cache: "pnpm" - cache-dependency-path: "./api/client/node/pnpm-lock.yaml" - - name: Install Dependencies - run: pnpm install --frozen-lockfile - working-directory: ./api/client/node + - name: Generate Client - run: pnpm run generate - working-directory: ./api/client/node - - name: Build Client - run: pnpm build - working-directory: ./api/client/node - - name: Run tests - run: pnpm test - working-directory: ./api/client/node + uses: dagger/dagger-for-github@eba69b4dddb54eddfdb51a88eb7fd86957137630 # v5.4.0 + with: + verb: call + args: --source .:default generate node-sdk -o api/client/node + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} + version: "0.11.2" + - name: Open Pull Request uses: peter-evans/create-pull-request@v6 with: - branch: openapi/node-client + branch: openapi/node-sdk branch-suffix: short-commit-hash delete-branch: true commit-message: "chore(api): generate node client" @@ -61,4 +42,4 @@ jobs: labels: | area/api release-note/misc - token: ${{ steps.app-token.outputs.token }} + token: ${{ secrets.BOT_GITHUB_TOKEN }} diff --git a/.github/workflows/generate-client-web.yaml b/.github/workflows/generate-client-web.yaml index 8fddc5c5d..cca55eb95 100644 --- a/.github/workflows/generate-client-web.yaml +++ b/.github/workflows/generate-client-web.yaml @@ -1,4 +1,4 @@ -name: Web Client Generation +name: Generate / Web SDK permissions: contents: write @@ -17,36 +17,23 @@ jobs: generate: runs-on: ubuntu-latest steps: - - uses: actions/create-github-app-token@v1 - id: app-token + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: - app-id: ${{ vars.BOT_APP_ID }} - private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }} - - uses: actions/checkout@v4 - with: - token: ${{ steps.app-token.outputs.token }} ref: ${{ github.head_ref }} - # Make sure the value of GITHUB_TOKEN will not be persisted in repo's config - persist-credentials: false - - uses: pnpm/action-setup@v3 - with: - version: 8 - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: "20" - cache: "pnpm" - cache-dependency-path: "./api/client/web/pnpm-lock.yaml" - - name: Install Dependencies - run: pnpm install --frozen-lockfile - working-directory: ./api/client/web + - name: Generate Client - run: pnpm run generate - working-directory: ./api/client/web + uses: dagger/dagger-for-github@eba69b4dddb54eddfdb51a88eb7fd86957137630 # v5.4.0 + with: + verb: call + args: --source .:default generate web-sdk -o api/client/web + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} + version: "0.11.2" + - name: Open Pull Request uses: peter-evans/create-pull-request@v6 with: - branch: openapi/web-client + branch: openapi/web-sdk branch-suffix: short-commit-hash delete-branch: true commit-message: "chore(api): generate web client" @@ -55,4 +42,4 @@ jobs: labels: | area/api release-note/misc - token: ${{ steps.app-token.outputs.token }} + token: ${{ secrets.BOT_GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index dd081bb24..3ff41ce86 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -41,9 +41,10 @@ jobs: with: verb: call module: github.com/${{ github.repository }}@${{ github.ref }} - args: --ref ${{ github.ref }} release --version ${{ github.ref_name }} --github-actor ${{ github.actor }} --github-token env:GITHUB_TOKEN --pypi-token env:PYPI_TOKEN + args: --ref ${{ github.ref }} release --version ${{ github.ref_name }} --github-actor ${{ github.actor }} --github-token env:GITHUB_TOKEN --pypi-token env:PYPI_TOKEN --npm-token env:NPM_TOKEN cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} version: "0.11.2" env: GITHUB_TOKEN: ${{ github.token }} PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/ci/generate.go b/ci/generate.go index cd0157fdd..eb7639968 100644 --- a/ci/generate.go +++ b/ci/generate.go @@ -30,3 +30,29 @@ func (m *Generate) PythonSdk() *Directory { WithExec([]string{"autorest", "config.yaml"}). Directory("/work/client/python") } + +// Generate the Node SDK. +func (m *Generate) NodeSdk() *Directory { + return dag.Container(). + From("node:20-alpine"). + WithExec([]string{"npm", "install", "-g", "pnpm"}). + WithDirectory("/work", m.Source.Directory("api")). + WithWorkdir("/work/client/node"). + WithExec([]string{"pnpm", "install", "--frozen-lockfile"}). + WithExec([]string{"pnpm", "run", "generate"}). + WithExec([]string{"pnpm", "build"}). + WithExec([]string{"pnpm", "test"}). + Directory("/work/client/node") +} + +// Generate the Web SDK. +func (m *Generate) WebSdk() *Directory { + return dag.Container(). + From("node:20-alpine"). + WithExec([]string{"npm", "install", "-g", "pnpm"}). + WithDirectory("/work", m.Source.Directory("api")). + WithWorkdir("/work/client/web"). + WithExec([]string{"pnpm", "install", "--frozen-lockfile"}). + WithExec([]string{"pnpm", "run", "generate"}). + Directory("/work/client/web") +} diff --git a/ci/main.go b/ci/main.go index 45e153630..474f990e4 100644 --- a/ci/main.go +++ b/ci/main.go @@ -75,6 +75,8 @@ func (m *Ci) Ci(ctx context.Context) error { wrapSyncables(m.releaseAssets("ci")), wrapSyncable(m.Generate().PythonSdk()), + wrapSyncable(m.Generate().NodeSdk()), + wrapSyncable(m.Generate().WebSdk()), ) return p.wait() diff --git a/ci/release.go b/ci/release.go index c7cad8a8e..0e4b0da42 100644 --- a/ci/release.go +++ b/ci/release.go @@ -8,7 +8,7 @@ import ( "time" ) -func (m *Ci) Release(ctx context.Context, version string, githubActor string, githubToken *Secret, pypiToken *Secret) error { +func (m *Ci) Release(ctx context.Context, version string, githubActor string, githubToken *Secret, pypiToken *Secret, npmToken *Secret) error { p := newPipeline(ctx) p.addJobs( @@ -43,6 +43,12 @@ func (m *Ci) Release(ctx context.Context, version string, githubActor string, gi func(ctx context.Context) error { return m.publishPythonSdk(ctx, version, pypiToken) }, + func(ctx context.Context) error { + return m.publishNodeSdk(ctx, version, npmToken) + }, + func(ctx context.Context) error { + return m.publishWebSdk(ctx, version, npmToken) + }, ) return p.wait() @@ -120,3 +126,29 @@ func (m *Ci) publishPythonSdk(ctx context.Context, version string, pypiToken *Se return err } + +func (m *Ci) publishNodeSdk(ctx context.Context, version string, npmToken *Secret) error { + // TODO: generate SDK on the fly? + return m.publishToNpm(ctx, m.Source.Directory("api/client/node"), version, npmToken) +} + +func (m *Ci) publishWebSdk(ctx context.Context, version string, npmToken *Secret) error { + // TODO: generate SDK on the fly? + return m.publishToNpm(ctx, m.Source.Directory("api/client/web"), version, npmToken) +} + +func (m *Ci) publishToNpm(ctx context.Context, pkg *Directory, version string, npmToken *Secret) error { + _, err := dag.Container(). + From("node:20-alpine"). + WithExec([]string{"npm", "install", "-g", "pnpm"}). + WithExec([]string{"sh", "-c", "echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > /root/.npmrc"}). + WithDirectory("/work", pkg). + WithExec([]string{"pnpm", "install", "--frozen-lockfile"}). + WithExec([]string{"pnpm", "version", version, "--no-git-tag-version"}). + WithEnvVariable("CACHE_BUSTER", time.Now().Format(time.RFC3339Nano)). + WithSecretVariable("NPM_TOKEN", npmToken). + WithExec([]string{"pnpm", "--access=public", "--no-git-checks"}). + Sync(ctx) + + return err +}