Skip to content

Commit

Permalink
attempt to write a github action workflow to autopublish npm packages…
Browse files Browse the repository at this point in the history
… on version change
  • Loading branch information
VINXIS committed Jul 28, 2024
1 parent ee750c3 commit f8c27aa
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/publish_npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Publish NPM Package

on:
workflow_run:
workflows: ["Run Tests"]
types:
- completed
branches:
- 'main'

jobs:
build_and_publish:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Extract Cargo.toml version
id: extract_version
run: echo "::set-output name=cargo_version::$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*)"/\1/')"

- name: Fetch current npm package version
id: fetch_npm_version
run: |
current_version=$(npm show corsace-parser version || echo "0.0.0")
echo "::set-output name=npm_version::$current_version"
- name: Compare versions and publish if Cargo.toml version is newer
id: compare_versions
run: |
cargo_version=${{ steps.extract_version.outputs.cargo_version }}
npm_version=${{ steps.fetch_npm_version.outputs.npm_version }}
if [ "$(printf '%s\n' "$npm_version" "$cargo_version" | sort -V | head -n1)" != "$cargo_version" ]; then
echo "New version detected. Publishing package..."
echo "::set-output name=should_publish::true"
else
echo "No new version. Skipping publish."
echo "::set-output name=should_publish::false"
fi
- name: Set up Rust
if: steps.compare_versions.outputs.should_publish == 'true'
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
profile: minimal

- name: Install wasm-pack
if: steps.compare_versions.outputs.should_publish == 'true'
run: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build WASM
if: steps.compare_versions.outputs.should_publish == 'true'
run: wasm-pack build --target nodejs

- name: Configure NPM
if: steps.compare_versions.outputs.should_publish == 'true'
run: npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}

- name: Publish NPM package
if: steps.compare_versions.outputs.should_publish == 'true'
run: npm publish --access public
working-directory: ./pkg
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div align="center">
<h1><code>wasm replay parser</code></h1>
<a href="https://wakatime.com/badge/user/8618af0f-2922-48fc-a975-d1faa417e6eb/project/5163423f-bfbe-4eac-bae6-5aab6c1ce9bf"><img src="https://wakatime.com/badge/user/8618af0f-2922-48fc-a975-d1faa417e6eb/project/5163423f-bfbe-4eac-bae6-5aab6c1ce9bf.svg" alt="wakatime"></a><br>
wip
<h1><code>corsace-parser</code></h1>
<a href="https://wakatime.com/badge/user/8618af0f-2922-48fc-a975-d1faa417e6eb/project/5163423f-bfbe-4eac-bae6-5aab6c1ce9bf"><img src="https://wakatime.com/badge/user/8618af0f-2922-48fc-a975-d1faa417e6eb/project/5163423f-bfbe-4eac-bae6-5aab6c1ce9bf.svg" alt="wakatime"></a> <a href="npmjs.com/package/corsace-parser"><img src="https://img.shields.io/npm/v/corsace-parser" alt="npm"></a>
<br>
readme is wip
</div>

# Build
Expand Down

0 comments on commit f8c27aa

Please sign in to comment.