node-red-contrib-homebridge-automation 0.3.0 → 0.3.1-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.
@@ -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
- 'Build, Publish and Release'
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 latest branch, create a github release as well
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
- # checkout repo
24
- - uses: actions/checkout@v4
25
-
26
- # get branch / tag name
27
- - name: Get Branch / Tag Name
28
- id: get_branch
29
- run: |
30
- export BRANCH_NAME=$(if [[ ${GITHUB_REF} =~ "refs/tags/" ]]; then echo ${GITHUB_REF/refs\/tags\//}; else echo ${GITHUB_REF/refs\/heads\//}; fi)
31
- echo $BRANCH_NAME
32
- echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
33
-
34
- # generate the image tag
35
- - name: Get Image Tag
36
- id: get_tag
37
- run: |
38
- 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)
39
- echo $TARGET_IMAGE_TAG
40
- echo "TARGET_IMAGE_TAG=${TARGET_IMAGE_TAG}" >> $GITHUB_OUTPUT
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
- # checkout repo
51
- - uses: actions/checkout@v4
52
- with:
53
- persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
54
- fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
55
-
56
- - uses: actions/setup-node@v4
57
- with:
58
- node-version: lts/*
59
-
60
- - name: Retrieve github-markdown-toc
61
- run: |
62
- wget -q https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc
63
- chmod a+x gh-md-toc
64
-
65
- - name: Create Table of Contents
66
- run: |
67
- npm run-script document --if-present
68
- rm gh-md-toc
69
-
70
- - name: Commit files
71
- run: |
72
- git config --local user.email "github-actions[bot]@users.noreply.github.com"
73
- git config --local user.name "github-actions[bot]"
74
- git add * || true
75
- git commit -a -m "Update TOC" || true
76
-
77
- - name: Push changes
78
- uses: ad-m/github-push-action@master
79
- with:
80
- github_token: ${{ secrets.GITHUB_TOKEN }}
81
- branch: ${{ github.ref }}
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.NPM_TOKEN }}
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.NPM_TOKEN }}
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
- - uses: actions/checkout@v4
116
- - name: Create Release
117
- uses: softprops/action-gh-release@v1
118
- env:
119
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120
- with:
121
- tag_name: ${{ needs.publish_prod_release.outputs.NPM_VERSION }}
122
- name: Release ${{ needs.publish_prod_release.outputs.NPM_VERSION }}
123
- generate_release_notes: true
124
- draft: false
125
- prerelease: false
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.0",
3
+ "version": "0.3.1-beta.0",
4
4
  "description": "NodeRED Automation for HomeBridge",
5
5
  "main": "src/HAP-NodeRed.js",
6
6
  "scripts": {
@@ -76,4 +76,4 @@
76
76
  "!src/test-utils"
77
77
  ]
78
78
  }
79
- }
79
+ }