-
Notifications
You must be signed in to change notification settings - Fork 73
286 lines (234 loc) · 7.88 KB
/
package.yaml
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
name: ytld-sub Docker Build
on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: ytdl-sub
jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
version:
name: version
runs-on: ubuntu-latest
outputs:
pypi_version: ${{ steps.set_outputs.outputs.pypi_version }}
local_version: ${{ steps.set_outputs.outputs.local_version }}
init_contents: ${{ steps.set_outputs.outputs.init_contents }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: master
- name: Set date and commit hash variables
run: |
echo "DATE=$(date +'%Y.%m.%d')" >> $GITHUB_ENV
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Count number of commits on master on day, minus 1 to account for post-push
run: |
echo "DATE_COMMIT_COUNT=$(($(git rev-list --count master --since='${{ env.DATE }} 00:00:00')-1))" >> $GITHUB_ENV
- name: Set pypi and local version values
run: |
echo "LOCAL_VERSION=${{ env.DATE }}+${{ env.COMMIT_HASH }}" >> $GITHUB_ENV
if [ ${{ env.DATE_COMMIT_COUNT }} -le "0" ]
then
echo "PYPI_VERSION=${{ env.DATE }}" >> $GITHUB_ENV
else
echo "PYPI_VERSION=${{ env.DATE }}.post${{ env.DATE_COMMIT_COUNT }}" >> $GITHUB_ENV
fi
- name: Test versions
run: |
echo "${{ env.PYPI_VERSION }}"
echo "${{ env.LOCAL_VERSION }}"
- id: set_outputs
run: |
echo "pypi_version=${{ env.PYPI_VERSION }}" >> "$GITHUB_OUTPUT"
echo "local_version=${{ env.LOCAL_VERSION }}" >> "$GITHUB_OUTPUT"
echo 'init_contents=__pypi_version__ = "${{ env.PYPI_VERSION }}";__local_version__ = "${{ env.LOCAL_VERSION }}"' >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [ "3.10" ]
permissions:
contents: read
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Build Wheel
run: |
make docker_stage
- name: Save Python build cache
uses: actions/cache@v3
with:
path: docker/root
key: ${{github.sha}}
# Build ARM64 container, only on master branch to save time testing
package-arm64:
runs-on: ubuntu-22.04
needs: [
build
]
permissions:
contents: read
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
steps:
- uses: actions/checkout@v3
- name: Restore Python build cache
uses: actions/cache@v3
with:
path: docker/root
key: ${{github.sha}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/arm64
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v2.0.0
- name: Build Docker Image
run: |
docker buildx build \
--platform=linux/arm64 \
--cache-to=type=local,dest=/tmp/build-cache/arm64 \
--tag $IMAGE_NAME \
--label "runnumber=${GITHUB_RUN_ID}" \
docker/
- name: Save ARM64 build cache
uses: actions/cache@v3
with:
path: /tmp/build-cache/arm64
key: ${{github.sha}}-arm64
# Build AMD64 container
package-amd64:
runs-on: ubuntu-22.04
needs: [
build
]
permissions:
contents: read
steps:
- uses: actions/checkout@v3
- name: Restore Python build cache
uses: actions/cache@v3
with:
path: docker/root
key: ${{github.sha}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/amd64
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v2.0.0
- name: Build Docker Image
run: |
docker buildx build \
--platform=linux/amd64 \
--cache-to=type=local,dest=/tmp/build-cache/amd64 \
--tag $IMAGE_NAME \
--label "runnumber=${GITHUB_RUN_ID}" \
docker/
- name: Save AMD64 build cache
uses: actions/cache@v3
with:
path: /tmp/build-cache/amd64
key: ${{github.sha}}-amd64
# On master branch, build the docker manifest file from the cached
# docker builds and push to the registry
deploy:
runs-on: ubuntu-22.04
needs: [
version,
build,
package-arm64,
package-amd64
]
permissions:
packages: write
contents: read
if: ${{
github.ref == 'refs/heads/master'
&& !contains(github.event.head_commit.message, '[DEV]')
&& !contains(github.event.head_commit.message, '[DOCS]')
}}
steps:
- uses: actions/checkout@v3
- name: Restore Python build cache
uses: actions/cache@v3
with:
path: docker/root
key: ${{github.sha}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/amd64,linux/arm64
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v2.0.0
- name: login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Restore ARM64 build cache
uses: actions/cache@v3
with:
path: /tmp/build-cache/arm64
key: ${{github.sha}}-arm64
- name: Restore AMD64 build cache
uses: actions/cache@v3
with:
path: /tmp/build-cache/amd64
key: ${{github.sha}}-amd64
- name: Format image_id
id: formatted-image_id
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo IMAGE_ID=${IMAGE_ID}
echo ::set-output name=IMAGE_ID::${IMAGE_ID}
- name: Get the version
id: formatted_version
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo VERSION=${VERSION}
echo ::set-output name=VERSION::${VERSION}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.formatted-image_id.outputs.IMAGE_ID }}
labels: |
runnumber=${{ github.run_number }}
maintainer=${{ github.repository_owner }}
org.opencontainers.image.authors=${{ github.repository_owner }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.documentation=https://ytdl-sub.readthedocs.io/
tags: |
type=raw,value=${{ steps.formatted_version.outputs.VERSION }}
type=raw,value=${{ needs.version.outputs.pypi_version }}
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: "docker/"
cache-from: |
type=local,src=/tmp/build-cache/amd64
type=local,src=/tmp/build-cache/arm64