-
-
Notifications
You must be signed in to change notification settings - Fork 17
149 lines (132 loc) · 5.13 KB
/
Copy pathrebuild-bottles.yml
File metadata and controls
149 lines (132 loc) · 5.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
---
name: Rebuild Bottles
run-name: Rebuild Bottles (${{ github.event.inputs.formula || 'all' }})
permissions: {}
on:
schedule:
- cron: '0 2 * * 0' # Run weekly on Sunday at 2 AM UTC
workflow_dispatch:
inputs:
formula:
description: 'Formula name to rebuild (e.g., sunshine, sunshine-beta, cuda@13.1)'
required: true
type: string
jobs:
detect-formulas:
name: Detect Formulas
outputs:
formulas: ${{ steps.detect.outputs.formulas }}
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Detect formula files
id: detect
env:
INPUT_FORMULA: ${{ github.event.inputs.formula }}
run: |
if [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then
# Manual trigger - use the input formula name
FORMULAS="[\"${INPUT_FORMULA}\"]"
else
# Scheduled - find all formula files and extract names
FORMULA_FILES=$(find Formula -name '*.rb' -type f)
ALL_FORMULAS=$(echo "$FORMULA_FILES" | xargs -I {} basename {} .rb | jq -R -s -c 'split("\n")[:-1]')
# Load skip list
SKIP_LIST=$(jq -c '.formulas' ci_config/rebuild_bottles_skiplist.json)
# Filter out formulas in the skip list
FORMULAS=$(echo "$ALL_FORMULAS" | jq -c --argjson skip "$SKIP_LIST" '. - $skip')
echo "All formulas: ${ALL_FORMULAS}"
echo "Skip list: ${SKIP_LIST}"
fi
echo "formulas=${FORMULAS}" >> "${GITHUB_OUTPUT}"
echo "Formulas to rebuild: ${FORMULAS}"
rebuild:
name: Rebuild ${{ matrix.formula }}
env:
COMMIT_MESSAGE: 'chore: ${{ matrix.formula }}: rebuild bottles'
MATRIX_FORMULA: ${{ matrix.formula }}
PR_BRANCH_NAME: bot/update-${{ matrix.formula }}-formula
needs: detect-formulas
permissions:
contents: read
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
formula: ${{ fromJson(needs.detect-formulas.outputs.formulas) }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Find formula file
id: find
run: |
# Find the formula file path from the formula name
FORMULA_NAME="${MATRIX_FORMULA}"
FORMULA_FILE=$(find Formula -name "${FORMULA_NAME}.rb" -type f | head -n 1)
if [ -z "${FORMULA_FILE}" ]; then
echo "Error: Formula file for '${FORMULA_NAME}' not found"
exit 1
fi
echo "formula_file=${FORMULA_FILE}" >> "${GITHUB_OUTPUT}"
echo "Found formula file: ${FORMULA_FILE}"
- name: Update formula with rebuild comment
id: update
env:
FORMULA_FILE: ${{ steps.find.outputs.formula_file }}
run: |
# Current rebuild number (timestamp-based for uniqueness)
REBUILD_NUM=$(date -u +%s)
COMMENT="# rebuild: ${REBUILD_NUM}"
# Check if a rebuild comment already exists
if grep -q "^# rebuild:" "${FORMULA_FILE}"; then
# Update existing comment
sed -i "s/^# rebuild:.*/${COMMENT}/" "${FORMULA_FILE}"
echo "action=updated" >> "${GITHUB_OUTPUT}"
else
# Add new comment at the end of the file
echo "${COMMENT}" >> "${FORMULA_FILE}"
echo "action=added" >> "${GITHUB_OUTPUT}"
fi
# Show the changes
echo "Changes made to ${FORMULA_FILE}:"
git diff "${FORMULA_FILE}"
- name: Push changes
uses: actions-js/push@5a7cbd780d82c0c937b5977586e641b2fd94acc5 # v1.5
with:
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ vars.GH_BOT_NAME }}
branch: ${{ env.PR_BRANCH_NAME }}
github_token: ${{ secrets.GH_BOT_TOKEN }}
message: ${{ env.COMMIT_MESSAGE }}
force: true
- name: Create or update Pull Request
env:
ACTION: ${{ steps.update.outputs.action }}
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
# Check if PR already exists
EXISTING_PR=$(gh pr list --head "${PR_BRANCH_NAME}" --json number --jq '.[0].number' || echo "")
if [ -z "${EXISTING_PR}" ]; then
echo "Creating new PR..."
PR_URL=$(gh pr create \
--title "${COMMIT_MESSAGE}" \
--body "Automatic rebuild bottles for \`${MATRIX_FORMULA}\`." \
--head "${PR_BRANCH_NAME}" \
--base master)
PR_NUMBER=$(echo "${PR_URL}" | grep -oE '[0-9]+$')
echo "Created new PR #${PR_NUMBER}: ${PR_URL}"
# Enable auto-merge
echo "Enabling auto-merge for PR #${PR_NUMBER}..."
gh pr merge "${PR_NUMBER}" \
--auto \
--delete-branch \
--squash \
--subject "${COMMIT_MESSAGE}"
echo "Auto-merge enabled"
fi