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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*.ts text
*.json text
yarn.lock merge=union
*.wasm binary merge=binary
46 changes: 0 additions & 46 deletions .github/workflows/ci-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ on:
paths-ignore:
- 'net/**'
- 'Sails.Net.sln'
push:
branches: [master]
paths:
- js/**
workflow_dispatch:

env:
BINARYEN_VERSION: version_111

jobs:
test:
if: github.event_name == 'pull_request'
Expand All @@ -40,12 +33,6 @@ jobs:
- name: 'Install: dependencies'
run: yarn install

- name: 'Install: binaryen'
working-directory: /usr
run: |
sudo wget -c https://github.com/WebAssembly/binaryen/releases/download/$BINARYEN_VERSION/binaryen-$BINARYEN_VERSION-x86_64-linux.tar.gz -O - | sudo tar -xz -C .
sudo cp binaryen-$BINARYEN_VERSION/bin/wasm-opt /usr/bin/

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

Expand All @@ -65,36 +52,3 @@ jobs:

- name: 'Test: run'
run: yarn test

publish-to-npm:
if: github.event_name == 'push'

runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use node 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x

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

- name: 'Install: binaryen'
working-directory: /usr
run: |
sudo wget -c https://github.com/WebAssembly/binaryen/releases/download/$BINARYEN_VERSION/binaryen-$BINARYEN_VERSION-x86_64-linux.tar.gz -O - | sudo tar -xz -C .
sudo cp binaryen-$BINARYEN_VERSION/bin/wasm-opt /usr/bin/

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

- name: Publish
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 }}
79 changes: 79 additions & 0 deletions .github/workflows/release-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
on:
push:
branches:
- master
paths:
- package.json

name: JS release

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=js/$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: '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: 'Prepare: install dependencies and build pkgs'
if: env.skip != 'true'
run: |
yarn install
yarn build

- name: Publish
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 }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ net/**/[Oo]bj/
node_modules/
js/**/lib/
js/cli/build/
js/parser/parser.wasm
js/test/demo/
.pnp.*
.yarn/*
Expand Down
6 changes: 6 additions & 0 deletions js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# CHANGELOG

## 0.3.1 (draft)

### Changes
- Setup releases (https://github.com/gear-tech/sails/pull/608)
Binary file added js/parser/parser.wasm
Binary file not shown.
11 changes: 0 additions & 11 deletions js/parser/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,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,7 +71,6 @@ export default [
},
],
plugins: [
buildParserWasm(),
checkParserFile(),
cleanOldBuild(),
typescript({
Expand Down
5 changes: 5 additions & 0 deletions js/scripts/build-parser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
echo "[*] Building parser wasm"
cargo build -p sails-idl-parser --target=wasm32-unknown-unknown --release
echo "[*] Optimizing parser wasm"
wasm-opt -O4 -o ./js/parser/parser.wasm ./target/wasm32-unknown-unknown/release/sails_idl_parser.wasm
ls -l ./js/parser/parser.wasm
9 changes: 9 additions & 0 deletions js/scripts/bump-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version=$1

echo "Bumping versions to $version"

pkgs=("package.json" "./js/package.json" "./js/cli/package.json" "./js/parser/package.json" "./js/types/package.json" "./js/util/package.json")

for pkg in ${pkgs[@]}; do
jq ".version = \"$version\"" $pkg > tmp.$$.json && mv tmp.$$.json $pkg
done