|
1 | | -name: Node Release |
| 1 | +name: Release |
| 2 | + |
| 3 | +# This workflow handles latest, beta, and alpha releases: |
| 4 | +# - Latest: Triggered by GitHub releases (tag vX.Y.Z) |
| 5 | +# - Beta: Triggered by pushes to beta-X.Y.Z branches |
| 6 | +# - Alpha: Triggered by pushes to alpha-X.Y.Z branches |
2 | 7 |
|
3 | 8 | on: |
| 9 | + release: |
| 10 | + types: [released] |
4 | 11 | push: |
5 | | - tags: |
6 | | - - 'v*.*.*' |
7 | | - workflow_dispatch: |
| 12 | + branches: |
| 13 | + - beta-*.*.* |
| 14 | + - alpha-*.*.* |
| 15 | + |
| 16 | +permissions: |
| 17 | + id-token: write |
| 18 | + contents: write |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 22 | + cancel-in-progress: true |
8 | 23 |
|
9 | 24 | jobs: |
10 | | - build_and_test: |
| 25 | + determine-npm-tag: |
| 26 | + name: Determine NPM Tag |
| 27 | + runs-on: ubuntu-latest |
| 28 | + if: ${{ github.repository == 'homebridge/hap-nodejs' }} |
| 29 | + outputs: |
| 30 | + npm_tag: ${{ steps.npm-tag.outputs.tag }} |
| 31 | + steps: |
| 32 | + - name: Determine NPM Tag |
| 33 | + id: npm-tag |
| 34 | + run: | |
| 35 | + if [[ "${{ github.event_name }}" == "release" ]]; then |
| 36 | + echo "tag=latest" >> $GITHUB_OUTPUT |
| 37 | + elif [[ "${{ github.ref }}" == refs/heads/beta-* ]]; then |
| 38 | + echo "tag=beta" >> $GITHUB_OUTPUT |
| 39 | + elif [[ "${{ github.ref }}" == refs/heads/alpha-* ]]; then |
| 40 | + echo "tag=alpha" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + echo "tag=none" >> $GITHUB_OUTPUT |
| 43 | + echo "No valid release type detected - skipping publish" |
| 44 | + fi |
| 45 | +
|
| 46 | + lint: |
| 47 | + needs: determine-npm-tag |
| 48 | + name: Lint |
| 49 | + if: needs.determine-npm-tag.outputs.npm_tag != 'none' |
| 50 | + uses: homebridge/.github/.github/workflows/eslint.yml@latest |
| 51 | + |
| 52 | + build_and_test_latest: |
| 53 | + needs: [determine-npm-tag, lint] |
| 54 | + name: Build & Test (Latest) |
| 55 | + if: needs.determine-npm-tag.outputs.npm_tag == 'latest' |
11 | 56 | uses: homebridge/.github/.github/workflows/nodejs-build-and-test.yml@latest |
12 | 57 | with: |
13 | 58 | enable_coverage: true |
14 | 59 | secrets: |
15 | 60 | token: ${{ secrets.GITHUB_TOKEN }} |
16 | 61 |
|
17 | | - publish: |
18 | | - needs: build_and_test |
| 62 | + build_and_test_beta: |
| 63 | + needs: [determine-npm-tag, lint] |
| 64 | + name: Build & Test (Beta) |
| 65 | + if: needs.determine-npm-tag.outputs.npm_tag == 'beta' |
| 66 | + uses: homebridge/.github/.github/workflows/nodejs-build-and-test.yml@latest |
| 67 | + with: |
| 68 | + enable_coverage: false |
| 69 | + secrets: |
| 70 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + |
| 72 | + publish-to-npm: |
| 73 | + needs: [determine-npm-tag, lint, build_and_test_latest, build_and_test_beta] |
| 74 | + if: | |
| 75 | + always() && |
| 76 | + needs.determine-npm-tag.outputs.npm_tag != 'none' && |
| 77 | + (needs.determine-npm-tag.outputs.npm_tag != 'alpha' || |
| 78 | + needs.lint.result == 'success') && |
| 79 | + (needs.determine-npm-tag.outputs.npm_tag == 'alpha' || |
| 80 | + needs.build_and_test_latest.result == 'success' || |
| 81 | + needs.build_and_test_latest.result == 'skipped') && |
| 82 | + (needs.build_and_test_beta.result == 'success' || |
| 83 | + needs.build_and_test_beta.result == 'skipped') |
| 84 | + name: Publish To NPM (${{ needs.determine-npm-tag.outputs.npm_tag }}) |
| 85 | + runs-on: ubuntu-latest |
| 86 | + outputs: |
| 87 | + npm_version: ${{ steps.get-published-version.outputs.version }} |
| 88 | + steps: |
| 89 | + - name: Checkout Code |
| 90 | + uses: actions/checkout@v6 |
19 | 91 |
|
20 | | - if: ${{ github.repository == 'homebridge/HAP-NodeJS' }} |
| 92 | + - name: Setup Node.js |
| 93 | + uses: actions/setup-node@v6 |
| 94 | + with: |
| 95 | + node-version: 24 |
| 96 | + registry-url: 'https://registry.npmjs.org' |
21 | 97 |
|
22 | | - uses: homebridge/.github/.github/workflows/npm-publish.yml@latest |
23 | | - secrets: |
24 | | - npm_auth_token: ${{ secrets.npm_token }} |
| 98 | + - name: Upgrade NPM (OIDC Support) |
| 99 | + run: npm install -g npm@latest |
| 100 | + |
| 101 | + - name: Install Dependencies |
| 102 | + run: npm ci |
| 103 | + |
| 104 | + - name: Handle Prerelease Versioning |
| 105 | + if: needs.determine-npm-tag.outputs.npm_tag == 'beta' || needs.determine-npm-tag.outputs.npm_tag == 'alpha' |
| 106 | + run: | |
| 107 | + # Download versioning script from homebridge/.github |
| 108 | + mkdir -p .github |
| 109 | + wget -q https://raw.githubusercontent.com/homebridge/.github/latest/.github/npm-version-script-esm.js -O .github/npm-version-script-esm.js |
| 110 | +
|
| 111 | + # Run the script to set base version |
| 112 | + node .github/npm-version-script-esm.js ${{ github.ref }} ${{ needs.determine-npm-tag.outputs.npm_tag }} |
| 113 | +
|
| 114 | + # Add prerelease suffix |
| 115 | + npm version pre --preid=${{ needs.determine-npm-tag.outputs.npm_tag }} --no-git-tag-version |
| 116 | +
|
| 117 | + - name: Build |
| 118 | + run: npm run build |
| 119 | + |
| 120 | + - name: NPM Publish (OIDC) |
| 121 | + run: npm publish --tag ${{ needs.determine-npm-tag.outputs.npm_tag }} --provenance --access public |
| 122 | + |
| 123 | + - name: Get Published Version |
| 124 | + id: get-published-version |
| 125 | + run: | |
| 126 | + VERSION=$(node -p "require('./package.json').version") |
| 127 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 128 | + echo "Published Version: $VERSION" |
25 | 129 |
|
26 | 130 | github-releases-to-discord: |
27 | 131 | name: Discord Webhooks |
28 | | - needs: [build_and_test,publish] |
| 132 | + needs: [determine-npm-tag, publish-to-npm] |
| 133 | + if: | |
| 134 | + always() && |
| 135 | + needs.publish-to-npm.result == 'success' |
29 | 136 | uses: homebridge/.github/.github/workflows/discord-webhooks.yml@latest |
30 | 137 | with: |
31 | | - title: "HAP-NodeJS Release" |
| 138 | + title: ${{ needs.determine-npm-tag.outputs.npm_tag == 'latest' && 'HAP-NodeJS Release' || needs.determine-npm-tag.outputs.npm_tag == 'beta' && 'HAP-NodeJS Beta Release' || 'HAP-NodeJS Alpha Release' }} |
32 | 139 | description: | |
33 | | - Version `v${{ needs.publish.outputs.NPM_VERSION }}` |
34 | | - url: "https://github.com/homebridge/homebridge-config-ui-x/releases/tag/v${{ needs.publish.outputs.NPM_VERSION }}" |
| 140 | + Version `v${{ needs.publish-to-npm.outputs.npm_version }}` |
| 141 | + url: 'https://github.com/homebridge/hap-nodejs/releases/tag/v${{ needs.publish-to-npm.outputs.npm_version }}' |
35 | 142 | secrets: |
36 | | - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_LATEST }} |
| 143 | + DISCORD_WEBHOOK: ${{ needs.determine-npm-tag.outputs.npm_tag == 'latest' && secrets.DISCORD_WEBHOOK_URL_LATEST || secrets.DISCORD_WEBHOOK_URL_BETA }} |
0 commit comments