-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
action.yml
149 lines (134 loc) · 5.3 KB
/
action.yml
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
name: 'Home Assistant helper: version'
description: 'GitHub action helper: version'
inputs:
type:
description: The type of target to check against (core, supervisor, plugin, generic)
required: false
default: 'generic'
outputs:
version:
description: The version found for the requested type
value: ${{ steps.version.outputs.version }}
stable:
description: Returns "true" if it is a stable build, else "false"
value: ${{ steps.version.outputs.stable }}
channel:
description: Returns suggested channel.
value: ${{ steps.channel.outputs.channel }}
publish:
description: Returns "true" if it should be published, else "false"
value: ${{ steps.publish.outputs.publish }}
runs:
using: "composite"
steps:
- shell: bash
env:
INPUTS_TYPE: ${{ inputs.type }}
run: |
if [[ -z "$INPUTS_TYPE" ]];then
echo "::error::Missing required key 'type' input!"
exit 1
fi
- shell: bash
id: version
env:
GITHUB_EVENT_INPUTS_VERSION: ${{ github.event.inputs.version }}
GITHUB_EVENT_INPUTS_STABLE: ${{ github.event.inputs.stable }}
INPUTS_TYPE: ${{ inputs.type }}
EVENT_NAME: ${{ github.event_name }}
REF: ${{ github.event_name == 'release' && github.event.release.tag_name || github.ref }}
UV_SYSTEM_PYTHON: "true"
run: |
version=$(echo "$REF" | awk -F"/" '{print $NF}' )
if [[ "${version}" == "" ]]; then
echo "::error::Verson is empty"
exit 1
fi
if [[ ! -z "$GITHUB_EVENT_INPUTS_VERSION" ]]; then
version="$GITHUB_EVENT_INPUTS_VERSION"
elif [[ "${version}" =~ (master|main) && "$INPUTS_TYPE" =~ (supervisor|plugin|generic) ]]; then
today="$(date --utc '+%Y-%m-%d')"
midnight_timestamp="$(date --utc +%s --date=$today)"
calver_date="$(date --utc --date=$today '+%Y.%m')"
if tag=$(git describe --tags --abbrev=0 --match="${calver_date}.*" 2>/dev/null)
then
base_ver="$(echo $tag | awk -F. '{printf "%s.%s.%d",$1,$2,$3+1}')"
else
base_ver="${calver_date}.0"
fi
commit_count="$(git rev-list --count --since=$midnight_timestamp HEAD)"
calver_dev="$(date --utc --date=$today '+.dev%d')$(printf "%02d" ${commit_count})"
version="${base_ver}${calver_dev}"
elif [[ "${version}" == "merge" && "$INPUTS_TYPE" =~ (supervisor|plugin|generic) ]]; then
version="${{ github.sha }}"
elif [[ "${version}" == "dev" && "$INPUTS_TYPE" == "core" ]]; then
python3 -m pip install uv
uv pip install packaging tomli
uv pip install .
python3 script/version_bump.py nightly
version="$(python3 ${{ github.action_path }}/../read_version.py)"
fi
if [[ ! -z "$GITHUB_EVENT_INPUTS_STABLE" ]]; then
stable="$GITHUB_EVENT_INPUTS_STABLE"
elif [[ "$EVENT_NAME" == "release" ]]; then
stable="true"
else
stable="false"
fi
echo "stable=$stable" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
- shell: bash
env:
INPUTS_TYPE: ${{ inputs.type }}
run: |
if [[ "$INPUTS_TYPE" == "supervisor" ]]; then
sed -i "s/^SUPERVISOR_VERSION =.*/SUPERVISOR_VERSION = \"${{ steps.version.outputs.version }}\"/g" supervisor/const.py
fi
- shell: bash
id: channel
env:
INPUTS_TYPE: ${{ inputs.type }}
GITHUB_EVENT_INPUTS_CHANNEL: ${{ github.event.inputs.channel }}
run: |
if [[ ! -z "$GITHUB_EVENT_INPUTS_CHANNEL" ]]; then
echo "channel=$GITHUB_EVENT_INPUTS_CHANNEL" >> "$GITHUB_OUTPUT"
elif [[ "$INPUTS_TYPE" =~ (plugin|supervisor) ]]; then
if [[ "${{ steps.version.outputs.stable }}" == "true" ]]; then
echo "channel=beta" >> "$GITHUB_OUTPUT"
else
echo "channel=dev" >> "$GITHUB_OUTPUT"
fi
elif [[ "$INPUTS_TYPE" == "core" ]]; then
if [[ "${{ steps.version.outputs.version }}" =~ dev ]]; then
echo "channel=dev" >> "$GITHUB_OUTPUT"
elif [[ "${{ steps.version.outputs.version }}" =~ b ]]; then
echo "channel=beta" >> "$GITHUB_OUTPUT"
else
echo "channel=stable" >> "$GITHUB_OUTPUT"
fi
fi
- shell: bash
id: publish
env:
INPUTS_TYPE: ${{ inputs.type }}
GITHUB_EVENT_INPUTS_PUBLISH: ${{ github.event.inputs.publish }}
EVENT_NAME: ${{ github.event_name }}
HEAD_REF: ${{ github.head_ref }}
run: |
if [[ ! -z "$GITHUB_EVENT_INPUTS_PUBLISH" ]]; then
echo "publish=$GITHUB_EVENT_INPUTS_PUBLISH" >> "$GITHUB_OUTPUT"
elif [[ "$INPUTS_TYPE" =~ (plugin|supervisor) ]]; then
if [[ ! -z "$HEAD_REF" ]]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
elif [[ "$EVENT_NAME" =~ (release|push) ]]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
elif [[ "$INPUTS_TYPE" == "core" ]]; then
if [[ "$EVENT_NAME" == "release" ]]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
fi