Skip to content

Commit

Permalink
feat(git): add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kodemon committed Oct 20, 2023
1 parent dab0670 commit 030efe6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 16 additions & 0 deletions version.cjs
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit 030efe6

Please sign in to comment.