-
Notifications
You must be signed in to change notification settings - Fork 3
218 lines (197 loc) · 8.24 KB
/
regenerate-sources.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
214
215
216
217
218
# This workflow does 4 things:
# - Restore data from GitHub Actions cache from previous runs of this workflow.
# - Regenerate NuGet sources for ARM64 and x86_64 used to build jellyfin. (Previously also confusingly called cache.)
# - Regenerate Node sources used to build jellyfin-web. (Previously not included in this workflow.)
# - Create a Pull Request if data has changed.
#
# NOTE:
# - Why so many env blocks? https://woodruffw.github.io/zizmor/audits/#template-injection
#
name: Regenerate NuGet and Node Sources
on:
# TODO: Remove, seems to be fixed.
# Running this workflow on a schedule with the current tooling will only
# create noise and waste resources. The order of the dependencies can change
# while versions and hashes remain the same. Since this workflow now exists
# and is considered complete, a maintainer should be able to run this
# workflow on demand from the GitHub app on a mobile device when the bot
# detects a new release of Jellyfin.
schedule:
# Past releases usually happened late on Ssturday
- cron: 15 6 * * SUN
workflow_dispatch:
env:
MANIFEST: "main/org.jellyfin.JellyfinServer.yml"
PR_BRANCH: update-nuget-node
REPO_BACKEND: "jellyfin/jellyfin"
REPO_FRONTEND: "jellyfin/jellyfin-web"
SOFTWARE_NAME: "Jellyfin"
jobs:
Regenerate-NuGet-Node-Sources:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout this repository
uses: actions/checkout@v4
with:
persist-credentials: false
path: main
- name: Check if branch used for Pull Request exists
working-directory: main
run: |
if [[ -n "$(git ls-remote --heads origin "${PR_BRANCH}")" ]]; then
echo "Warning: Branch '${PR_BRANCH}' exists. Merge the Pull Request or delete the branch."
exit 1
else
echo "OK: Branch not found."
fi
env:
PR_BRANCH: ${{ env.PR_BRANCH }}
# Restores the path below contains most of the data of installed apps and runtimes.
# This can save about 1GB of downloads.
- name: Restore Flatpak apps from cache
uses: actions/cache@v4
with:
path: |
~/.local/share/flatpak
key: flatpak-cache-x86_64-${{ github.sha }}
restore-keys: |
flatpak
- name: Install flatpak and pipx package
run: |
sudo apt-get update -y
sudo apt-get install flatpak pipx -y --no-install-recommends
- name: Install yq binary, if necessary
run: |
if ! command -v "yq" > /dev/null 2>&1; then
mkdir -pv ~/.local/bin
wget --quiet https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \
-O ~/.local/bin/yq
chmod -v +x ~/.local/bin/yq
fi
- name: Get latest ${{ env.SOFTWARE_NAME }} frontend tag
id: jq_tag_jf_fe
run: |
latest_tag=$(
curl -s "https://api.github.com/repos/${REPO_FRONTEND}/releases/latest" \
| jq -r '.tag_name'
)
echo "JQ_TAG_JF_FE=$latest_tag" >> "$GITHUB_ENV"
env:
REPO_FRONTEND: ${{ env.REPO_FRONTEND }}
- name: Get latest ${{ env.SOFTWARE_NAME }} backend tag
id: jq_tag_jf_be
run: |
latest_tag=$(
curl -s "https://api.github.com/repos/${REPO_BACKEND}/releases/latest" \
| jq -r '.tag_name'
)
echo "JQ_TAG_JF_BE=$latest_tag" >> "$GITHUB_ENV"
env:
REPO_BACKEND: ${{ env.REPO_BACKEND }}
- name: Extract environment variables from manifest
run: |
# shellcheck disable=SC2129
# Freedesktop SDK runtime rersion, example: 24.08
echo "YQ_RUNTIME_VERSION=$(yq '.runtime-version' "${MANIFEST}")" >> "$GITHUB_ENV"
# Jellyfin tag, example: 10.10.3
echo "YQ_JF_TAG=$(yq '.modules[-1].sources[2].tag' "${MANIFEST}")" >> "$GITHUB_ENV"
# DotNet SDK, example: org.freedesktop.Sdk.Extension.dotnet8
echo "YQ_DOTNETSDK=$(yq '.sdk-extensions[0]' "${MANIFEST}")" >> "$GITHUB_ENV"
# DotNet version, example: 8
YQ_DOTNETSDK="$(yq '.sdk-extensions[0]' "${MANIFEST}")"
echo "DOT_NET_VER=${YQ_DOTNETSDK##*dotnet}" >> "$GITHUB_ENV"
# Node SDK, example: org.freedesktop.Sdk.Extension.node22
echo "YQ_NODESDK=$(yq '.sdk-extensions[1]' "${MANIFEST}")" >> "$GITHUB_ENV"
# If frontend and backend tags are equal, and backend tag is not empty,
# and backend tag does not match the manifest, then there must be a new
# release.
# shellcheck disable=SC2153
if [[ "${JQ_TAG_JF_FE}" == "${JQ_TAG_JF_BE}" && -n "${JQ_TAG_JF_BE}" && "${JQ_TAG_JF_BE}" != "${YQ_JF_TAG}" ]]; then
echo "JF_TAG=${JQ_TAG_JF_BE}" >> "$GITHUB_ENV"
echo "NEW_RELEASE_DETECTED=true" >> "$GITHUB_ENV"
else
echo "JF_TAG=${YQ_JF_TAG}" >> "$GITHUB_ENV"
echo "NEW_RELEASE_DETECTED=false" >> "$GITHUB_ENV"
fi
env:
JQ_TAG_JF_FE: ${{ env.JQ_TAG_JF_FE }}
JQ_TAG_JF_BE: ${{ env.JQ_TAG_JF_BE }}
MANIFEST: ${{ env.MANIFEST }}
- name: Install Flatpak Builder, Freedesktop SDK, DotNet and Node
run: |
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak update --user --noninteractive -y
flatpak install --user flathub "org.flatpak.Builder" --noninteractive -y
flatpak install --user flathub "org.freedesktop.Sdk//${YQ_RUNTIME_VERSION}" --noninteractive -y
flatpak install --user flathub "${YQ_DOTNETSDK}//${YQ_RUNTIME_VERSION}" --noninteractive -y
flatpak install --user flathub "${YQ_NODESDK}//${YQ_RUNTIME_VERSION}" --noninteractive -y
env:
DOT_NET_VER: ${{ env.DOT_NET_VER }}
YQ_DOTNETSDK: ${{ env.YQ_DOTNETSDK }}
YQ_NODESDK: ${{ env.YQ_NODESDK }}
YQ_RUNTIME_VERSION: ${{ env.YQ_RUNTIME_VERSION }}
- name: Checkout Flatpak Builder Tools
uses: actions/checkout@v4
with:
persist-credentials: false
repository: flatpak/flatpak-builder-tools
path: flatpak-builder-tools
- name: Install flatpak-node-generator with pipx
run: |
pipx install "./flatpak-builder-tools/node/"
- name: Checkout jellyfin
uses: actions/checkout@v4
with:
persist-credentials: false
repository: jellyfin/jellyfin
path: jellyfin
ref: ${{ env.JF_TAG }}
- name: Checkout jellyfin-web
uses: actions/checkout@v4
with:
persist-credentials: false
repository: jellyfin/jellyfin-web
path: jellyfin-web
ref: ${{ env.JF_TAG }}
- name: Generate sources for NuGet x64 used by jellyfin
run: |
./flatpak-builder-tools/dotnet/flatpak-dotnet-generator.py \
--dotnet "${DOT_NET_VER}" --freedesktop "${YQ_RUNTIME_VERSION}" --runtime=linux-x64 \
"main/nuget-generated-sources-x64.json" \
"jellyfin/Jellyfin.Server/Jellyfin.Server.csproj"
env:
DOT_NET_VER: ${{ env.DOT_NET_VER }}
YQ_RUNTIME_VERSION: ${{ env.YQ_RUNTIME_VERSION }}
- name: Generate sources for NuGet arm64 used by jellyfin
run: |
./flatpak-builder-tools/dotnet/flatpak-dotnet-generator.py \
--dotnet "${DOT_NET_VER}" --freedesktop "${YQ_RUNTIME_VERSION}" --runtime=linux-arm64 \
"main/nuget-generated-sources-arm64.json" \
"jellyfin/Jellyfin.Server/Jellyfin.Server.csproj"
env:
DOT_NET_VER: ${{ env.DOT_NET_VER }}
YQ_RUNTIME_VERSION: ${{ env.YQ_RUNTIME_VERSION }}
- name: Generate sources for Node used by jellyfin-web
run: |
flatpak-node-generator \
-o "main/npm-generated-sources.json" npm "jellyfin-web/package-lock.json"
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: latest
- name: Install Prettier
run: |
npm install -g prettier
- name: Reformat JSON files
run: npx prettier --write "main/"*".json"
- name: Create Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
path: main
title: Regenerate NuGet and Node Sources ${{ env.JF_TAG }}
commit-message: Regenerate NuGet and Node Sources ${{ env.JF_TAG }}
branch: ${{ env.PR_BRANCH }}
delete-branch: true