node-red-contrib-homebridge-automation 0.3.3 → 0.3.4-beta.0

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.
@@ -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
+ }
@@ -90,11 +90,9 @@ jobs:
90
90
  needs: [get_tags, create_documentation]
91
91
  name: Publish Release Version
92
92
  if: ${{ needs.get_tags.outputs.BRANCH_NAME == 'main' }}
93
- uses: homebridge/.github/.github/workflows/npm-publish.yml@latest
93
+ uses: homebridge/.github/.github/workflows/npm-publish-oidc.yml@latest
94
94
  with:
95
95
  install_cmd: npm ci
96
- secrets:
97
- npm_auth_token: ${{ secrets.npm_token }}
98
96
 
99
97
  publish_test_release:
100
98
  permissions:
@@ -102,14 +100,13 @@ jobs:
102
100
  needs: [get_tags, create_documentation]
103
101
  name: Publish Test Version - ${{ needs.get_tags.outputs.BRANCH_NAME }}
104
102
  if: ${{ needs.get_tags.outputs.BRANCH_NAME != 'main' }}
105
- uses: homebridge/.github/.github/workflows/npm-publish.yml@latest
103
+ uses: homebridge/.github/.github/workflows/npm-publish-oidc.yml@latest
106
104
  with:
107
105
  tag: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
108
106
  dynamically_adjust_version: true
109
107
  npm_version_command: 'pre'
110
108
  pre_id: ${{ needs.get_tags.outputs.TARGET_IMAGE_TAG }}
111
- secrets:
112
- npm_auth_token: ${{ secrets.npm_token }}
109
+ install_cmd: npm ci
113
110
 
114
111
  publish_github_release:
115
112
  needs: [publish_prod_release]
@@ -117,7 +114,7 @@ jobs:
117
114
  steps:
118
115
  - uses: actions/checkout@v6
119
116
  - name: Create Release
120
- uses: softprops/action-gh-release@v2
117
+ uses: softprops/action-gh-release@v3
121
118
  env:
122
119
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123
120
  with:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-homebridge-automation",
3
- "version": "0.3.3",
3
+ "version": "0.3.4-beta.0",
4
4
  "description": "NodeRED Automation for HomeBridge",
5
5
  "main": "src/HAP-NodeRed.js",
6
6
  "scripts": {
@@ -3,7 +3,7 @@
3
3
  "id": "caef1e7b5b399e80",
4
4
  "type": "tab",
5
5
  "label": "Flow 1",
6
- "disabled": true,
6
+ "disabled": false,
7
7
  "info": "",
8
8
  "env": []
9
9
  },
@@ -174,14 +174,14 @@
174
174
  "id": "0ed3cd7e0d60beda",
175
175
  "type": "hb-control",
176
176
  "z": "caef1e7b5b399e80",
177
- "name": "West Bedroom Fan",
177
+ "name": "West Bedroom",
178
178
  "Homebridge": "homebridge",
179
179
  "Manufacturer": "Tasmota",
180
180
  "Service": "Fan",
181
- "device": "homebridge1C:22:3D:E3:CF:34TasmotaWest Bedroom Fan00000040",
181
+ "device": "homebridge1C:22:3D:E3:CF:34TasmotaWest Bedroom00000040",
182
182
  "conf": "7e647d67.f33acc",
183
183
  "outputs": 0,
184
- "x": 510,
184
+ "x": 500,
185
185
  "y": 220,
186
186
  "wires": []
187
187
  },
@@ -477,14 +477,14 @@
477
477
  "id": "12ce98441601c981",
478
478
  "type": "hb-event",
479
479
  "z": "caef1e7b5b399e80",
480
- "name": "Driveway",
480
+ "name": "Driveway 8E52",
481
481
  "Homebridge": "ECI-T24F2",
482
482
  "Manufacturer": "HikVision",
483
483
  "Service": "MotionSensor",
484
- "device": "ECI-T24F2CB:6F:94:DD:43:77HikVisionDriveway00000085",
484
+ "device": "ECI-T24F2CB:6F:94:DD:43:77HikVisionDriveway 8E5200000085",
485
485
  "conf": "7e647d67.f33acc",
486
486
  "sendInitialState": true,
487
- "x": 320,
487
+ "x": 340,
488
488
  "y": 520,
489
489
  "wires": [
490
490
  [
@@ -2883,14 +2883,14 @@
2883
2883
  "id": "6df154716efd4949",
2884
2884
  "type": "hb-event",
2885
2885
  "z": "92f59d974b9c8a86",
2886
- "name": "North Sidewalk 6EED",
2886
+ "name": "North Sidewalk 5036",
2887
2887
  "Homebridge": "ECI-T24F2",
2888
2888
  "Manufacturer": "HikVision",
2889
2889
  "Service": "MotionSensor",
2890
- "device": "ECI-T24F28E:88:AB:7A:D0:54HikVisionNorth Sidewalk 6EED00000085",
2890
+ "device": "ECI-T24F25C:EE:FE:4D:64:B4HikVisionNorth Sidewalk 503600000085",
2891
2891
  "conf": "7e647d67.f33acc",
2892
2892
  "sendInitialState": true,
2893
- "x": 140,
2893
+ "x": 130,
2894
2894
  "y": 220,
2895
2895
  "wires": [
2896
2896
  [
@@ -2955,11 +2955,11 @@
2955
2955
  "id": "769d2de2c6bd3544",
2956
2956
  "type": "hb-control",
2957
2957
  "z": "92f59d974b9c8a86",
2958
- "name": "North Sidewalk 6EED",
2958
+ "name": "North Sidewalk 5036",
2959
2959
  "Homebridge": "ECI-T24F2",
2960
2960
  "Manufacturer": "HikVision",
2961
2961
  "Service": "CameraRTPStreamManagement",
2962
- "device": "ECI-T24F28E:88:AB:7A:D0:54HikVisionNorth Sidewalk 6EED00000110",
2962
+ "device": "ECI-T24F25C:EE:FE:4D:64:B4HikVisionNorth Sidewalk 503600000110",
2963
2963
  "conf": "7e647d67.f33acc",
2964
2964
  "outputs": 1,
2965
2965
  "x": 760,
@@ -3157,11 +3157,11 @@
3157
3157
  "id": "448a23fd99b4e52a",
3158
3158
  "type": "hb-event",
3159
3159
  "z": "92f59d974b9c8a86",
3160
- "name": "Side door",
3160
+ "name": "Side Door",
3161
3161
  "Homebridge": "homebridge",
3162
3162
  "Manufacturer": "Eufy",
3163
3163
  "Service": "MotionSensor",
3164
- "device": "homebridge0E:89:A7:DA:D3:21EufySide door00000085",
3164
+ "device": "homebridge0E:89:A7:DA:D3:21EufySide Door00000085",
3165
3165
  "conf": "7e647d67.f33acc",
3166
3166
  "sendInitialState": true,
3167
3167
  "x": 100,
@@ -3229,11 +3229,11 @@
3229
3229
  "id": "389516e4379cfcc8",
3230
3230
  "type": "hb-control",
3231
3231
  "z": "92f59d974b9c8a86",
3232
- "name": "Side door",
3232
+ "name": "Side Door",
3233
3233
  "Homebridge": "homebridge",
3234
3234
  "Manufacturer": "Eufy",
3235
3235
  "Service": "CameraRTPStreamManagement",
3236
- "device": "homebridge0E:89:A7:DA:D3:21EufySide door00000110",
3236
+ "device": "homebridge0E:89:A7:DA:D3:21EufySide Door00000110",
3237
3237
  "conf": "7e647d67.f33acc",
3238
3238
  "outputs": 1,
3239
3239
  "x": 720,
@@ -3248,11 +3248,11 @@
3248
3248
  "id": "2802a70d3cd5570b",
3249
3249
  "type": "hb-event",
3250
3250
  "z": "92f59d974b9c8a86",
3251
- "name": "Canoe 5036",
3251
+ "name": "Canoe B6AE",
3252
3252
  "Homebridge": "ECI-T24F2",
3253
3253
  "Manufacturer": "HikVision",
3254
3254
  "Service": "MotionSensor",
3255
- "device": "ECI-T24F25C:EE:FE:4D:64:B4HikVisionCanoe 503600000085",
3255
+ "device": "ECI-T24F2C1:BB:DE:42:A5:39HikVisionCanoe B6AE00000085",
3256
3256
  "conf": "7e647d67.f33acc",
3257
3257
  "sendInitialState": true,
3258
3258
  "x": 130,