Skip to content

Commit

Permalink
chore: setup changesets for automated releases (#31)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra authored Feb 3, 2025
1 parent 94b121b commit 99473d1
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 3,949 deletions.
21 changes: 21 additions & 0 deletions .changeset/commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { execSync } = require('node:child_process')

const getSignedOffBy = () => {
const gitUserName = execSync('git config user.name').toString('utf-8').trim()
const gitEmail = execSync('git config user.email').toString('utf-8').trim()

return `Signed-off-by: ${gitUserName} <${gitEmail}>`
}

const getAddMessage = async (changeset) => {
return `docs(changeset): ${changeset.summary}\n\n${getSignedOffBy()}\n`
}

const getVersionMessage = async () => {
return `chore(release): new version\n\n${getSignedOffBy()}\n`
}

module.exports = {
getAddMessage,
getVersionMessage,
}
13 changes: 13 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": "./commit",
"privatePackages": false,
"fixed": [["@openwallet-foundation/*"]],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"snapshot": {
"useCalculatedVersion": true
}
}
86 changes: 0 additions & 86 deletions .github/workflows/build.yml

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Continuous Integration

on:
pull_request_review:

pull_request:
branches:
- main
push:
branches:
- main

jobs:
validate:
if: github.event_name != 'pull_request_review' || github.event.pull_request.head.ref == 'changeset-release/main'
runs-on: ubuntu-20.04
name: Validate
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"

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

- name: Check Style
run: pnpm style:check

- name: Check Types
run: pnpm types:check

- name: Compile
run: pnpm build

tests:
runs-on: ubuntu-20.04
name: Tests
if: github.event_name != 'pull_request_review' || github.event.pull_request.head.ref == 'changeset-release/main'

strategy:
fail-fast: false
matrix:
node-version: [18, 20, 22]

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Setup NodeJS
id: setup-node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

# See https://github.com/actions/setup-node/issues/641#issuecomment-1358859686
- name: pnpm cache path
id: pnpm-cache-path
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache-path.outputs.STORE_PATH }}
key: ${{ runner.os }}-${{ steps.setup-node.outputs.node-version }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-node.outputs.node-version }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run tests
run: pnpm test
102 changes: 102 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release-stable:
runs-on: ubuntu-20.04
name: Release Stable
outputs:
published: ${{ steps.changesets.outputs.published }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"

- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
title: "chore(release): new version"
commit: "chore(release): new version"
publish: pnpm release
version: pnpm changeset-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Get current package version
id: get_version
run: echo "CURRENT_PACKAGE_VERSION=$(node -p "require('./packages/askar-shared/package.json').version")" >> $GITHUB_ENV

- name: Create Github Release
if: steps.changesets.outputs.published == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ env.CURRENT_PACKAGE_VERSION }}

release-unstable:
runs-on: ubuntu-20.04
name: Release Unstable
needs: release-stable
if: always() && github.event_name == 'push' && needs.release-stable.outputs.published == 'false'
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Creating .npmrc
run: |
cat << EOF > ".npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create unstable release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
# this ensures there's always a patch release created
cat << 'EOF' > .changeset/snapshot-template-changeset.md
---
'@openwallet-foundation/askar-shared': patch
---
snapshot release
EOF
pnpm changeset version --snapshot alpha
pnpm style:fix
pnpm build
pnpm changeset publish --tag alpha
CURRENT_PACKAGE_VERSION=$(node -p "require('./packages/askar-shared/package.json').version")
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag v$CURRENT_PACKAGE_VERSION
git push origin v$CURRENT_PACKAGE_VERSION --no-verify
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ packages/askar-nodejs/native
packages/askar-react-native/native
packages/askar-react-native/android/build
packages/askar-react-native/android/.cxx
.gradle

examples/askar-react-native-example/android
examples/askar-react-native-example/ios
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ Wrapper for Node.js and React Native around [https://github.com/openwallet-found

## Requirements

This library requires (and has been tested extensively with) Node.js version `18.x` and React Native version `0.75.x`. Newer versions might also work, but they have not been tested.
This library requires and has been tested with Node.js version `18.x`, `20.x` and `22.x`, or React Native version `0.75.x` and `0.76.x`. Newer versions might also work, but they have not been tested.

## Setup

You can import all types and classes from the `@openwallet-foundation/askar-nodejs` or `@openwalletfoundation/askar-react-native` library:

```typescript
import { Key, KeyAlgs } from '@openwallet-foundation/askar-nodejs'
import { Key, KeyAlgs } from "@openwallet-foundation/askar-nodejs";

const seed = Uint8Array.from(Buffer.from('testseed000000000000000000000001'))
const key = Key.fromSeed({ algorithm: KeyAlgs.Bls12381G1, seed })
const seed = Uint8Array.from(Buffer.from("testseed000000000000000000000001"));
const key = Key.fromSeed({ algorithm: KeyAlgs.Bls12381G1, seed });
```

> **Note**: If you want to use this library in a cross-platform environment you need to import methods from the `@openwallet-foundation/askar-shared` package instead. This is a platform independent package that allows to register the native bindings. The `@openwallet-foundation/askar-nodejs` package uses this package under the hood. See the [Askar Shared README](https://github.com/openwallet-foundation/askar-wrapper-javascript/tree/main/packages/askar-shared/README.md) for documentation on how to use this package.
> **Note**: If you want to use this library in a cross-platform environment you need to import methods from the `@openwallet-foundation/askar-shared` package instead. This is a platform independent package that allows to register the native bindings. The `@openwallet-foundation/askar-nodejs` and `@openwallet-foundation/askar-react-native` packages use this package under the hood. See the [Askar Shared README](https://github.com/openwallet-foundation/askar-wrapper-javascript/tree/main/packages/askar-shared/README.md) for documentation on how to use this package.
## Version Compatibility

The JavaScript wrapper is versioned independently from the native bindings. The following table shows the compatibility between the different versions:

| Askar | JavaScript Wrapper |
| ----------- | ------------------ |
| v0.2.9 | v0.1.x |
| v0.3.x | v0.2.x |
| v0.4.x | v0.3.x |
| Askar | JavaScript Wrapper | React Native |
| ------ | ------------------ | ------------ |
| v0.2.9 | v0.1.x | - |
| v0.3.x | v0.2.x | - |
| v0.4.x | v0.3.x | 0.75, 0.76 |
2 changes: 1 addition & 1 deletion examples/askar-react-native-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"@babel/core": "^7.20.0",
"@babel/runtime": "^7.22.15",
"@types/react": "~18.3.18",
"typescript": "~5.3.3"
"typescript": "catalog:"
}
}
21 changes: 8 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
"build": "pnpm -r build",
"clean": "pnpm -r clean",
"test": "node --import tsx --test packages/**/tests/*.test.ts",
"release": "lerna publish"
"release": "pnpm build && pnpm changeset publish --no-git-tag",
"changeset-version": "pnpm changeset version && pnpm style:fix"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/jest": "^29.5.4",
"@types/node": "^20.12.11",
"jest": "^29.7.0",
"lerna": "^8.1.2",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.19.2",
"typescript": "~5.4.5"
"@biomejs/biome": "catalog:",
"@types/node": "catalog:",
"rimraf": "catalog:",
"tsx": "catalog:",
"typescript": "catalog:"
},
"packageManager": "pnpm@9.7.1+sha512.faf344af2d6ca65c4c5c8c2224ea77a81a5e8859cbc4e06b1511ddce2f0151512431dd19e6aff31f2c6a8f5f2aced9bd2273e1fed7dd4de1868984059d2c4247"
"packageManager": "pnpm@9.15.3+sha256.c1da43727ccbc1ed42aff4fd6bdb4b1e91e65a818e6efff5b240fbf070ba4eaf"
}
Loading

0 comments on commit 99473d1

Please sign in to comment.