-
-
Notifications
You must be signed in to change notification settings - Fork 157
255 lines (247 loc) · 10.5 KB
/
ci.yaml
File metadata and controls
255 lines (247 loc) · 10.5 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
name: CI
env:
IMAGE_NAME: tubesync
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'test-*'
pull_request:
branches:
- 'main'
types:
- opened
- reopened
- synchronize
- ready_for_review
concurrency:
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
info:
if: ${{ !cancelled() && 'pull_request' != github.event_name }}
runs-on: ubuntu-latest
outputs:
ffmpeg-date: ${{ steps.jq.outputs.FFMPEG_DATE }}
ffmpeg-releases: ${{ steps.ffmpeg.outputs.releases }}
ffmpeg-version: ${{ steps.jq.outputs.FFMPEG_VERSION }}
lowercase-github-actor: ${{ steps.github-actor.outputs.lowercase }}
lowercase-github-repository_owner: ${{ steps.github-repository_owner.outputs.lowercase }}
ytdlp-latest-release: ${{ steps.yt-dlp.outputs.latest-release }}
ytdlp-releases: ${{ steps.yt-dlp.outputs.releases }}
missing-tags: ${{ steps.tagged.outputs.missing }}
missing-tags-image: ${{ steps.tagged.outputs.image }}
steps:
- name: Pull tagged releases
id: tagged
run: |
image='ghcr.io/meeb/${{ env.IMAGE_NAME }}'
missing=''
set_sl_var() { local f='%s=%s\n' ; printf -- "${f}" "$@" ; } ;
set -eux
set_sl_var image "${image}" >> "${GITHUB_OUTPUT}"
set_sl_var missing "${missing}" >> "${GITHUB_OUTPUT}"
- uses: actions/checkout@v6
- name: Lowercase github username
id: github-actor
uses: ./.github/actions/string-case
with:
string: ${{ github.actor }}
- name: Lowercase github repository owner
id: github-repository_owner
uses: ./.github/actions/string-case
with:
string: ${{ github.repository_owner }}
- name: Retrieve yt-dlp/FFmpeg-Builds releases with GitHub CLI
id: ffmpeg
uses: ./.github/actions/FFmpeg
- name: Retrieve yt-dlp/yt-dlp releases with GitHub CLI
id: yt-dlp
uses: ./.github/actions/yt-dlp
- name: Set outputs with jq
id: jq
run: |
cat >| .ffmpeg.releases.json <<'EOF'
${{ steps.ffmpeg.outputs.releases }}
EOF
mk_delim() { local f='%s_EOF_%d_' ; printf -- "${f}" "$1" "${RANDOM}" ; } ;
open_ml_var() { local f=''\%'s<<'\%'s\n' ; printf -- "${f}" "$2" "$1" ; } ;
close_ml_var() { local f='%s\n' ; printf -- "${f}" "$1" ; } ;
{
var='FFMPEG_DATE' ;
delim="$(mk_delim "${var}")" ;
open_ml_var "${delim}" "${var}" ;
jq_arg='[foreach .[] as $release ([{}, []]; [ .[0] + {($release.commit): ([ $release.date ] + (.[0][($release.commit)] // []) ) }, [ .[1][0] // $release.commit ] ] ; .[0][(.[1][0])] ) ][-1][0]' ;
jq -r "${jq_arg}" -- .ffmpeg.releases.json ;
close_ml_var "${delim}" "${var}" ;
ffmpeg_date="$( jq -r "${jq_arg}" -- .ffmpeg.releases.json )"
var='FFMPEG_VERSION' ;
delim="$(mk_delim "${var}")" ;
open_ml_var "${delim}" "${var}" ;
jq_arg='.[]|select(.date == $date)|.versions[]|select(startswith("N-"))' ;
jq -r --arg date "${ffmpeg_date}" "${jq_arg}" -- .ffmpeg.releases.json ;
close_ml_var "${delim}" "${var}" ;
unset -v delim jq_arg var ;
} >> "${GITHUB_OUTPUT}"
cat -v "${GITHUB_OUTPUT}"
rm -v -f .ffmpeg.releases.json
test:
if: ${{ !cancelled() && ( 'pull_request' != github.event_name || (! github.event.pull_request.draft) ) }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@v6
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Test shasum
run: |
python3 -B -W default tubesync/shasum.py --help
python3 -B -W default tubesync/shasum.py --version
python3 -B -W default tubesync/shasum_tests.py
- name: Install dependencies
run: |
python -m pip install uv
uv --no-config --no-managed-python --no-progress \
pip install --system --strict pipenv
pipenv lock
pipenv requirements | tee requirements.txt
#PIPENV_VERBOSITY=64 pipenv install --system --skip-lock
uv --no-config --no-managed-python --no-progress \
pip install --system --strict --requirements requirements.txt
- name: Set up Django environment
run: |
mkdir -v -p ~/.config/TubeSync/config
mkdir -v -p ~/.config/TubeSync/downloads
sudo ln -v -s -f -T ~/.config/TubeSync/config /config
sudo ln -v -s -f -T ~/.config/TubeSync/downloads /downloads
cp -v -p tubesync/tubesync/local_settings.py.example tubesync/tubesync/local_settings.py
cp -v -a -t "${Python3_ROOT_DIR}"/lib/python3.*/site-packages/yt_dlp/ patches/yt_dlp/*
cd tubesync && python3 -B manage.py collectstatic --no-input --link
- name: Check with ruff
continue-on-error: false
run: |
target_version='py310'
ignore_csv_list='E701,E722,E731'
cd tubesync
# output formats:
# "full" | "concise" | "grouped" |
# "json" | "junit" | "github" | "gitlab" |
# "pylint" | "azure"
{
echo '## Output from `ruff check` for `tubesync`'
echo ''
echo '### Formats'
echo ''
for fmt in full concise grouped pylint
do
echo '<details>'
echo '<summary>'"${fmt}"'</summary>'
echo ''
echo '#### '"${fmt}"' output format'
echo ''
echo '```'
uvx --no-config --no-managed-python --no-progress --isolated \
ruff check --exit-zero \
--target-version "${target_version}" \
--output-format "${fmt}" \
--extend-select RUF100 \
--ignore "${ignore_csv_list}"
echo ''
echo '```'
echo ''
echo '</details>'
echo ''
done
} >> "${GITHUB_STEP_SUMMARY}"
uvx --no-config --no-managed-python --no-progress --isolated \
ruff check \
--target-version "${target_version}" \
--output-format github \
--ignore "${ignore_csv_list}"
- name: Run Django tests
run: cd tubesync && TUBESYNC_DEBUG=True python3 -B -W default manage.py test --no-input --buffer --verbosity=2
containerise:
if: ${{ !cancelled() && 'success' == needs.info.result }}
needs: ['info', 'test']
runs-on: ubuntu-latest
timeout-minutes: 120
concurrency:
group: ${{ github.repository }}-${{ github.workflow }}
cancel-in-progress: false
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Log into GitHub Container Registry
env:
DOCKER_REGISTRY: https://ghcr.io
DOCKER_USERNAME: ${{ github.repository_owner }}
DOCKER_TOKEN: ${{ 'meeb' == github.repository_owner && secrets.REGISTRY_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
run: echo "${DOCKER_TOKEN}" | docker login --password-stdin --username "${DOCKER_USERNAME}" "${DOCKER_REGISTRY}"
- name: Push missing release tags
if: ${{ false && 'meeb' == github.actor && github.actor == github.repository_owner && '' != needs.info.outputs.missing-tags }}
run: |
missing='${{ needs.info.outputs.missing-tags }}'
image='${{ needs.info.outputs.missing-tags-image }}'
printf -- '%s\n' "${missing}" | tr '|' '\n' | \
while read SPEC
do
printf -- '%s\n' "${SPEC}" | ( IFS='=' ; \
read tag source && \
docker pull "${source}" && \
docker tag "${source}" "${image}:${tag}" && \
docker push "${image}:${tag}" ;
)
done
- name: Build image for `dive`
id: build-dive-image
uses: docker/build-push-action@v6
with:
build-args: |
IMAGE_NAME=${{ env.IMAGE_NAME }}
FFMPEG_DATE=${{ needs.info.outputs.ffmpeg-date }}
FFMPEG_VERSION=${{ needs.info.outputs.ffmpeg-version }}
YTDLP_DATE=${{ fromJSON(needs.info.outputs.ytdlp-latest-release).tag.name }}
cache-from: type=gha
load: true
platforms: linux/amd64
push: false
tags: ghcr.io/${{ needs.info.outputs.lowercase-github-repository_owner }}/${{ env.IMAGE_NAME }}:dive
- name: Analysis with `dive`
continue-on-error: false
run: |
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
'ghcr.io/wagoodman/dive' \
'ghcr.io/${{ needs.info.outputs.lowercase-github-repository_owner }}/${{ env.IMAGE_NAME }}:dive' \
--ci \
--highestUserWastedPercent '0.05' \
--highestWastedBytes '50M'
- name: Build and push
id: build-push
timeout-minutes: 60
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: ${{ 'success' == needs.test.result && 'meeb' == github.repository_owner && 'pull_request' != github.event_name && 'true' || 'false' }}
tags: ghcr.io/${{ needs.info.outputs.lowercase-github-repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.event.repository.default_branch == github.ref_name && 'latest' || 'test' }}
cache-from: |
type=registry,ref=ghcr.io/${{ needs.info.outputs.lowercase-github-actor }}/${{ env.IMAGE_NAME }}:latest
type=registry,ref=ghcr.io/${{ needs.info.outputs.lowercase-github-repository_owner }}/${{ env.IMAGE_NAME }}:latest
type=gha
cache-to: |
type=gha,mode=max
${{ 'meeb' == github.repository_owner && 'pull_request' != github.event_name && 'type=inline' || '' }}
build-args: |
IMAGE_NAME=${{ env.IMAGE_NAME }}
FFMPEG_DATE=${{ needs.info.outputs.ffmpeg-date }}
FFMPEG_VERSION=${{ needs.info.outputs.ffmpeg-version }}
YTDLP_DATE=${{ fromJSON(needs.info.outputs.ytdlp-latest-release).tag.name }}