Repository navigation
159 lines (139 loc) · 5.36 KB
/
Copy pathupdate-dev-json.yml
File metadata and controls
159 lines (139 loc) · 5.36 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
name: Update dev channel OTA index files
on:
workflow_dispatch:
push:
branches:
- dev
paths:
- "images/**"
- ".github/SCHEMA.json"
# Default to no permissions; each job declares exactly what it needs
permissions: {}
concurrency:
group: update-dev-json
cancel-in-progress: false
env:
PYTHON_VERSION_DEFAULT: "3.14"
jobs:
# Generate index files in a read-only job to isolate OTA image parsing
# from privileged push operations
generate-index:
name: Generate OTA index files
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
# Shallow clone is sufficient — this job only reads files from the working tree.
# Full history is only needed by update-release-files (which switches branches).
- name: Checkout repository
uses: actions/checkout@v7
with:
# This job only reads the tree (and parses untrusted OTA images) -
# don't leave any credentials behind
persist-credentials: false
- name: Load schema config
run: |
set -euo pipefail
{
echo "TMP_ZIGPY=/tmp/$(jq -r '.zigpy_filename' .github/SCHEMA.json)"
echo "TMP_Z2M=/tmp/$(jq -r '.z2m_filename' .github/SCHEMA.json)"
echo "TMP_MARKDOWN=/tmp/$(jq -r '.markdown_filename' .github/SCHEMA.json)"
} >> "$GITHUB_ENV"
- name: Set up Python ${{ env.PYTHON_VERSION_DEFAULT }}
uses: actions/setup-python@v7
with:
python-version: ${{ env.PYTHON_VERSION_DEFAULT }}
- name: Install uv
uses: astral-sh/setup-uv@v10.0.1
with:
# No dependency caching: this job generates the published OTA index
# files, so a poisoned cache must not be able to influence its output
enable-cache: false
- name: Install package
run: uv sync --group ci
- name: Generate zigpy JSON metadata (dev channel)
run: |
uv run zigpy-ota generate-index \
--format zigpy \
--channel dev \
--output-file "$TMP_ZIGPY"
- name: Generate Z2M JSON metadata (dev channel)
run: |
uv run zigpy-ota generate-index \
--format z2m \
--channel dev \
--output-file "$TMP_Z2M"
- name: Generate markdown index (dev channel)
run: |
uv run zigpy-ota generate-index \
--format markdown \
--channel dev \
--output-file "$TMP_MARKDOWN"
- name: Upload generated index files
uses: actions/upload-artifact@v7
with:
name: dev-index-files
if-no-files-found: error
retention-days: 1
path: |
${{ env.TMP_ZIGPY }}
${{ env.TMP_Z2M }}
${{ env.TMP_MARKDOWN }}
update-release-files:
name: Commit index files to release/files branch
needs: [generate-index]
permissions: {}
runs-on: ubuntu-slim
timeout-minutes: 5
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ secrets.BOT_APP_CLIENT_ID }}
private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
# Downscope the token to just what this workflow needs (without
# permission-* inputs, it would carry all installation permissions)
permission-contents: write
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Download generated index files
uses: actions/download-artifact@v8
with:
name: dev-index-files
path: /tmp/index-files
# Commits keep the zigpy-bot user identity for now; pushes authenticate
# with the GitHub App installation token (the checkout credentials)
- name: Configure git
run: |
set -euo pipefail
git config --global user.name "zigpy-bot"
git config --global user.email "247691930+zigpy-bot@users.noreply.github.com"
- name: Commit and push changes to release/files
run: |
set -euo pipefail
# Switch to the release/files branch. It must already exist: it is created
# once per repository as an orphan branch, never derived from the code tree
# (e.g. git switch --orphan release/files && git commit --allow-empty -m "Init")
if ! git ls-remote --exit-code --heads origin release/files > /dev/null 2>&1; then
echo "::error::Branch release/files not found (or the remote could not be reached). It must be created manually, once, as an orphan branch."
exit 1
fi
git fetch origin release/files:release/files
git checkout release/files
# Copy all generated index files to the dev directory
mkdir -p dev
cp /tmp/index-files/* dev/
# Add, commit, and push if there are changes. Retry once after a rebase:
# the version pointer workflows push to this branch from a different
# concurrency group.
git add dev/
git diff --staged --quiet || git commit -m "Update \`dev\` OTA index files to ${GITHUB_SHA::10}"
git push origin release/files || {
git pull --rebase origin release/files
git push origin release/files
}