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