|
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*.*.*' |
| 12 | + branches: |
| 13 | + - beta-*.*.* |
| 14 | + - alpha-*.*.* |
7 | 15 | workflow_dispatch: |
8 | 16 |
|
| 17 | +permissions: |
| 18 | + id-token: write |
| 19 | + contents: write |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
9 | 25 | jobs: |
10 | | - build_and_test: |
| 26 | + determine-release-type: |
| 27 | + name: Determine Release Type |
| 28 | + runs-on: ubuntu-latest |
| 29 | + if: ${{ github.repository == 'homebridge/HAP-NodeJS' }} |
| 30 | + outputs: |
| 31 | + release_type: ${{ steps.release-type.outputs.type }} |
| 32 | + npm_tag: ${{ steps.release-type.outputs.tag }} |
| 33 | + version: ${{ steps.get_version.outputs.version }} |
| 34 | + steps: |
| 35 | + - name: Determine release type |
| 36 | + id: release-type |
| 37 | + run: | |
| 38 | + if [[ "${{ github.event_name }}" == "release" ]]; then |
| 39 | + echo "type=latest" >> $GITHUB_OUTPUT |
| 40 | + echo "tag=latest" >> $GITHUB_OUTPUT |
| 41 | + elif [[ "${{ github.ref }}" == refs/heads/beta-* ]]; then |
| 42 | + echo "type=beta" >> $GITHUB_OUTPUT |
| 43 | + echo "tag=beta" >> $GITHUB_OUTPUT |
| 44 | + elif [[ "${{ github.ref }}" == refs/heads/alpha-* ]]; then |
| 45 | + echo "type=alpha" >> $GITHUB_OUTPUT |
| 46 | + echo "tag=alpha" >> $GITHUB_OUTPUT |
| 47 | + else |
| 48 | + echo "type=none" >> $GITHUB_OUTPUT |
| 49 | + echo "tag=none" >> $GITHUB_OUTPUT |
| 50 | + echo "No valid release type detected - skipping publish" |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Get Release Tag (Latest Only) |
| 54 | + if: steps.release-type.outputs.type == 'latest' |
| 55 | + id: get_version |
| 56 | + uses: jannemattila/get-version-from-tag@v3 |
| 57 | + |
| 58 | + - name: Tag Info (Latest Only) |
| 59 | + if: steps.release-type.outputs.type == 'latest' |
| 60 | + run: | |
| 61 | + echo "Release Tag: ${{github.ref}}" |
| 62 | + echo "Latest Tag: ${{ steps.get_version.outputs.version }}" |
| 63 | +
|
| 64 | + - name: Tag Info Matches (Latest Only) |
| 65 | + if: steps.release-type.outputs.type == 'latest' && endsWith(github.ref, steps.get_version.outputs.version) |
| 66 | + run: | |
| 67 | + echo Latest Tag matches Release tag |
| 68 | +
|
| 69 | + - name: Tag Info Doesn't Match (Latest Only) |
| 70 | + if: steps.release-type.outputs.type == 'latest' && !endsWith(github.ref, steps.get_version.outputs.version) |
| 71 | + run: | |
| 72 | + echo Latest Tag does not matches Release tag |
| 73 | + exit 1 |
| 74 | +
|
| 75 | + build_and_test_latest: |
| 76 | + needs: determine-release-type |
| 77 | + name: Build and Test ${{ needs.determine-release-type.outputs.version }} |
| 78 | + if: needs.determine-release-type.outputs.release_type == 'latest' |
11 | 79 | uses: homebridge/.github/.github/workflows/nodejs-build-and-test.yml@latest |
12 | 80 | with: |
13 | 81 | enable_coverage: true |
| 82 | + install_cmd: npm ci |
| 83 | + secrets: |
| 84 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + |
| 86 | + build_and_test_beta: |
| 87 | + needs: determine-release-type |
| 88 | + name: Build and Test (Beta) |
| 89 | + if: needs.determine-release-type.outputs.release_type == 'beta' |
| 90 | + uses: homebridge/.github/.github/workflows/nodejs-build-and-test.yml@latest |
| 91 | + with: |
| 92 | + enable_coverage: false |
| 93 | + install_cmd: npm ci |
14 | 94 | secrets: |
15 | 95 | token: ${{ secrets.GITHUB_TOKEN }} |
16 | 96 |
|
17 | 97 | publish: |
18 | | - needs: build_and_test |
| 98 | + needs: [determine-release-type, build_and_test_latest, build_and_test_beta] |
| 99 | + if: | |
| 100 | + always() && |
| 101 | + needs.determine-release-type.outputs.release_type != 'none' && |
| 102 | + (needs.determine-release-type.outputs.release_type == 'alpha' || |
| 103 | + needs.build_and_test_latest.result == 'success' || |
| 104 | + needs.build_and_test_latest.result == 'skipped') && |
| 105 | + (needs.build_and_test_beta.result == 'success' || |
| 106 | + needs.build_and_test_beta.result == 'skipped') |
| 107 | + name: Publish to npm (${{ needs.determine-release-type.outputs.npm_tag }}) |
| 108 | + runs-on: ubuntu-latest |
| 109 | + outputs: |
| 110 | + npm_version: ${{ steps.get-published-version.outputs.version }} |
| 111 | + steps: |
| 112 | + - name: Checkout code |
| 113 | + uses: actions/checkout@v6 |
19 | 114 |
|
20 | | - if: ${{ github.repository == 'homebridge/HAP-NodeJS' }} |
| 115 | + - name: Setup Node.js |
| 116 | + uses: actions/setup-node@v6 |
| 117 | + with: |
| 118 | + node-version: 24 |
| 119 | + registry-url: 'https://registry.npmjs.org' |
21 | 120 |
|
22 | | - uses: homebridge/.github/.github/workflows/npm-publish.yml@latest |
23 | | - secrets: |
24 | | - npm_auth_token: ${{ secrets.npm_token }} |
| 121 | + - name: Upgrade npm for OIDC support |
| 122 | + run: npm install -g npm@latest |
| 123 | + |
| 124 | + - name: Install dependencies |
| 125 | + run: npm ci |
| 126 | + |
| 127 | + - name: Handle prerelease versioning |
| 128 | + if: needs.determine-release-type.outputs.release_type == 'beta' || needs.determine-release-type.outputs.release_type == 'alpha' |
| 129 | + run: | |
| 130 | + # Download versioning script from homebridge/.github |
| 131 | + mkdir -p .github |
| 132 | + wget -q https://raw.githubusercontent.com/homebridge/.github/latest/.github/npm-version-script-esm.js -O .github/npm-version-script-esm.js |
| 133 | +
|
| 134 | + # Run the script to set base version |
| 135 | + node .github/npm-version-script-esm.js ${{ github.ref }} ${{ needs.determine-release-type.outputs.release_type }} |
| 136 | +
|
| 137 | + # Add prerelease suffix |
| 138 | + npm version pre --preid=${{ needs.determine-release-type.outputs.release_type }} --no-git-tag-version |
| 139 | +
|
| 140 | + - name: Build |
| 141 | + run: npm run build |
| 142 | + |
| 143 | + - name: Publish to npm with OIDC |
| 144 | + run: npm publish --tag ${{ needs.determine-release-type.outputs.npm_tag }} --provenance --access public |
| 145 | + |
| 146 | + - name: Get published version |
| 147 | + id: get-published-version |
| 148 | + run: | |
| 149 | + VERSION=$(node -p "require('./package.json').version") |
| 150 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 151 | + echo "Published version: $VERSION" |
25 | 152 |
|
26 | 153 | github-releases-to-discord: |
27 | 154 | name: Discord Webhooks |
28 | | - needs: [build_and_test,publish] |
| 155 | + needs: [determine-release-type, publish] |
| 156 | + if: | |
| 157 | + always() && |
| 158 | + needs.publish.result == 'success' && |
| 159 | + needs.attach-artifact.result == 'success' |
29 | 160 | uses: homebridge/.github/.github/workflows/discord-webhooks.yml@latest |
30 | 161 | with: |
31 | 162 | title: "HAP-NodeJS Release" |
32 | 163 | description: | |
33 | 164 | 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 }}" |
| 165 | + url: "https://github.com/homebridge/HAP-NodeJS/releases/tag/v${{ needs.publish.outputs.NPM_VERSION }}" |
35 | 166 | secrets: |
36 | | - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_LATEST }} |
| 167 | + DISCORD_WEBHOOK: ${{ needs.determine-release-type.outputs.release_type == 'latest' && secrets.DISCORD_WEBHOOK_URL_LATEST || secrets.DISCORD_WEBHOOK_URL_BETA }} |
0 commit comments