-
-
Notifications
You must be signed in to change notification settings - Fork 4
79 lines (76 loc) · 5.46 KB
/
wheelie_HA_scheduler.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
name: Wheelie_HA Scheduler
on:
schedule:
- cron: '20 * * * *'
workflow_dispatch:
jobs:
wheelie-HA-scheduler:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Check for updates and trigger
run: |
export HASS_RELEASE=$(curl -sfX GET https://api.github.com/repos/home-assistant/core/releases/latest \
| jq -r .tag_name)
echo "HASS_RELEASE is ${HASS_RELEASE}"
export HASS_BASE=$(curl -sfL https://raw.githubusercontent.com/home-assistant/core/${HASS_RELEASE}/build.yaml \
| grep 'amd64: ' \
| cut -d: -f3)
echo "HASS_BASE is ${HASS_BASE}"
echo "Downloading upstream requirements files. . ."
mkdir -p upstream
curl -sfL https://raw.githubusercontent.com/home-assistant/core/${HASS_RELEASE}/requirements.txt -o upstream/requirements.txt
curl -sfL https://raw.githubusercontent.com/home-assistant/core/${HASS_RELEASE}/requirements_all.txt -o upstream/requirements_all.txt
curl -sfL https://raw.githubusercontent.com/home-assistant/docker/${HASS_BASE}/requirements.txt -o upstream/requirements_base.txt
echo "Comparing local files to upstream. . ."
CURRENT_HASH=$(grep -hs ^ HA-reqs/* | md5sum | cut -c1-8)
NEW_HASH=$(grep -hs ^ upstream/* | md5sum | cut -c1-8)
if [ ${CURRENT_HASH} != ${NEW_HASH} ]; then
if [[ $(curl -sL https://pypi.python.org/pypi/homeassistant/json | jq -r '. | .info.version') != "${HASS_RELEASE}" ]]; then
echo "Github release is there but the package is not pushed to PyPI yet, skipping build"
echo "**** Notifying Discord ****"
FAILURE_REASON="Changes to HomeAssistant wheel requirements detected, but the package is not pushed to PyPI yet, skipping for now."
curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903,
"description": "**Trigger Failed** \n**Reason:** '"${FAILURE_REASON}"' \n"}],
"username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }}
exit 0
fi
if [ $(curl -s https://ci.linuxserver.io/job/Tools/job/wheelie/lastBuild/api/json | jq -r '.building') == "false" ] && [ $(curl -s https://ci.linuxserver.io/job/Tools/job/wheelieHA/lastBuild/api/json | jq -r '.building') == "false" ] && [ $(curl -s https://ci.linuxserver.io/job/Tools/job/wheelieSCI/lastBuild/api/json | jq -r '.building') == "false" ]; then
echo "**** Triggering wheelie for HomeAssistant ****"
response=$(curl -iX POST \
https://ci.linuxserver.io/job/Tools/job/wheelieHA/build \
--user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} | grep -i location | sed "s|^[L|l]ocation: \(.*\)|\1|")
echo "**** Jenkins job queue url: ${response%$'\r'} ****"
echo "**** Sleeping 10 seconds until job starts ****"
sleep 10
buildurl=$(curl -s "${response%$'\r'}api/json" | jq -r '.executable.url')
buildurl="${buildurl%$'\r'}"
echo "**** Jenkins job build url: ${buildurl} ****"
echo "**** Attempting to change the Jenkins job description ****"
curl -iX POST \
"${buildurl}submitDescription" \
--user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} \
--data-urlencode "description=GHA external trigger https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
--data-urlencode "Submit=Submit"
echo "**** Notifying discord ****"
TRIGGER_REASON="Changes to HomeAssistant wheel requirements detected, triggering wheelie."
curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903,
"description": "**Build Triggered** \n**Reason:** '"${TRIGGER_REASON}"' \n**Build URL:** '"${buildurl}display/redirect"' \n"}],
"username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }}
else
echo "**** New packages are available but there is already an active Wheelie build, skipping ****"
echo "**** Notifying Discord ****"
FAILURE_REASON="Changes to HomeAssistant wheel requirements detected, but a wheelie build is already active, skipping for now."
curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903,
"description": "**Trigger Failed** \n**Reason:** '"${FAILURE_REASON}"' \n"}],
"username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }}
fi
else
echo "**** No changes to the requirements files, skipping wheelie trigger, but triggering docker-homeassistant trigger ****"
curl -iX POST \
-H "Authorization: token ${{ secrets.CR_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"ref\":\"refs/heads/main\"}" \
https://api.github.com/repos/linuxserver/docker-homeassistant/actions/workflows/external_trigger.yml/dispatches
fi