2828 required : false
2929 type : number
3030 default : 60
31+ download_version :
32+ description : |
33+ Download an existing build by version number instead of creating a new build.
34+ When provided, build and package-init jobs will be skipped.
35+ Example: 2025.703.161609
36+ required : false
37+ type : string
3138 secrets :
3239 COPR_BETA_WEBHOOK_TOKEN :
3340 description : ' Copr beta webhook token. This should be a secret.'
4451 name : Create/update copr package
4552 runs-on : ubuntu-latest
4653 container : fedora:latest
54+ if : inputs.download_version == ''
4755 env :
4856 BASE_URL : https://copr.fedorainfracloud.org/api_3
4957 OWNERNAME : ${{ inputs.copr_ownername }}
5866 echo "copr_ownername: ${{ inputs.copr_ownername }}"
5967 echo "auto_update_package: ${{ inputs.auto_update_package }}"
6068 echo "job_timeout: ${{ inputs.job_timeout }}"
69+ echo "download_version: ${{ inputs.download_version }}"
6170
6271 - name : Test secrets
6372 id : test_secrets
@@ -134,7 +143,9 @@ jobs:
134143 build :
135144 name : Copr build
136145 needs : package-init
137- if : github.repository_owner == inputs.github_org_owner
146+ if : >-
147+ github.repository_owner == inputs.github_org_owner &&
148+ inputs.download_version == ''
138149 runs-on : ubuntu-latest
139150 timeout-minutes : ${{ inputs.job_timeout }}
140151 outputs :
@@ -184,7 +195,8 @@ jobs:
184195 needs : build
185196 if : |
186197 always() &&
187- needs.build.outputs.BUILD_CANCEL == 'true'
198+ needs.build.outputs.BUILD_CANCEL == 'true' &&
199+ inputs.download_version == ''
188200 runs-on : ubuntu-latest
189201 container : fedora:latest
190202 steps :
@@ -209,7 +221,12 @@ jobs:
209221
210222 download-build :
211223 name : Download build
212- if : needs.build.outputs.BUILD_SUCCESS == 'true'
224+ if : |
225+ always() &&
226+ (
227+ (needs.build.outputs.BUILD_SUCCESS == 'true' && inputs.download_version == '') ||
228+ (inputs.download_version != '')
229+ )
213230 needs : build
214231 runs-on : ubuntu-latest
215232 container : fedora:latest
@@ -219,16 +236,99 @@ jobs:
219236 dnf install -y \
220237 copr-cli \
221238 nodejs \
222- zip
239+ zip \
240+ jq
241+
242+ - name : Setup Copr CLI config
243+ if : inputs.download_version != ''
244+ run : |
245+ if [ -n "${{ secrets.COPR_CLI_CONFIG }}" ]; then
246+ mkdir -p ~/.config
247+ echo "${{ secrets.COPR_CLI_CONFIG }}" > ~/.config/copr
248+ else
249+ echo "Cannot download build. No Copr CLI configuration file found."
250+ exit 1
251+ fi
252+
253+ - name : Find and wait for build
254+ if : inputs.download_version != ''
255+ run : |
256+ VERSION="${{ inputs.download_version }}-1"
257+ PACKAGE_NAME="${{ github.event.repository.name }}"
258+ OWNERNAME="${{ inputs.copr_ownername }}"
259+ PROJECT="beta"
260+
261+ echo "Looking for build with version: ${VERSION}"
262+ echo "Searching in project: ${PROJECT}"
263+
264+ # Find build ID by version
265+ BUILD_ID=""
266+ page=0
267+ while [ -z "${BUILD_ID}" ] && [ $page -lt 10 ]; do
268+ builds=$(copr-cli list-builds --output-format json "${OWNERNAME}/${PROJECT}" --limit 50 --offset $((page * 50)))
269+
270+ BUILD_ID=$(echo "$builds" | jq -r --arg version "${VERSION}" --arg package "$PACKAGE_NAME" '
271+ .[] | select(.source_package.name == $package and (.source_package.version | startswith($version))) | .id | tostring
272+ ' | head -n1)
273+
274+ if [ -n "${BUILD_ID}" ] && [ "${BUILD_ID}" != "null" ]; then
275+ break
276+ fi
277+
278+ page=$((page + 1))
279+ done
280+
281+ if [ -z "${BUILD_ID}" ] || [ "${BUILD_ID}" = "null" ]; then
282+ echo "No build found for version ${VERSION} in project ${PROJECT}"
283+ exit 1
284+ fi
285+
286+ echo "Found build ID: ${BUILD_ID}"
287+ echo "BUILD_ID=${BUILD_ID}" >> $GITHUB_ENV
288+
289+ # Wait for build to complete
290+ echo "Waiting for build to complete..."
291+ while true; do
292+ status=$(copr-cli get-build "${BUILD_ID}" --output-format json | jq -r '.state')
293+ echo "Build status: $status"
294+
295+ case "$status" in
296+ "succeeded")
297+ echo "Build completed successfully"
298+ break
299+ ;;
300+ "failed"|"canceled"|"skipped")
301+ echo "Build failed with status: $status"
302+ exit 1
303+ ;;
304+ "running"|"pending"|"starting"|"importing")
305+ echo "Build still in progress, waiting 30 seconds..."
306+ sleep 30
307+ ;;
308+ *)
309+ echo "Unknown build status: $status"
310+ exit 1
311+ ;;
312+ esac
313+ done
223314
224315 - name : Download build
225316 run : |
317+ # Use provided version's build ID or the one from the build job
318+ if [ -n "${{ inputs.download_version }}" ]; then
319+ BUILD_ID="${BUILD_ID}"
320+ else
321+ BUILD_ID="${{ needs.build.outputs.BUILD_ID }}"
322+ fi
323+
324+ echo "Downloading build ID: ${BUILD_ID}"
325+
226326 mkdir -p artifacts
227327 copr-cli \
228328 download-build \
229329 --dest . \
230330 --rpms \
231- ${{ needs.build.outputs. BUILD_ID }}
331+ "${ BUILD_ID}"
232332
233333 - name : Setup gh actions artifact client
234334 uses : lhotari/gh-actions-artifact-client@v2
@@ -239,4 +339,3 @@ jobs:
239339 name=build-$(basename "$file")
240340 echo "Uploading $name, file: $file"
241341 zip - "$file" | gh-actions-artifact-client.js upload "${name}" --retentionDays=7
242- done
0 commit comments