Skip to content

Commit

Permalink
Merge pull request #9 from scottbedard/check-versions
Browse files Browse the repository at this point in the history
check versions
  • Loading branch information
scottbedard authored Sep 4, 2024
2 parents c580b18 + 372da3a commit baa116c
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 12 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ env:
CARGO_TERM_COLOR: always

jobs:
versions:
name: Check versions

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false

- name: Install dependencies
run: pnpm install

- name: Check versions
run: node ./scripts/check-versions.mjs

rust:
name: Rust

Expand Down Expand Up @@ -41,10 +61,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
version: 9
run_install: false

- name: Install dependencies
Expand Down
41 changes: 34 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ env:
CARGO_TERM_COLOR: always

jobs:
versions:
name: Check versions

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false

- name: Install dependencies
run: pnpm install

- name: Check versions
run: node ./scripts/check-versions.mjs release=${{ github.ref_name }}

rust:
name: Rust

Expand All @@ -31,11 +51,11 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
version: 9
run_install: false

- uses: jetli/[email protected]
Expand All @@ -54,7 +74,7 @@ jobs:
publish:
name: Publish

needs: [rust, wasm]
needs: [versions, rust, wasm]

runs-on: ubuntu-latest

Expand All @@ -65,11 +85,13 @@ jobs:
with:
registry-url: https://registry.npmjs.org/

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
version: 9
run_install: false

- uses: dtolnay/rust-toolchain@stable

- uses: jetli/[email protected]
with:
Expand All @@ -81,9 +103,14 @@ jobs:
- name: Build wasm package
run: pnpm build

- name: Publish
- name: Publish to NPM
run: |
cd ./pkg
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to Crates.io
run: |
cargo login ${{ secrets.CARGO_TOKEN }}
cargo publish
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT"
name = "hexchess"
readme = "README.md"
repository = "https://github.com/scottbedard/hexchess.rs"
version = "0.1.0"
version = "0.5.1"

[features]
default = ["console_error_panic_hook"]
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bedard/hexchess",
"version": "0.5.0",
"version": "0.5.1",
"description": "",
"scripts": {
"build": "wasm-pack build --release && node scripts/build.mjs",
Expand All @@ -10,6 +10,7 @@
"author": "Scott Bedard",
"devDependencies": {
"@bedard/hexchess": "link:pkg",
"smol-toml": "^1.3.0",
"typescript": "^5.5.4",
"vite": "^5.4.2",
"vite-plugin-top-level-await": "^1.4.4",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions scripts/check-versions.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { fileURLToPath } from 'url'
import fs from 'fs'
import path from 'path'
import toml from 'smol-toml'

function run() {

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const cargo = toml.parse(fs.readFileSync(path.resolve(__dirname, '../Cargo.toml'), 'utf-8'))
const npm = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json')), 'utf-8')

console.log('Checking versions...')
console.log()
console.log(`Cargo: ${cargo.package.version}`)
console.log(`NPM: ${npm.version}`)

if (cargo.package.version !== npm.version) {
throw new Error(`Version mismatch [npm: ${npm.version}, cargo: ${cargo.package.version}]`)
}

let releasing = false

for (const arg of process.argv) {
if (arg.startsWith('release=')) {
const release = arg.slice(8)

if (release !== npm.version) {
throw new Error(`Release version mismatch [${release}]`)
}

console.log(`Release: ${release}`)
releasing = true
}
}

if (!releasing) {
console.log('Release: \x1b[2mNone')
}

console.log()
console.log('\x1b[32mSuccess')
}

run()

0 comments on commit baa116c

Please sign in to comment.