Skip to content

Commit

Permalink
Publish to NPM and GitHub (#2)
Browse files Browse the repository at this point in the history
* Publish to NPM and GitHub

* Update CI

* Update main workflow

* Update token
  • Loading branch information
aryzing authored Sep 3, 2024
1 parent aa25c25 commit d267073
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/ci-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ jobs:
- name: Run CI
run: bun run ci

- name: Prepare .npmrc for publishing
- name: Publish to NPM package registry
# https://github.com/oven-sh/bun/issues/1976
run: |
echo "@secretkeylabs:registry=https://registry.npmjs.org/" > .npmrc
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
echo "//registry.npmjs.org/:_authToken=$AUTH_TOKEN" >> .npmrc
bunx npm@latest publish --access=public --tag=latest
env:
NPM_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }}
AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }}

- name: Publish to NPM package registry
- name: Publish to GitHub package registry
# https://github.com/oven-sh/bun/issues/1976
run: bunx npm@latest publish --access=public --tag=latest
run: |
echo "@secretkeylabs:registry=https://npm.pkg.github.com/" > .npmrc
echo "//npm.pkg.github.com/:_authToken=$AUTH_TOKEN" >> .npmrc
bunx npm@latest publish --access=public --tag=latest
env:
AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 12 additions & 7 deletions .github/workflows/ci-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ jobs:
name: Get commit sha
run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Set publish version
- name: Set package version with commit sha
# https://github.com/oven-sh/bun/issues/1976
run: bunx npm@latest version --no-git-tag-version $CURRENT_VERSION-$SHA
env:
SHA: ${{ steps.sha.outputs.SHA }}
CURRENT_VERSION: ${{ steps.current-version.outputs.CURRENT_VERSION }}

- name: Prepare .npmrc for publishing
- name: Publish to NPM package registry
# https://github.com/oven-sh/bun/issues/1976
run: |
echo "@secretkeylabs:registry=https://registry.npmjs.org/" > .npmrc
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
echo "//registry.npmjs.org/:_authToken=$AUTH_TOKEN" >> .npmrc
bunx npm@latest publish --access=public
env:
NPM_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }}
AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }}

- name: Publish to NPM package registry
- name: Publish to GitHub package registry
# https://github.com/oven-sh/bun/issues/1976
run: bunx npm@latest publish --access=public --tag pr-$PR_NUMBER
run: |
echo "@secretkeylabs:registry=https://npm.pkg.github.com/" > .npmrc
echo "//npm.pkg.github.com/:_authToken=$AUTH_TOKEN" >> .npmrc
bunx npm@latest publish --access=public
env:
PR_NUMBER: ${{ github.event.number }}
AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Use defaults
{}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@secretkeylabs/stacks-tools",
"version": "0.1.0",
"version": "0.2.0",
"type": "module",
"files": [
"dist"
Expand Down
34 changes: 26 additions & 8 deletions src/queries/get-signer-total-locked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ import {
type SafeError,
} from "../utils/safe.js";

export type Args = {
export type Identifier =
| {
type: "address";
signerAddress: string;
}
| {
type: "publicKey";
signerPublicKey: string;
};

export type Args = { identifier: Identifier } & {
cycleNumber: number;
signerAddress: string;
} & ApiRequestOptions;

/**
Expand All @@ -21,7 +30,7 @@ export async function getSignerTotalLocked(
): Promise<Result<bigint, SafeError<"SignerNotFound" | string>>> {
let totalLocked = 0n;

const { signerAddress, ...rest } = args;
const { identifier, ...rest } = args;

let hasMore = true;
let offset = 0;
Expand All @@ -46,10 +55,18 @@ export async function getSignerTotalLocked(
}

for (const signer of data.results) {
if (signer.signer_address === signerAddress) {
totalLocked = BigInt(signer.stacked_amount);
found = true;
break;
if (identifier.type === "address") {
if (signer.signer_address === identifier.signerAddress) {
totalLocked = BigInt(signer.stacked_amount);
found = true;
break;
}
} else {
if (signer.signing_key === identifier.signerPublicKey) {
totalLocked = BigInt(signer.stacked_amount);
found = true;
break;
}
}
}

Expand All @@ -62,7 +79,8 @@ export async function getSignerTotalLocked(
name: "SignerNotFound",
message: "Signer not found.",
data: {
signerAddress,
identifier,
cycle: args.cycleNumber,
},
});
}
Expand Down

0 comments on commit d267073

Please sign in to comment.