-
Notifications
You must be signed in to change notification settings - Fork 2
223 lines (195 loc) · 8.13 KB
/
Copy pathgenerate_defs_visibility.yml
File metadata and controls
223 lines (195 loc) · 8.13 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
name: Generate visibility configuration files
on:
workflow_dispatch:
inputs:
slicer:
type: choice
options:
- all
- OrcaSlicer
- PrusaSlicer
- BambuStudio
- ElegooSlicer
- CrealityPrint
default: all
description: Slicer to generate visibility for
required: true
build-type:
type: choice
options:
- all
- nightly
- latest_release
default: all
description: Build type to run
required: true
release-tag:
type: string
default: ''
description: Optional release tag override for testing one version
required: false
force-regenerate:
type: boolean
default: false
description: Regenerate latest_release even when visibility already exists
required: false
workflow_run:
types:
- completed
workflows:
- Build and Extract JSON
permissions:
contents: write
jobs:
generate_defs_visibility:
runs-on: ubuntu-latest
concurrency:
group: slicer-out-${{ github.ref_name }}
cancel-in-progress: false
env:
continue_generate: 'true'
strategy:
fail-fast: false
max-parallel: 1
matrix:
slicer:
- OrcaSlicer
- PrusaSlicer
- BambuStudio
- ElegooSlicer
- CrealityPrint
build-type:
- nightly
- latest_release
include:
- slicer: OrcaSlicer
repo: OrcaSlicer/OrcaSlicer
- slicer: PrusaSlicer
repo: prusa3d/PrusaSlicer
- slicer: BambuStudio
repo: BambuLab/BambuStudio
- slicer: ElegooSlicer
repo: ELEGOO-3D/ElegooSlicer
- slicer: CrealityPrint
repo: CrealityOfficial/CrealityPrint
steps:
- name: Apply dispatch filters
run: |
selected_slicer="${{ inputs.slicer || 'all' }}"
selected_build_type="${{ inputs.build-type || 'all' }}"
if [[ "$selected_slicer" != "all" && "$selected_slicer" != "${{ matrix.slicer }}" ]]; then
echo "Skipping ${{ matrix.slicer }} because slicer filter is $selected_slicer."
echo "continue_generate=false" >> "$GITHUB_ENV"
exit 0
fi
if [[ "$selected_build_type" != "all" && "$selected_build_type" != "${{ matrix.build-type }}" ]]; then
echo "Skipping ${{ matrix.build-type }} because build-type filter is $selected_build_type."
echo "continue_generate=false" >> "$GITHUB_ENV"
exit 0
fi
- name: Checkout repository
if: env.continue_generate == 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Install the latest version of uv
if: env.continue_generate == 'true'
uses: astral-sh/setup-uv@v6
with:
python-version: 3.13
- name: Install generate_defs_visibility cli tool
if: env.continue_generate == 'true'
run: |
uv tool install ./tools/generate_defs_visibility
- name: Generate visibility configuration files
if: env.continue_generate == 'true'
env:
OPENAI_API_KEY: ${{ secrets.SLICER_BUILDS_OPENAI_API_KEY }}
run: |
set -euo pipefail
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
cd "slicers/${{ matrix.slicer }}/out"
release_tag_override="${{ inputs.release-tag || '' }}"
if [[ -n "$release_tag_override" ]]; then
latest_release_tag="$release_tag_override"
latest_release_json=$(curl -fsSL "https://api.github.com/repos/${{ matrix.repo }}/releases/tags/${latest_release_tag}" || echo '{}')
else
latest_release_json=$(curl -fsSL "https://api.github.com/repos/${{ matrix.repo }}/releases/latest")
latest_release_tag=$(echo "$latest_release_json" | jq -r '.tag_name')
fi
latest_release_hash=$(curl -fsSL "https://api.github.com/repos/${{ matrix.repo }}/commits/refs/tags/${latest_release_tag}" | jq -r '.sha')
upstream_published_at=$(echo "$latest_release_json" | jq -r '.published_at // empty')
latest_stored_tag=$(jq -r '.latest // empty' _index.json 2>/dev/null || true)
release_visibility_present=$(jq -r --arg tag "$latest_release_tag" '(.versions[$tag].visibility? != null)' _index.json 2>/dev/null || echo false)
head_hash=$(curl -fsSL "https://api.github.com/repos/${{ matrix.repo }}/commits/HEAD" | jq -r '.sha')
echo latest_release_tag=$latest_release_tag
echo latest_release_hash=$latest_release_hash
echo latest_stored_tag=$latest_stored_tag
echo release_visibility_present=$release_visibility_present
echo head_hash=$head_hash
if [[ "$release_visibility_present" != "true" ]] || [[ "${{ inputs.force-regenerate || false }}" == "true" ]]; then
if [[ "$head_hash" == "$latest_release_hash" ]]; then
echo "Latest release found at HEAD"
latest_release_at_head=true
fi
elif [[ "${{ matrix.build-type }}" == "latest_release" ]]; then
echo "The latest release has already been generated. Exiting..."
exit 0
fi
if [[ "${{ matrix.build-type }}" == "latest_release" ]] && [[ "${latest_release_at_head:-false}" == "true" ]] && [[ "${{ inputs.build-type || 'all' }}" != "latest_release" ]]; then
echo "The latest release is at the HEAD of the repo. The nightly build will generate the release files. Exiting..."
exit 0
fi
if [[ "${{ matrix.build-type }}" == "nightly" ]]; then
ref=HEAD
folder_name=nightly
upstream_ref="$head_hash"
else
ref=refs/tags/$latest_release_tag
folder_name=$latest_release_tag
upstream_ref="$latest_release_hash"
fi
if ! [[ -d "$folder_name" ]]; then
echo "The folder for the specified version does not exist: $folder_name"
exit 1
fi
pushd "$folder_name"
uvx generate-defs-visibility --slicer ${{ matrix.slicer }} --ref "$ref" --cache-dir "../.cache/${folder_name}"
popd
created_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)
workflow_run_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
../../../tools/update_slicer_index.py \
--index _index.json \
--version "$folder_name" \
--kind visibility \
--created-at "$created_at" \
--upstream-ref "$upstream_ref" \
--upstream-published-at "$upstream_published_at" \
--source-repo "${{ matrix.repo }}" \
--workflow-run-url "$workflow_run_url" \
$([[ "$folder_name" != "nightly" ]] && echo --latest)
if [[ "${{ matrix.build-type }}" == "nightly" && "${latest_release_at_head:-false}" == "true" ]]; then
mkdir -p "$latest_release_tag"
cp -rf nightly/conditional_visibility.json "$latest_release_tag" || true
../../../tools/update_slicer_index.py \
--index _index.json \
--version "$latest_release_tag" \
--latest \
--kind visibility \
--created-at "$created_at" \
--upstream-ref "$upstream_ref" \
--upstream-published-at "$upstream_published_at" \
--source-repo "${{ matrix.repo }}" \
--workflow-run-url "$workflow_run_url"
fi
cd ../../..
git add "slicers/${{ matrix.slicer }}/out"
if git diff --cached --quiet; then
echo "No changes to commit."
else
slicer="${{ matrix.slicer }}"
git commit -m "chore(${slicer,,}): generate visibility for ${folder_name} @ ${upstream_ref:0:12}"
git pull --rebase origin "${GITHUB_REF_NAME}"
git push origin "HEAD:${GITHUB_REF_NAME}"
fi