Skip to content

Commit

Permalink
feat: sdk deployment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed Nov 19, 2024
1 parent cb1d491 commit 79ed1a7
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/deploy-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy NPM Package

on:
workflow_dispatch:
inputs:
version:
description: "Version to publish (e.g., 1.0.0)"
default: "1.0.0"
required: true

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9.11.0

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: lts/Iron
cache: 'pnpm'

- name: Install dependencies
run: pnpm install -r --frozen-lockfile

- name: Build the package
run: pnpm nx run build sdk

- name: Prepare package.json
working-directory: packages/sdk
run: node prepare-package.mjs
env:
INPUT_VERSION: ${{ github.event.inputs.version }}

- name: Publish to NPM
working-directory: packages/sdk
env:
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_NPM_MATTERLABS_AUTOMATION_TOKEN }}
run: npm publish --access public
40 changes: 40 additions & 0 deletions .github/workflows/temp-deploy-package-auto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Temp Deploy NPM Package

on:
pull_request:

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9.11.0

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: lts/Iron
cache: 'pnpm'

- name: Install dependencies
run: pnpm install -r --frozen-lockfile

- name: Build the package
run: pnpm nx run build sdk

- name: Prepare package.json
working-directory: packages/sdk
run: node prepare-package.mjs
env:
INPUT_VERSION: "0.0.0-beta.1"

- name: Publish to NPM
working-directory: packages/sdk
env:
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_NPM_MATTERLABS_AUTOMATION_TOKEN }}
run: npm publish --access public
10 changes: 10 additions & 0 deletions packages/sdk/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore everything by default
*

# Include specific files and folders
!dist/
!src/
!README.md

# Ignore unnecessary files
*.tsbuildinfo
1 change: 1 addition & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"private": true,
"type": "module",
"name": "zksync-sso",
"description": "ZKsync Smart Sign On SDK",
Expand Down
39 changes: 39 additions & 0 deletions packages/sdk/prepare-package.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { promises as fs } from "fs";
import path from "path";

// Define the path to the package.json
const packageJsonPath = path.resolve("./package.json");
console.log(packageJsonPath);

// Get the version from environment variables
const version = process.env.INPUT_VERSION;
if (!version) {
console.error("Error: INPUT_VERSION is required.");
process.exit(1);
}

async function preparePackageJson() {
try {
// Read the existing package.json
const packageJsonData = await fs.readFile(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonData);

// Remove unnecessary properties
delete packageJson.private;
delete packageJson.type;
delete packageJson.publishConfig;

// Set the new version
packageJson.version = version;

// Write the updated package.json back to the file
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));

console.log(`Updated package.json for version ${version}`);
} catch (error) {
console.error("Error updating package.json:", error);
process.exit(1);
}
}

preparePackageJson();

0 comments on commit 79ed1a7

Please sign in to comment.