node-red-contrib-homebridge-automation 0.3.0 → 0.3.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.github/dependabot.yml
CHANGED
|
@@ -11,3 +11,17 @@ updates:
|
|
|
11
11
|
versions:
|
|
12
12
|
- 13.2.0
|
|
13
13
|
- 13.2.1
|
|
14
|
+
groups:
|
|
15
|
+
npm-dependencies:
|
|
16
|
+
patterns:
|
|
17
|
+
- "*"
|
|
18
|
+
- package-ecosystem: github-actions
|
|
19
|
+
directory: "/"
|
|
20
|
+
schedule:
|
|
21
|
+
interval: daily
|
|
22
|
+
time: "10:00"
|
|
23
|
+
open-pull-requests-limit: 10
|
|
24
|
+
groups:
|
|
25
|
+
github-actions:
|
|
26
|
+
patterns:
|
|
27
|
+
- "*"
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This scripts queries the npm registry to pull out the latest version for a given tag.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const assert = require('node:assert')
|
|
8
|
+
const child_process = require('node:child_process')
|
|
9
|
+
const fs = require('node:fs')
|
|
10
|
+
const process = require('node:process')
|
|
11
|
+
|
|
12
|
+
const BRANCH_VERSION_PATTERN = /^([A-Z]+)-(\d+\.\d+\.\d+)$/i
|
|
13
|
+
|
|
14
|
+
// Load the contents of the package.json file
|
|
15
|
+
const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf8'))
|
|
16
|
+
|
|
17
|
+
const refArgument = process.argv[2]
|
|
18
|
+
const tagArgument = process.argv[3] || 'latest'
|
|
19
|
+
|
|
20
|
+
if (!refArgument) {
|
|
21
|
+
console.error('ref argument is missing')
|
|
22
|
+
console.error('Usage: npm-version-script.js <ref> [tag]')
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Queries the NPM registry for the latest version for the provided base version and tag.
|
|
28
|
+
* If the tag is latest, then the base version is returned if it exists. For other tags, the latest
|
|
29
|
+
* version found for that base version and tag is returned.
|
|
30
|
+
* @param baseVersion The base version to query for, e.g. 2.0.0
|
|
31
|
+
* @param tag The tag to query for, e.g. beta or latest
|
|
32
|
+
* @returns {string} Returns the version, or '' if not found
|
|
33
|
+
*/
|
|
34
|
+
function getTagVersionFromNpm(baseVersion, tag) {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(child_process.execSync(`npm info ${packageJSON.name} versions --json`).toString('utf8').trim())
|
|
37
|
+
.filter(v => tag === 'latest' ? v === baseVersion : v.startsWith(`${baseVersion}-${tag}.`)) // find all published versions for this base version and tag
|
|
38
|
+
.reduce((_, current) => current, '') // choose the last as they're sorted in ascending order, or '' if there are none
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error(`Failed to query the npm registry for the latest version for tag: ${tag}`, e)
|
|
41
|
+
// throw e;
|
|
42
|
+
return ''
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function desiredTargetVersion(ref) {
|
|
47
|
+
// ref is a GitHub action ref string
|
|
48
|
+
if (ref.startsWith('refs/pull/')) {
|
|
49
|
+
throw new Error('The version script was executed inside a PR!')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
assert(ref.startsWith('refs/heads/'))
|
|
53
|
+
const branchName = ref.slice('refs/heads/'.length)
|
|
54
|
+
|
|
55
|
+
const results = branchName.match(BRANCH_VERSION_PATTERN)
|
|
56
|
+
if (results !== null) {
|
|
57
|
+
if (results[1] !== tagArgument) {
|
|
58
|
+
console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return results[2]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
throw new Error(`Malformed branch name for ref: ${ref}. Can't derive the base version. Use a branch name like: beta-x.x.x or alpha-x.x.x`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// derive the base version from the branch ref
|
|
68
|
+
const baseVersion = desiredTargetVersion(refArgument)
|
|
69
|
+
|
|
70
|
+
// query the npm registry for the latest version of the provided tag name
|
|
71
|
+
const latestReleasedVersion = getTagVersionFromNpm(baseVersion, tagArgument) // e.g. 0.7.0-beta.12
|
|
72
|
+
|
|
73
|
+
let publishTag
|
|
74
|
+
|
|
75
|
+
if (latestReleasedVersion) {
|
|
76
|
+
console.warn(`Latest published version for ${baseVersion} with tag ${tagArgument} is ${latestReleasedVersion}`)
|
|
77
|
+
publishTag = latestReleasedVersion // set this released beta or alpha to be incremented
|
|
78
|
+
} else {
|
|
79
|
+
console.warn(`No published versions for ${baseVersion} with tag ${tagArgument}`)
|
|
80
|
+
publishTag = baseVersion // start off with a new beta or alpha version
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (packageJSON.version !== publishTag) {
|
|
84
|
+
// report the change for CI
|
|
85
|
+
console.warn(`Changing version in package.json from ${packageJSON.version} to ${publishTag}`)
|
|
86
|
+
|
|
87
|
+
// save the package.json
|
|
88
|
+
packageJSON.version = publishTag
|
|
89
|
+
fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2))
|
|
90
|
+
|
|
91
|
+
// perform the same change to the package-lock.json
|
|
92
|
+
const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'))
|
|
93
|
+
packageLockJSON.version = publishTag
|
|
94
|
+
fs.writeFileSync('package-lock.json', JSON.stringify(packageLockJSON, null, 2))
|
|
95
|
+
} else {
|
|
96
|
+
console.warn(`Leaving version in package.json at ${packageJSON.version}`)
|
|
97
|
+
}
|
|
@@ -1,43 +1,47 @@
|
|
|
1
|
-
name:
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
name: "Build, Publish and Release"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# Automatically publish beta releases on pushes, require a manual workflow action for production releases
|
|
6
|
+
#
|
|
7
|
+
# Does the following
|
|
8
|
+
# 1 - Run the documentation script against the package
|
|
9
|
+
# 2 - Create the npm package using the package.json version tag ( or for beta releases, adds a beta tag and increments as needed )
|
|
10
|
+
# 3 - Publish the npm package
|
|
11
|
+
# 4 - For releases against the main branch, create a github release as well
|
|
12
12
|
|
|
13
13
|
on:
|
|
14
14
|
push:
|
|
15
15
|
branches: [beta-*.*.*, beta]
|
|
16
16
|
workflow_dispatch:
|
|
17
17
|
|
|
18
|
+
concurrency:
|
|
19
|
+
group: build_and_publish
|
|
20
|
+
cancel-in-progress: true
|
|
21
|
+
|
|
18
22
|
jobs:
|
|
19
23
|
get_tags:
|
|
20
24
|
runs-on: ubuntu-latest
|
|
21
25
|
|
|
22
26
|
steps:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
# checkout repo
|
|
28
|
+
- uses: actions/checkout@v5
|
|
29
|
+
|
|
30
|
+
# get branch / tag name
|
|
31
|
+
- name: Get Branch / Tag Name
|
|
32
|
+
id: get_branch
|
|
33
|
+
run: |
|
|
34
|
+
export BRANCH_NAME=$(if [[ ${GITHUB_REF} =~ "refs/tags/" ]]; then echo ${GITHUB_REF/refs\/tags\//}; else echo ${GITHUB_REF/refs\/heads\//}; fi)
|
|
35
|
+
echo $BRANCH_NAME
|
|
36
|
+
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
|
|
37
|
+
|
|
38
|
+
# generate the image tag
|
|
39
|
+
- name: Get Image Tag
|
|
40
|
+
id: get_tag
|
|
41
|
+
run: |
|
|
42
|
+
export TARGET_IMAGE_TAG=$(if [ "${{ steps.get_branch.outputs.BRANCH_NAME }}" = "main" ]; then echo "main"; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}" | awk -F- '{ print $1 }'; fi)
|
|
43
|
+
echo $TARGET_IMAGE_TAG
|
|
44
|
+
echo "TARGET_IMAGE_TAG=${TARGET_IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
41
45
|
|
|
42
46
|
outputs:
|
|
43
47
|
BRANCH_NAME: ${{ steps.get_branch.outputs.BRANCH_NAME }}
|
|
@@ -47,38 +51,38 @@ jobs:
|
|
|
47
51
|
runs-on: ubuntu-latest
|
|
48
52
|
|
|
49
53
|
steps:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
54
|
+
# checkout repo
|
|
55
|
+
- uses: actions/checkout@v5
|
|
56
|
+
with:
|
|
57
|
+
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
|
|
58
|
+
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
|
|
59
|
+
|
|
60
|
+
- uses: actions/setup-node@v6
|
|
61
|
+
with:
|
|
62
|
+
node-version: lts/*
|
|
63
|
+
|
|
64
|
+
- name: Retrieve github-markdown-toc
|
|
65
|
+
run: |
|
|
66
|
+
wget -q https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc
|
|
67
|
+
chmod a+x gh-md-toc
|
|
68
|
+
|
|
69
|
+
- name: Create Table of Contents
|
|
70
|
+
run: |
|
|
71
|
+
npm run-script document
|
|
72
|
+
rm gh-md-toc
|
|
73
|
+
|
|
74
|
+
- name: Commit files
|
|
75
|
+
run: |
|
|
76
|
+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
|
77
|
+
git config --local user.name "github-actions[bot]"
|
|
78
|
+
git add *
|
|
79
|
+
git commit -a -m "Update TOC" || true
|
|
80
|
+
|
|
81
|
+
- name: Push changes
|
|
82
|
+
uses: ad-m/github-push-action@master
|
|
83
|
+
with:
|
|
84
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
85
|
+
branch: ${{ github.ref }}
|
|
82
86
|
|
|
83
87
|
publish_prod_release:
|
|
84
88
|
permissions:
|
|
@@ -88,9 +92,9 @@ jobs:
|
|
|
88
92
|
if: ${{ needs.get_tags.outputs.BRANCH_NAME == 'main' }}
|
|
89
93
|
uses: homebridge/.github/.github/workflows/npm-publish.yml@latest
|
|
90
94
|
with:
|
|
91
|
-
install_cmd: npm ci
|
|
95
|
+
install_cmd: npm ci
|
|
92
96
|
secrets:
|
|
93
|
-
npm_auth_token: ${{ secrets.
|
|
97
|
+
npm_auth_token: ${{ secrets.npm_token }}
|
|
94
98
|
|
|
95
99
|
publish_test_release:
|
|
96
100
|
permissions:
|
|
@@ -102,24 +106,23 @@ jobs:
|
|
|
102
106
|
with:
|
|
103
107
|
tag: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
|
|
104
108
|
dynamically_adjust_version: true
|
|
105
|
-
npm_version_command: pre
|
|
109
|
+
npm_version_command: 'pre'
|
|
106
110
|
pre_id: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
|
|
107
|
-
install_cmd: npm ci
|
|
108
111
|
secrets:
|
|
109
|
-
npm_auth_token: ${{ secrets.
|
|
112
|
+
npm_auth_token: ${{ secrets.npm_token }}
|
|
110
113
|
|
|
111
114
|
publish_github_release:
|
|
112
115
|
needs: [publish_prod_release]
|
|
113
116
|
runs-on: ubuntu-latest
|
|
114
117
|
steps:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
- uses: actions/checkout@v5
|
|
119
|
+
- name: Create Release
|
|
120
|
+
uses: softprops/action-gh-release@v2
|
|
121
|
+
env:
|
|
122
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
123
|
+
with:
|
|
124
|
+
tag_name: ${{ needs.publish_prod_release.outputs.NPM_VERSION }}
|
|
125
|
+
name: Release ${{ needs.publish_prod_release.outputs.NPM_VERSION }}
|
|
126
|
+
generate_release_notes: true
|
|
127
|
+
draft: false
|
|
128
|
+
prerelease: false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-homebridge-automation",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1-beta.1",
|
|
4
4
|
"description": "NodeRED Automation for HomeBridge",
|
|
5
5
|
"main": "src/HAP-NodeRed.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node-red": "^1.3.5",
|
|
29
|
-
"@types/jest": "^
|
|
29
|
+
"@types/jest": "^30.0.0",
|
|
30
30
|
"@eslint/js": "^9.16.0",
|
|
31
31
|
"eslint": "^9.36.0",
|
|
32
32
|
"eslint-plugin-format": "^1.0.2",
|
|
33
33
|
"eslint-plugin-jest": "^29.0.1",
|
|
34
34
|
"globals": "^16.4.0",
|
|
35
|
-
"jest": "^
|
|
35
|
+
"jest": "^30.2.0",
|
|
36
36
|
"node-red": "^4.0.2",
|
|
37
37
|
"node-red-node-test-helper": "^0.3.4",
|
|
38
38
|
"nodemon": "^3.1.7",
|
|
@@ -76,4 +76,4 @@
|
|
|
76
76
|
"!src/test-utils"
|
|
77
77
|
]
|
|
78
78
|
}
|
|
79
|
-
}
|
|
79
|
+
}
|