Repository navigation
87 lines (79 loc) · 2.93 KB
/
Copy pathrequeue-evaluation.yml
File metadata and controls
87 lines (79 loc) · 2.93 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
name: Requeue Evaluation
on:
workflow_call:
inputs:
workflow-file:
description: "The workflow file to requeue"
required: true
type: string
repeat:
description: "Current repeat count"
required: true
type: string
workflow-inputs:
description: "JSON string of workflow inputs to pass (excluding repeat)"
required: true
type: string
existing-tag:
description: "Ephemeral tag already created earlier in the run (avoids re-creating it at requeue time)"
required: false
default: ""
type: string
permissions:
contents: write
actions: write
jobs:
requeue-if-needed:
runs-on: ubuntu-latest
if: ${{ inputs.repeat != '1' }}
steps:
- name: Reuse tag for requeue
env:
GH_TOKEN: ${{ github.token }}
INPUTS_JSON: ${{ inputs.workflow-inputs }}
run: |
REF="${{ github.ref }}"
if [[ "${REF}" == refs/tags/eval-run-* ]]; then
# Already running from an ephemeral tag: reuse it
TAG_NAME="${{ github.ref_name }}"
echo "Reusing existing ephemeral tag: ${TAG_NAME}"
elif [[ -n "${{ inputs.existing-tag }}" ]]; then
# A tag was already created earlier in this run (see the pin-commit job)
TAG_NAME="${{ inputs.existing-tag }}"
echo "Using previously created ephemeral tag: ${TAG_NAME}"
else
echo "No ephemeral tag is available for requeue."
exit 1
fi
# Build the workflow dispatch command with inputs from JSON
NEXT_REPEAT=$(( ${{ inputs.repeat }} - 1 ))
# Build the arguments array safely (handles spaces and special chars)
ARGS=()
while IFS= read -r line; do
key="${line%%=*}"
value="${line#*=}"
ARGS+=("-f" "${key}=${value}")
done < <(printf '%s' "${INPUTS_JSON}" | jq -r 'to_entries[] | select(.value != null) | "\(.key)=\(.value)"')
# Trigger the workflow using the tag as ref
gh workflow run ${{ inputs.workflow-file }} \
--repo ${{ github.repository }} \
--ref "${TAG_NAME}" \
-f repeat="${NEXT_REPEAT}" \
"${ARGS[@]}"
cleanup-ephemeral-tag:
runs-on: ubuntu-latest
if: ${{ inputs.repeat == '1' }}
steps:
- name: Delete ephemeral tag if running from one
env:
GH_TOKEN: ${{ github.token }}
run: |
REF="${{ github.ref }}"
if [[ "${REF}" == refs/tags/eval-run-* ]]; then
TAG_NAME="${{ github.ref_name }}"
echo "Cleaning up ephemeral tag: ${TAG_NAME}"
gh api repos/${{ github.repository }}/git/refs/tags/${TAG_NAME} \
--method DELETE || echo "Tag deletion failed or already deleted"
else
echo "Not running from an ephemeral tag (ref: ${REF}), skipping cleanup"
fi