From 0f504eaf538d05cb749df527cb24071852436410 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Fri, 18 Feb 2022 07:40:39 +0000 Subject: [PATCH] Clean up some of the test, finish implementing auto publish on both npm and git --- appveyor.yml | 20 ++++++++++++++++++-- package.json | 2 +- test/core.test.mjs | 6 ++++++ test/log.test.mjs | 8 ++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index dfe53e6..f955e74 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,12 +38,28 @@ artifacts: # on successful build on_success: - sh: | - CURR_VER=$(npm view package.json version) - if curl -s -X GET -H "token: $deploytoken" https://git.nfp.is/api/v1/repos/$APPVEYOR_REPO_NAME/releases | grep -o "\"name\"\:\"v${CURR_VER}\"" > /dev/null; then + apk add curl jq + CURR_VER=$(cat package.json | jq -r .version) + if curl -s -X GET -H "Authorization: token $deploytoken" https://git.nfp.is/api/v1/repos/$APPVEYOR_REPO_NAME/releases | grep -o "\"name\"\:\"v${CURR_VER}\"" > /dev/null; then echo "Release already exists, nothing to do."; else ./test/7zas a -mx9 "${CURR_VER}_sc-core.7z" package.json index.mjs cli.mjs core bin + echo "Creating release on gitea" + RELEASE_RESULT=$(curl \ + -X POST \ + -H "Authorization: token $deploytoken" \ + -H "Content-Type: application/json" \ + https://git.nfp.is/api/v1/repos/$APPVEYOR_REPO_NAME/releases \ + -d "{\"tag_name\":\"v${CURR_VER}\",\"name\":\"v${CURR_VER}\",\"body\":\"Automatic release from Appveyor from ${APPVEYOR_REPO_COMMIT}: ${APPVEYOR_REPO_COMMIT_MESSAGE}\"}") + RELEASE_ID=$(echo $RELEASE_RESULT | jq -r .id) + echo "Adding ${CURR_VER}_sc-core.7z to release ${RELEASE_ID}" + curl \ + -X POST \ + -H "Authorization: token $deploytoken" \ + -F "attachment=@${CURR_VER}_sc-core.7z" \ + https://git.nfp.is/api/v1/repos/$APPVEYOR_REPO_NAME/releases/$RELEASE_ID/assets echo '//registry.npmjs.org/:_authToken=${npmtoken}' > ~/.npmrc + echo "Publishing new version to npm" npm publish fi - sh: | diff --git a/package.json b/package.json index 4106721..b2a668b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "service-core", - "version": "3.0.0-beta.1", + "version": "3.0.0-beta.2", "description": "Core boiler plate code to install node server as windows service", "main": "index.mjs", "scripts": { diff --git a/test/core.test.mjs b/test/core.test.mjs index 0a3c271..591d1d1 100644 --- a/test/core.test.mjs +++ b/test/core.test.mjs @@ -255,6 +255,12 @@ t.describe('#init()', function() { Core.providers.set(assertProviderName, FakeProvider) }) + t.after(function() { + return Promise.all([ + fs.rm('./log_test_1.log', { recursive: true, force: true }), + ]) + }) + t.test('it should call util.verifyConfig correctly', async function() { const assertError = new Error('Red faction IO drive mix') const assertConfig = { a: 1 } diff --git a/test/log.test.mjs b/test/log.test.mjs index a913815..8bede96 100644 --- a/test/log.test.mjs +++ b/test/log.test.mjs @@ -1,4 +1,5 @@ import { Eltro as t, assert, stub } from 'eltro' +import fs from 'fs/promises' import getLog from '../core/log.mjs' t.describe('#constructor', function() { @@ -6,6 +7,13 @@ t.describe('#constructor', function() { process.env.NODE_ENV = null }) + + t.after(function() { + return Promise.all([ + fs.rm('./log.log', { recursive: true, force: true }), + ]) + }) + t.test('should add name', function() { const assertName = 'Stray Cat' let logger = getLog(assertName)