forked from home-assistant/version
-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (185 loc) · 6.79 KB
/
jh-version.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: JH Version
on:
workflow_dispatch:
inputs:
files:
description: 'File(s) to run action against'
required: true
pull_request:
branches: ["master-jethub"]
push:
branches: ["master-jethub"]
paths:
- '*.txt'
- '*.json'
- '*.png'
- homeassistant.pub
env:
PYTHON_VERSION: "3.10"
COSIGN_VERSION: "v2.0.2"
SIGNED_FILES: "apparmor.txt apparmor_beta.txt apparmor_dev.txt apparmor_stable.txt beta.json dev.json stable.json"
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Lint with JQ
uses: jethub-homeassistant/actions/helpers/jq@master-jethub
prepare:
name: Prepare
needs: ["lint"]
runs-on: ubuntu-latest
outputs:
files: ${{ steps.changed_files.outputs.files }}
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Get changed files for push
if: github.event_name == 'push'
id: changed_files_push
uses: jitterbit/get-changed-files@v1
- name: Get changed files
id: changed_files
run: |
if [[ ${{ github.event_name }} == "push" ]]; then
echo "files=${{ steps.changed_files_push.outputs.all }}" >> $GITHUB_OUTPUT
else
echo "files=${{ github.event.inputs.files }}" >> $GITHUB_OUTPUT
fi
signing:
name: Sign ${{ matrix.path }}
needs: ["prepare"]
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
id-token: write
packages: write
strategy:
matrix:
path:
- stable.json
- beta.json
- dev.json
- apparmor.txt
- apparmor_stable.txt
- apparmor_beta.txt
- apparmor_dev.txt
steps:
- name: Check
id: check
run: |
if [[ "${{ needs.prepare.outputs.files }}" =~ ${{ matrix.path }} ]]; then
echo "sign=yes" >> $GITHUB_OUTPUT
fi
- name: Checkout the repository
if: steps.check.outputs.sign == 'yes'
uses: actions/checkout@v3
- name: Install SSH key for storage
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.SSH_KNOWNHOSTS_UPLOAD }}
if_key_exists: replace
- name: Login to GitHub Container Registry
if: steps.check.outputs.sign == 'yes'
uses: docker/[email protected]
with:
registry: ghcr.io
username: jethub-homeassistant
password: ${{ secrets.GITHUB_TOKEN }}
- uses: sigstore/cosign-installer@main
if: steps.check.outputs.sign == 'yes'
with:
cosign-release: ${{ env.COSIGN_VERSION }}
- name: Setup Python version ${{ env.PYTHON_VERSION }}
if: steps.check.outputs.sign == 'yes'
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Sign CAS
if: steps.check.outputs.sign == 'yes'
uses: jethub-homeassistant/actions/helpers/codenotary@master-jethub
with:
source: ${{ matrix.path }}
token: ${{ secrets.CAS_TOKEN }}
- name: Upload file
if: steps.check.outputs.sign == 'yes'
run: |
cosign upload blob -f ${{ matrix.path }} ghcr.io/jethub-homeassistant/version/${{ matrix.path }}
- name: Sign Cosign
if: steps.check.outputs.sign == 'yes'
run: |
cosign sign --yes ghcr.io/jethub-homeassistant/version/${{ matrix.path }}
cosign sign-blob --yes ${{ matrix.path }} --bundle ${{ matrix.path }}.sig
#cosign sign --yes --key env://COSIGN_PRIVATE_KEY --output-signature ${{ matrix.path }}.sig ghcr.io/jethub-homeassistant/version/${{ matrix.path }}
env:
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_KEY }}
- name: Upload signature
if: steps.check.outputs.sign == 'yes'
run: |
#ssh-keyscan update.jethome.ru >"${HOME}/.ssh/known_hosts"
rsync "${{ matrix.path }}.sig" [email protected]:/var/www/haversion.jethome.ru/
upload:
name: Upload
needs: ["signing", "prepare"]
if: needs.prepare.outputs.files != null && github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Install SSH key for storage
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.SSH_KNOWNHOSTS_UPLOAD }}
if_key_exists: replace
- name: Setup Python version ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Check diff
id: checkdiff
run: |
MESSAGE="Upload new versions: "
MESSAGESEND=false
for file in ${{ needs.prepare.outputs.files }}; do
if [[ "$file" =~ \.json ]]; then
JSON2=${file}
JSON=$(mktemp).json
rsync [email protected]:/var/www/haversion.jethome.ru/"$file" ${JSON}
OUTPUT=$(mktemp).json
OUTPUT2=$(mktemp).json
cat ${JSON} | jq "{supervisor,cli,dns,audio,multicast,observer}" | jq .core+="$(jq .homeassistant[\"jethub-d1\"] ${JSON})" | jq .hassos+="$(jq .hassos[\"jethub-d1\"] ${JSON})"> ${OUTPUT}
cat ${JSON2} | jq "{supervisor,cli,dns,audio,multicast,observer}" | jq .core+="$(jq .homeassistant[\"jethub-d1\"] ${JSON2})" | jq .hassos+="$(jq .hassos[\"jethub-d1\"] ${JSON2})"> ${OUTPUT2}
DIFF=$(diff -y --suppress-common-lines ${OUTPUT} ${OUTPUT2} | cut -d '|' -f 2 | xargs | sed 's/,$//g' | sed 's/\"//g')
if [[ -n "${DIFF}" ]]; then
echo "file${file}=${DIFF}" >> $GITHUB_OUTPUT
MESSAGE="${MESSAGE}"$'\n'"${file}:"$'\n'"${DIFF}"$'\n'
MESSAGESEND=true
fi
rm -f ${JSON} ${OUTPUT} ${OUTPUT2}
fi
done
if [[ "$MESSAGESEND" == "true" ]]; then
echo "message<<EOF" >> $GITHUB_OUTPUT
echo "${MESSAGE}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Upload files
run: |
for file in ${{ needs.prepare.outputs.files }}; do
if [[ "$file" =~ \.txt|\.json|\.png ]]; then
#ssh-keyscan update.jethome.ru >"${HOME}/.ssh/known_hosts"
rsync "$file" [email protected]:/var/www/haversion.jethome.ru/
fi
done
- name: Notify
if: ${{ steps.checkdiff.outputs.message != null }}
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
${{ steps.checkdiff.outputs.message }}