From ce230d27fb89b0efcbd8499fbc0e9cafd085c0e1 Mon Sep 17 00:00:00 2001 From: DutchmanNL Date: Sat, 27 Feb 2021 22:27:31 +0100 Subject: [PATCH] implement release script --- .github/workflows/test-and-release.yml | 110 ++++++++++++------------- package-lock.json | 19 +++++ package.json | 2 + 3 files changed, 74 insertions(+), 57 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index c3e79a1..85f6b24 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -76,61 +76,57 @@ jobs: # if: startsWith(runner.OS, 'windows') # run: set DEBUG=testing:* & npm run test:integration -# TODO: To enable automatic npm releases, create a token on npmjs.org -# Enter this token as a GitHub secret (with name NPM_TOKEN) in the repository options -# Then uncomment the following block: + # Deploys the final package to NPM + deploy: + needs: [adapter-tests] -# # Deploys the final package to NPM -# deploy: -# needs: [adapter-tests] -# -# # Trigger this step only when a commit on any branch is tagged with a version number -# if: | -# contains(github.event.head_commit.message, '[skip ci]') == false && -# github.event_name == 'push' && -# startsWith(github.ref, 'refs/tags/v') -# -# runs-on: ubuntu-latest -# strategy: -# matrix: -# node-version: [14.x] -# -# steps: -# - name: Checkout code -# uses: actions/checkout@v2 -# -# - name: Use Node.js ${{ matrix.node-version }} -# uses: actions/setup-node@v1 -# with: -# node-version: ${{ matrix.node-version }} -# -# - name: Extract the version and commit body from the tag -# id: extract_release -# # The body may be multiline, therefore newlines and % need to be escaped -# run: | -# VERSION="${{ github.ref }}" -# VERSION=${VERSION##*/v} -# echo "::set-output name=VERSION::$VERSION" -# BODY=$(git show -s --format=%b) -# BODY="${BODY//'%'/'%25'}" -# BODY="${BODY//$'\n'/'%0A'}" -# BODY="${BODY//$'\r'/'%0D'}" -# echo "::set-output name=BODY::$BODY" -# -# - name: Publish package to npm -# run: | -# npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} -# npm whoami -# npm publish -# -# - name: Create Github Release -# uses: actions/create-release@v1 -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# with: -# tag_name: ${{ github.ref }} -# release_name: Release v${{ steps.extract_release.outputs.VERSION }} -# draft: false -# # Prerelease versions create prereleases on Github -# prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }} -# body: ${{ steps.extract_release.outputs.BODY }} + # Trigger this step only when a commit on any branch is tagged with a version number + if: | + contains(github.event.head_commit.message, '[skip ci]') == false && + github.event_name == 'push' && + startsWith(github.ref, 'refs/tags/v') + + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [14.x] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Extract the version and commit body from the tag + id: extract_release + # The body may be multiline, therefore newlines and % need to be escaped + run: | + VERSION="${{ github.ref }}" + VERSION=${VERSION##*/v} + echo "::set-output name=VERSION::$VERSION" + BODY=$(git show -s --format=%b) + BODY="${BODY//'%'/'%25'}" + BODY="${BODY//$'\n'/'%0A'}" + BODY="${BODY//$'\r'/'%0D'}" + echo "::set-output name=BODY::$BODY" + + - name: Publish package to npm + run: | + npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} + npm whoami + npm publish + + - name: Create Github Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release v${{ steps.extract_release.outputs.VERSION }} + draft: false + # Prerelease versions create prereleases on Github + prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }} + body: ${{ steps.extract_release.outputs.BODY }} diff --git a/package-lock.json b/package-lock.json index 3e71619..0955058 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,19 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@alcalzone/release-script": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@alcalzone/release-script/-/release-script-1.8.3.tgz", + "integrity": "sha512-PPzX+GG08Gwx7ygraGB8pbnWSD0KIxHiJtegLhHK9GZ+QodAl2K4VQe8/RuY0r4fhwDWCXbYbPEw10xaxXmh2w==", + "dev": true, + "requires": { + "alcalzone-shared": "^3.0.1", + "axios": "^0.21.1", + "colors": "^1.4.0", + "semver": "^7.3.4", + "yargs": "^16.2.0" + } + }, "@babel/code-frame": { "version": "7.12.11", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.11.tgz", @@ -902,6 +915,12 @@ "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", "dev": true }, + "colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", + "dev": true + }, "component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", diff --git a/package.json b/package.json index fdc1ad3..65c5ff8 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "mdns-js": "^1.0.3" }, "devDependencies": { + "@alcalzone/release-script": "^1.8.3", "@iobroker/testing": "^2.4.2", "@types/chai": "^4.2.15", "@types/chai-as-promised": "^7.1.3", @@ -45,6 +46,7 @@ }, "main": "main.js", "scripts": { + "release": "release-script", "test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"", "test:package": "mocha test/package --exit", "test:unit": "mocha test/unit --exit",