From 030efe60b8bd70caf09ca792021930a69cbcc91b Mon Sep 17 00:00:00 2001 From: kodemon Date: Fri, 20 Oct 2023 08:55:56 +0000 Subject: [PATCH] feat(git): add release workflow --- .github/workflows/publish.yml | 42 +++++++++++++++++++++++++++++++++++ package.json | 2 +- version.cjs | 16 +++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml create mode 100644 version.cjs diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..4c7471f --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,42 @@ +name: Publish + +on: + release: + types: [published] + +jobs: + npm: + name: NPM + runs-on: ubuntu-latest + environment: NPM Release Publishing + steps: + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c + + - uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c + with: + node-version-file: ".nvmrc" + cache: npm + + - uses: actions/github-script@e3cbab99d3a9b271e1b79fc96d103a4a5534998c + id: version + with: + script: | + const semver = context.ref.replace('refs/tags/v', '') + if (semver.match(/^[0-9]+\.[0-9]+\.[0-9]+$/)) { + return semver + } + throw new Error('not semver') + result-encoding: string + + - run: npm install + - run: npm build + + - name: Version + run: | + node ./version.cjs --version ${{ steps.version.outputs.result }} + - name: Publish + run: | + npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN + npm run publish + env: + NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} diff --git a/package.json b/package.json index 2aff67d..85ca4d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@valkyr/db", - "version": "1.0.0-rc1", + "version": "0.0.0", "description": "Simple client side storage solution written in TypeScript.", "repository": "https://github.com/cmdo/valkyr.git", "bugs": "https://github.com/cmdo/valkyr/issues", diff --git a/version.cjs b/version.cjs new file mode 100644 index 0000000..98ae127 --- /dev/null +++ b/version.cjs @@ -0,0 +1,16 @@ +const { readFileSync, writeFileSync } = require("node:fs"); +const { join, resolve } = require("node:path"); + +const ROOT_DIR = resolve(__dirname); +const VERSION = process.argv[process.argv.indexOf("--version") + 1]; + +setPackageVersions(ROOT_DIR, VERSION); + +function setPackageVersions(rootDir, version) { + const packagePath = join(rootDir, "package.json"); + const packageJson = JSON.parse(readFileSync(packagePath, "utf-8")); + + packageJson.version = version; + + writeFileSync(packagePath, JSON.stringify(packageJson, null, 2)); +}