214 lines
8.7 KiB
YAML
214 lines
8.7 KiB
YAML
name: Release
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
check_if_wasm_version_upgraded:
|
|
name: Check if WASM version has been upgraded
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
wasm_version: ${{ steps.version-updated.outputs.current-package-version }}
|
|
wasm_has_updated: ${{ steps.version-updated.outputs.has-updated }}
|
|
steps:
|
|
- uses: JiPaix/package-json-updated-action@v1.0.5
|
|
id: version-updated
|
|
with:
|
|
path: rust/automerge-wasm/package.json
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
publish-wasm:
|
|
name: Publish WASM package
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- check_if_wasm_version_upgraded
|
|
# We create release only if the version in the package.json has been upgraded
|
|
if: needs.check_if_wasm_version_upgraded.outputs.wasm_has_updated == 'true'
|
|
steps:
|
|
- uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '16.x'
|
|
registry-url: 'https://registry.npmjs.org'
|
|
- uses: denoland/setup-deno@v1
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
ref: ${{ github.ref }}
|
|
- name: Get rid of local github workflows
|
|
run: rm -r .github/workflows
|
|
- name: Remove tmp_branch if it exists
|
|
run: git push origin :tmp_branch || true
|
|
- run: git checkout -b tmp_branch
|
|
- name: Install wasm-bindgen-cli
|
|
run: cargo install wasm-bindgen-cli wasm-opt
|
|
- name: Install wasm32 target
|
|
run: rustup target add wasm32-unknown-unknown
|
|
- name: run wasm js tests
|
|
id: wasm_js_tests
|
|
run: ./scripts/ci/wasm_tests
|
|
- name: run wasm deno tests
|
|
id: wasm_deno_tests
|
|
run: ./scripts/ci/deno_tests
|
|
- name: build release
|
|
id: build_release
|
|
run: |
|
|
npm --prefix $GITHUB_WORKSPACE/rust/automerge-wasm run release
|
|
- name: Collate deno release files
|
|
if: steps.wasm_js_tests.outcome == 'success' && steps.wasm_deno_tests.outcome == 'success'
|
|
run: |
|
|
mkdir $GITHUB_WORKSPACE/deno_wasm_dist
|
|
cp $GITHUB_WORKSPACE/rust/automerge-wasm/deno/* $GITHUB_WORKSPACE/deno_wasm_dist
|
|
cp $GITHUB_WORKSPACE/rust/automerge-wasm/index.d.ts $GITHUB_WORKSPACE/deno_wasm_dist
|
|
cp $GITHUB_WORKSPACE/rust/automerge-wasm/README.md $GITHUB_WORKSPACE/deno_wasm_dist
|
|
cp $GITHUB_WORKSPACE/rust/automerge-wasm/LICENSE $GITHUB_WORKSPACE/deno_wasm_dist
|
|
sed -i '1i /// <reference types="./index.d.ts" />' $GITHUB_WORKSPACE/deno_wasm_dist/automerge_wasm.js
|
|
- name: Create npm release
|
|
if: steps.wasm_js_tests.outcome == 'success' && steps.wasm_deno_tests.outcome == 'success'
|
|
run: |
|
|
if [ "$(npm --prefix $GITHUB_WORKSPACE/rust/automerge-wasm show . version)" = "$VERSION" ]; then
|
|
echo "This version is already published"
|
|
exit 0
|
|
fi
|
|
EXTRA_ARGS="--access public"
|
|
if [[ $VERSION == *"alpha."* ]] || [[ $VERSION == *"beta."* ]] || [[ $VERSION == *"rc."* ]]; then
|
|
echo "Is pre-release version"
|
|
EXTRA_ARGS="$EXTRA_ARGS --tag next"
|
|
fi
|
|
if [ "$NODE_AUTH_TOKEN" = "" ]; then
|
|
echo "Can't publish on NPM, You need a NPM_TOKEN secret."
|
|
false
|
|
fi
|
|
npm publish $GITHUB_WORKSPACE/rust/automerge-wasm $EXTRA_ARGS
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
VERSION: ${{ needs.check_if_wasm_version_upgraded.outputs.wasm_version }}
|
|
- name: Commit wasm deno release files
|
|
run: |
|
|
git config --global user.name "actions"
|
|
git config --global user.email actions@github.com
|
|
git add $GITHUB_WORKSPACE/deno_wasm_dist
|
|
git commit -am "Add deno release files"
|
|
git push origin tmp_branch
|
|
- name: Tag wasm release
|
|
if: steps.wasm_js_tests.outcome == 'success' && steps.wasm_deno_tests.outcome == 'success'
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
name: Automerge Wasm v${{ needs.check_if_wasm_version_upgraded.outputs.wasm_version }}
|
|
tag_name: js/automerge-wasm-${{ needs.check_if_wasm_version_upgraded.outputs.wasm_version }}
|
|
target_commitish: tmp_branch
|
|
generate_release_notes: false
|
|
draft: false
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Remove tmp_branch
|
|
run: git push origin :tmp_branch
|
|
check_if_js_version_upgraded:
|
|
name: Check if JS version has been upgraded
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
js_version: ${{ steps.version-updated.outputs.current-package-version }}
|
|
js_has_updated: ${{ steps.version-updated.outputs.has-updated }}
|
|
steps:
|
|
- uses: JiPaix/package-json-updated-action@v1.0.5
|
|
id: version-updated
|
|
with:
|
|
path: javascript/package.json
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
publish-js:
|
|
name: Publish JS package
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- check_if_js_version_upgraded
|
|
- check_if_wasm_version_upgraded
|
|
- publish-wasm
|
|
# We create release only if the version in the package.json has been upgraded and after the WASM release
|
|
if: |
|
|
(always() && ! cancelled()) &&
|
|
(needs.publish-wasm.result == 'success' || needs.publish-wasm.result == 'skipped') &&
|
|
needs.check_if_js_version_upgraded.outputs.js_has_updated == 'true'
|
|
steps:
|
|
- uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '16.x'
|
|
registry-url: 'https://registry.npmjs.org'
|
|
- uses: denoland/setup-deno@v1
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
ref: ${{ github.ref }}
|
|
- name: Get rid of local github workflows
|
|
run: rm -r .github/workflows
|
|
- name: Remove js_tmp_branch if it exists
|
|
run: git push origin :js_tmp_branch || true
|
|
- run: git checkout -b js_tmp_branch
|
|
- name: check js formatting
|
|
run: |
|
|
yarn global add prettier
|
|
prettier -c javascript/.prettierrc javascript
|
|
- name: run js tests
|
|
id: js_tests
|
|
run: |
|
|
cargo install wasm-bindgen-cli wasm-opt
|
|
rustup target add wasm32-unknown-unknown
|
|
./scripts/ci/js_tests
|
|
- name: build js release
|
|
id: build_release
|
|
run: |
|
|
npm --prefix $GITHUB_WORKSPACE/javascript run build
|
|
- name: build js deno release
|
|
id: build_deno_release
|
|
run: |
|
|
VERSION=$WASM_VERSION npm --prefix $GITHUB_WORKSPACE/javascript run deno:build
|
|
env:
|
|
WASM_VERSION: ${{ needs.check_if_wasm_version_upgraded.outputs.wasm_version }}
|
|
- name: run deno tests
|
|
id: deno_tests
|
|
run: |
|
|
npm --prefix $GITHUB_WORKSPACE/javascript run deno:test
|
|
- name: Collate deno release files
|
|
if: steps.js_tests.outcome == 'success' && steps.deno_tests.outcome == 'success'
|
|
run: |
|
|
mkdir $GITHUB_WORKSPACE/deno_js_dist
|
|
cp $GITHUB_WORKSPACE/javascript/deno_dist/* $GITHUB_WORKSPACE/deno_js_dist
|
|
- name: Create npm release
|
|
if: steps.js_tests.outcome == 'success' && steps.deno_tests.outcome == 'success'
|
|
run: |
|
|
if [ "$(npm --prefix $GITHUB_WORKSPACE/javascript show . version)" = "$VERSION" ]; then
|
|
echo "This version is already published"
|
|
exit 0
|
|
fi
|
|
EXTRA_ARGS="--access public"
|
|
if [[ $VERSION == *"alpha."* ]] || [[ $VERSION == *"beta."* ]] || [[ $VERSION == *"rc."* ]]; then
|
|
echo "Is pre-release version"
|
|
EXTRA_ARGS="$EXTRA_ARGS --tag next"
|
|
fi
|
|
if [ "$NODE_AUTH_TOKEN" = "" ]; then
|
|
echo "Can't publish on NPM, You need a NPM_TOKEN secret."
|
|
false
|
|
fi
|
|
npm publish $GITHUB_WORKSPACE/javascript $EXTRA_ARGS
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
VERSION: ${{ needs.check_if_js_version_upgraded.outputs.js_version }}
|
|
- name: Commit js deno release files
|
|
run: |
|
|
git config --global user.name "actions"
|
|
git config --global user.email actions@github.com
|
|
git add $GITHUB_WORKSPACE/deno_js_dist
|
|
git commit -am "Add deno js release files"
|
|
git push origin js_tmp_branch
|
|
- name: Tag JS release
|
|
if: steps.js_tests.outcome == 'success' && steps.deno_tests.outcome == 'success'
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
name: Automerge v${{ needs.check_if_js_version_upgraded.outputs.js_version }}
|
|
tag_name: js/automerge-${{ needs.check_if_js_version_upgraded.outputs.js_version }}
|
|
target_commitish: js_tmp_branch
|
|
generate_release_notes: false
|
|
draft: false
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Remove js_tmp_branch
|
|
run: git push origin :js_tmp_branch
|