-
Notifications
You must be signed in to change notification settings - Fork 0
218 lines (180 loc) · 8.99 KB
/
Copy pathrun.yaml
File metadata and controls
218 lines (180 loc) · 8.99 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
name: Build R Packages
on:
workflow_dispatch:
push:
branches:
- 'build/**'
paths:
- 'logs/dispatched-packages.txt'
- 'logs/successful-packages.txt'
concurrency:
group: build-r-packages-${{ github.ref }}
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
token: ${{ secrets.PAT }}
persist-credentials: true
- name: Update to latest
run: |
git pull origin ${GITHUB_REF#refs/heads/}
git reset --hard origin/${GITHUB_REF#refs/heads/}
- name: Save kubeconfig
shell: bash
run: mkdir -p ~/.kube && echo "${{ secrets.KUBECONFIG }}" > ~/.kube/config
- name: Install Kubectl
run: |
curl -LO 'https://dl.k8s.io/release/v1.34.1/bin/linux/amd64/kubectl' && \
chmod +x ./kubectl && \
mv ./kubectl /usr/local/bin/kubectl && \
kubectl version
- name: Check for completed cycle
id: cycle_check
run: |
# Check if PACKAGES file exists (indicates completed cycle)
if [[ -f "PACKAGES" ]]; then
echo "Cycle already completed (PACKAGES file exists). Skipping."
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Manage build lifecycle
if: steps.cycle_check.outputs.skip != 'true'
env:
RCLONE_CONF: ${{secrets.RCLONE_CONF}}
id: build
run: |
set -euxo pipefail
# Use branch name as the build identifier
BRANCH_NAME=${GITHUB_REF#refs/heads/}
BUILD_ID=$(echo "${BRANCH_NAME}" | sed 's|build/||' | tr '/' '-')
echo "Build ID: ${BUILD_ID}"
echo "Branch: ${BRANCH_NAME}"
# Check if this is first run (no biocdeps.json yet)
if [[ ! -s "biocdeps.json" ]]; then
echo "First run - setting up Kubernetes resources..."
CONTAINER=$(cat CONTAINER_BASE_IMAGE.bioc)
# Setup Kubernetes resources - this handles running deps_json.R via init container
bash ./.github/scripts/setup_k8s.sh "nfs-client" "500Gi" "${BUILD_ID}"
else
echo "Continuing existing build..."
CONTAINER=$(cat CONTAINER_BASE_IMAGE.bioc)
# Handle completed jobs
bash ./.github/scripts/handle_k8s_jobs.sh \
"${BUILD_ID}" \
"logs/successful-packages.txt" \
"logs/failed-packages.txt"
fi
# Ensure log directory exists before any operations
mkdir -p logs
touch logs/dispatched-packages.txt
# Find and dispatch packages
python ./.github/scripts/find_ready_pkgs.py \
"biocdeps.json" \
"ready_packages.txt" \
"logs/dispatched-packages.txt" \
"logs/successful-packages.txt" \
"remaining-packages.json"
# Calculate truncated build ID for PVC name
BUILD_ID_CLEAN=$(echo "${BUILD_ID}" | tr '[:upper:]' '[:lower:]' | tr '.' '-' | tr -cd '[:alnum:]-')
VERSION_SUFFIX="${BUILD_ID_CLEAN: -3}"
DATE_PART=$(echo "$BUILD_ID_CLEAN" | cut -d'-' -f1-3 | tr -d '-')
CONTAINER_HINT=$(echo "$BUILD_ID_CLEAN" | sed 's/^[0-9-]*-[0-9]*-//' | sed 's/-[^-]*$//' | cut -c1-4)
BUILD_ID_SHORT="${DATE_PART}-${CONTAINER_HINT}-${VERSION_SUFFIX}"
PVC_NAME="pvc-${BUILD_ID_SHORT}"
# Dispatch jobs with xargs and delay
cat "ready_packages.txt" | xargs -i bash -c "bash ./.github/scripts/dispatch_k8s_job.sh {} ${CONTAINER} ${PVC_NAME} ${BUILD_ID} && sleep 1"
# Track if we had any new activity
git add .
ACTIVITY_CHECK=$(git diff --staged --name-status | grep -q "logs/.*packages.txt" && echo "true" || echo "false")
echo "had_activity=${ACTIVITY_CHECK}" >> $GITHUB_OUTPUT
# Get counter values
NULL_PUSH_COUNT=$(cat "null_push_counter" 2>/dev/null || echo "0")
RESET_ATTEMPTS=$(cat "reset_attempts_counter" 2>/dev/null || echo "0")
# Note: Reset failed logic removed - handle failures manually or via separate workflow if needed
# Backup changed files to temp directory
mkdir -p /tmp/restore
# Stage all changes to identify modified files
git add .
# Copy changed files to restore directory
git diff --staged --name-only | xargs -r -I{} bash -c 'mkdir -p "/tmp/restore/$(dirname "{}")" && cp "{}" "/tmp/restore/{}"'
echo "Backup complete - copied changed files"
- name: Commit and push results
if: steps.cycle_check.outputs.skip != 'true'
id: repo_changes
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
git pull origin ${BRANCH_NAME} && git reset --hard origin/${BRANCH_NAME} || git reset --hard origin/${BRANCH_NAME}
cp -r /tmp/restore/* ./ || true
git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com'
git add . || true
# Check if there are actual changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
# If no changes, increment the null push counter
NULL_PUSH_COUNT=$(cat "null_push_counter" 2>/dev/null || echo "0")
NEW_COUNT=$((NULL_PUSH_COUNT + 1))
echo "${NEW_COUNT}" > "null_push_counter"
# Commit just the counter change
git add "null_push_counter"
git commit -m "Increment null push counter to ${NEW_COUNT}"
git push || (git pull --rebase && git push)
echo "pushed=false" >> $GITHUB_OUTPUT
else
# Check for new successful packages
NEW_SUCCESS=$(git diff --staged -- "logs/successful-packages.txt" | grep -c "^\+" | grep -v "^\+\+\+" || echo "0")
# Always reset null push counter on meaningful changes
echo "0" > "null_push_counter"
git add "null_push_counter"
# Only reset attempts counter if we have new successful packages
if [ "${NEW_SUCCESS}" -gt 0 ]; then
echo "New successful packages detected (${NEW_SUCCESS}), resetting attempts counter"
echo "0" > "reset_attempts_counter"
git add "reset_attempts_counter"
fi
# Commit all changes
git commit -m "Build state update: ${{ github.run_id }}"
git push || (git pull --rebase && git push)
echo "pushed=true" >> $GITHUB_OUTPUT
fi
- name: Check if cycle is ready to finish
if: steps.cycle_check.outputs.skip != 'true'
id: check_complete
run: |
if bash ./.github/scripts/check_cycle_complete.sh > /tmp/cycle-check-output.txt 2>&1; then
echo "notify=yes" >> $GITHUB_OUTPUT
# Get container name for notification
CONTAINER=$(cat CONTAINER_BASE_IMAGE.bioc)
# Get stats for notification
SUCCESSFUL=$(wc -l < logs/successful-packages.txt 2>/dev/null || echo 0)
FAILED=$(wc -l < logs/failed-packages.txt 2>/dev/null || echo 0)
# Count only blocked packages (remaining packages that are not failed)
REMAINING=$(python3 -c "import json; remaining = json.load(open('remaining-packages.json')); failed = set(line.strip() for line in open('logs/failed-packages.txt') if line.strip()); blocked = [pkg for pkg in remaining if pkg not in failed]; print(len(blocked))" 2>/dev/null || echo 0)
# Create simple single-line notification message (avoid quotes to prevent JSON escaping issues)
MSG="Build cycle ready for ${CONTAINER}: ${SUCCESSFUL} successful, ${FAILED} failed, ${REMAINING} blocked. Run finish_cycle: https://github.com/${{ github.repository }}/actions/workflows/finish_cycle.yaml"
# Replace any double quotes with single quotes to avoid JSON issues
MSG="${MSG//\"/\'}"
echo "SLACK_MESSAGE=${MSG}" >> "$GITHUB_ENV"
else
echo "notify=no" >> $GITHUB_OUTPUT
cat /tmp/cycle-check-output.txt || true
fi
- name: Notify slack channel
uses: slackapi/slack-github-action@v2.1.1
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
{
"channel": "${{ secrets.SLACK_CHANNEL_ID }}",
"text": "${{ env.SLACK_MESSAGE }}"
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
if: env.SLACK_BOT_TOKEN != null && env.SLACK_CHANNEL_ID != null && steps.check_complete.outputs.notify == 'yes'
continue-on-error: true