feat(git): add release workflow

This commit is contained in:
2023-10-20 08:55:56 +00:00
parent dab06707c9
commit 030efe60b8
3 changed files with 59 additions and 1 deletions

42
.github/workflows/publish.yml vendored Normal file
View File

@@ -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 }}

View File

@@ -1,6 +1,6 @@
{ {
"name": "@valkyr/db", "name": "@valkyr/db",
"version": "1.0.0-rc1", "version": "0.0.0",
"description": "Simple client side storage solution written in TypeScript.", "description": "Simple client side storage solution written in TypeScript.",
"repository": "https://github.com/cmdo/valkyr.git", "repository": "https://github.com/cmdo/valkyr.git",
"bugs": "https://github.com/cmdo/valkyr/issues", "bugs": "https://github.com/cmdo/valkyr/issues",

16
version.cjs Normal file
View File

@@ -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));
}