Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(js): setup release flow #608

Merged
merged 13 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*.ts text
*.json text
yarn.lock merge=union

# Verify
*.verified.txt text eol=lf working-tree-encoding=UTF-8
*.verified.xml text eol=lf working-tree-encoding=UTF-8
Expand Down
100 changes: 0 additions & 100 deletions .github/workflows/ci-js.yml

This file was deleted.

57 changes: 57 additions & 0 deletions .github/workflows/js-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: '[js] CI'

on:
pull_request:
types: [opened, synchronize, reopened, labeled]
branches: [master]
paths:
- 'js/**'
- 'package.json'
workflow_dispatch:

env:
BINARYEN_VERSION: version_111

jobs:
test:
if: github.event_name == 'pull_request'

runs-on: ubuntu-22.04
env:
RUSTUP_HOME: /tmp/rustup_home
steps:
- name: Cancel previous workflow runs
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v4

- name: 'Install: NodeJS 20.x'
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: 'Install: dependencies'
run: yarn install

- name: 'Prepare: build all'
run: yarn build

- name: 'Prepare: fmt'
run: yarn lint

- name: 'Prepare: download Gear node'
run: |
wget -O ./gear https://github.com/gear-tech/gear/releases/download/build/gear
chmod +x gear

- name: 'Prepare: run Gear node'
run: nohup ./gear --dev --execution=wasm --tmp --unsafe-rpc-external --rpc-methods Unsafe --rpc-cors all &

- name: 'Prepare: sleep 3 min'
run: sleep 180

- name: 'Test: run'
run: yarn test
79 changes: 79 additions & 0 deletions .github/workflows/js-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: '[js] Release'

on:
push:
branches:
- master
paths:
- package.json

jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: 'Setup NodeJS 20.x'
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: 'Get version from package.json'
run: |
VERSION=$(jq -r '.version' package.json)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "TAG_NAME=Sails-JS/v$VERSION" >> $GITHUB_ENV

- name: 'Get previous version from npm registry'
run: |
PREVIOUS_VERSION=$(npm show @js/package version)
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV

- name: 'Compare versions'
run: |
if [ ${{ env.VERSION }} == ${{ env.PREVIOUS_VERSION }} ]; then
echo "No new version to release"
echo "skip=true" >> $GITHUB_ENV
else
echo "New version to release"
echo "skip=false" >> $GITHUB_ENV
fi

- name: 'Get release notes'
if: env.skip != 'true'
run: |
awk '/## ${{ env.VERSION }}/{flag=1;next}/---/{flag=0} flag' ./js/CHANGELOG.md >> release_notes.txt
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
cat release_notes.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
rm release_notes.txt

- name: 'Prepare: install dependencies and build pkgs'
if: env.skip != 'true'
run: |
yarn install
yarn build

- name: 'Create new tag'
if: env.skip != 'true'
run: |
git tag ${{ env.TAG_NAME }}
git push origin ${{ env.TAG_NAME }}

- name: 'Create Release'
if: env.skip != 'true'
uses: softprops/action-gh-release@v2
with:
body: ${{ env.RELEASE_NOTES }}
tag_name: ${{ env.TAG_NAME }}

- name: 'Publish to npm registry'
if: env.skip != 'true'
run: |
export token=$(printenv npm_token)
echo "//registry.npmjs.org/:_authToken=$token" > .npmrc
npx lerna publish from-package --yes --no-private
env:
npm_token: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ net/**/*.trx
node_modules/
js/**/lib/
js/cli/build/
js/parser/parser.wasm
js/test/demo/
.pnp.*
.yarn/*
Expand All @@ -26,6 +25,7 @@ js/test/demo/
!.yarn/sdks
!.yarn/versions
.npmrc
js/parser/parser.wasm

# Verify
*.received.*
Expand Down
9 changes: 9 additions & 0 deletions js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# CHANGELOG

## 0.3.1 (draft)

### Compatibility
- Sails-RS v0.6.3

### Changes
- Setup automated releases in https://github.com/gear-tech/sails/pull/608
2 changes: 1 addition & 1 deletion js/cli/src/generate/types-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class TypesGenerator extends BaseGenerator {
}

public generate() {
this._out.line('declare global {').increaseIndent();
this._out.line('declare global {', false).increaseIndent();
for (const { name, def, docs } of this._program.types) {
this._out.lines(formatDocs(docs), false);

Expand Down
3 changes: 3 additions & 0 deletions js/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sails-rs": "0.6.3"
}
70 changes: 30 additions & 40 deletions js/parser/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
import { writeFileSync, readFileSync, existsSync, rmSync } from 'fs';
import { execSync } from 'child_process';
import { writeFileSync, rmSync } from 'fs';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import config from '../config.json' assert { type: 'json' };

function checkParserFile() {
return {
name: 'check-parser-file',
buildStart() {
if (!existsSync('./parser.wasm')) {
throw new Error('parser.wasm file not found');
}
},
};
async function getStreamFromRelease(version, cs) {
const link = `https://github.com/gear-tech/sails/releases/download/rs%2Fv${version}/sails_idl_parser.wasm`;
const res = await fetch(link);

if (!res.ok) {
throw new Error(`Failed to fetch parser from ${link}`);
}

return res.body.pipeThrough(cs);
}

function compressParser(type) {
return {
name: 'compress-parser',
async closeBundle() {
const buf = readFileSync('./parser.wasm');
async function getBase64Parser(version) {
const cs = new CompressionStream('gzip');

const cs = new CompressionStream('gzip');
const stream = await getStreamFromRelease(version, cs);

const compressedReadableStream = new Response(buf).body.pipeThrough(cs);
const reader = stream.getReader();

const reader = compressedReadableStream.getReader();
let resultArr = [];

let resultArr = [];
while (true) {
const read = await reader.read();

while (true) {
const read = await reader.read();
if (read.done) break;

if (read.done) break;
resultArr = resultArr.concat(Array.from(read.value));
}

resultArr = resultArr.concat(Array.from(read.value));
}
return Buffer.from(Uint8Array.from(resultArr).buffer).toString('base64');
}

const base64Bytes = Buffer.from(Uint8Array.from(resultArr).buffer).toString('base64');
function writeCompressedWasmParser(type) {
return {
name: 'write-wasm-parser',
async closeBundle() {
const base64Bytes = await getBase64Parser(config['sails-rs']);

if (type === 'cjs') {
writeFileSync(
Expand All @@ -59,16 +61,6 @@ function cleanOldBuild() {
};
}

function buildParserWasm() {
return {
name: 'build-parser-wasm',
buildStart() {
execSync('cargo build -p sails-idl-parser --target=wasm32-unknown-unknown --release');
execSync('wasm-opt -O4 -o ./parser.wasm ../../target/wasm32-unknown-unknown/release/sails_idl_parser.wasm');
},
};
}

export default [
{
input: 'src/index.ts',
Expand All @@ -81,13 +73,11 @@ export default [
},
],
plugins: [
buildParserWasm(),
checkParserFile(),
cleanOldBuild(),
typescript({
tsconfig: 'tsconfig.build.json',
}),
compressParser('es'),
writeCompressedWasmParser('es'),
],
},
{
Expand All @@ -107,7 +97,7 @@ export default [
tsconfig: 'tsconfig.cjs.json',
}),
commonjs(),
compressParser('cjs'),
writeCompressedWasmParser('cjs'),
],
},
];
Loading