-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
203 lines (183 loc) · 7.49 KB
/
action.yml
File metadata and controls
203 lines (183 loc) · 7.49 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
name: 'Deploy Course to qBraid'
description: 'Validate, upload, and deploy a course to qBraid platform'
author: 'qBraid'
branding:
icon: 'upload-cloud'
color: 'blue'
inputs:
api-key:
description: 'qBraid API key (pass from secrets, e.g. secrets.QBRAID_API_KEY)'
required: true
repo-read-token:
description: 'GitHub token with read access (pass from secrets, e.g. secrets.GITHUB_TOKEN)'
required: true
course-json-path:
description: 'Path to course.json file'
required: false
default: 'course.json'
article-type:
description: 'Type of article (course or blog)'
required: false
default: 'course'
force-duplicate-questions:
description: 'Whether to force duplicate questions'
required: false
default: 'false'
draft:
description: 'Whether to create a draft course (true or false)'
required: false
default: 'false'
max-poll-attempts:
description: 'Maximum polling attempts before timing out'
required: false
default: '20'
poll-interval-seconds:
description: 'Seconds to wait between polling attempts'
required: false
default: '15'
max-consecutive-errors:
description: 'Maximum consecutive polling errors before failing'
required: false
default: '5'
mode:
description: 'Operation mode: "create" or "update"'
required: false
default: 'create'
course-custom-id:
description: 'Custom ID of the course (required if mode is "update")'
required: false
outputs:
course_name:
description: 'Name of the deployed course'
value: ${{ steps.validate-course.outputs.course_name }}
course-custom-id:
description: 'Custom ID of the deployed course'
value: ${{ steps.create-course.outputs.course_custom_id }}${{ steps.update-course.outputs.course_custom_id }}
qbook_url:
description: 'URL of the deployed course'
value: ${{ steps.poll-status.outputs.qbook_url }}
runs:
using: "composite"
steps:
- name: Install UV
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
shell: bash
run: |
uv pip install --system -e ${{ github.action_path }}
- name: Validate required secrets (passed as inputs)
shell: bash
run: |
if [[ -z "${{ inputs.api-key }}" ]]; then
echo "::error::api-key is empty. In your workflow, pass it from secrets (e.g. secrets.QBRAID_API_KEY)."
exit 1
fi
if [[ -z "${{ inputs.repo-read-token }}" ]]; then
echo "::error::repo-read-token is empty. In your workflow, pass it from secrets (e.g. secrets.GITHUB_TOKEN)."
exit 1
fi
- name: Stage 1 - Validate course.json structure
id: validate-course
shell: bash
run: |
python ${{ github.action_path }}/src/scripts/validate_course.py "${{ inputs.course-json-path }}"
- name: Stage 2 - Verify all notebooks exist
shell: bash
run: |
python ${{ github.action_path }}/src/scripts/verify_notebooks.py
- name: Stage 3 - Verify all image references in notebooks
shell: bash
run: |
python ${{ github.action_path }}/src/scripts/check_images.py
- name: Stage 5a - Create Course
if: inputs.mode == 'create'
id: create-course
shell: bash
run: |
python ${{ github.action_path }}/src/scripts/create_course.py \
--api-key '${{ inputs.api-key }}' \
--repo-read-token '${{ inputs.repo-read-token }}' \
--repo-url '${{ github.server_url }}/${{ github.repository }}' \
--commit-sha '${{ github.sha }}' \
--article-type '${{ inputs.article-type }}' \
--force-duplicate-questions '${{ inputs.force-duplicate-questions }}'
- name: Stage 5b - Update Course
if: inputs.mode == 'update'
id: update-course
shell: bash
run: |
python ${{ github.action_path }}/src/scripts/update_course.py \
--api-key '${{ inputs.api-key }}' \
--course-custom-id '${{ inputs.course-custom-id }}' \
--repo-read-token '${{ inputs.repo-read-token }}' \
--repo-url '${{ github.server_url }}/${{ github.repository }}' \
--commit-sha '${{ github.sha }}' \
--article-type '${{ inputs.article-type }}' \
--force-duplicate-questions '${{ inputs.force-duplicate-questions }}'
- name: Stage 6 - Poll status end point for completion
id: poll-status
shell: bash
env:
QBRAID_MAX_POLL_ATTEMPTS: ${{ inputs.max-poll-attempts }}
QBRAID_POLL_INTERVAL_SECONDS: ${{ inputs.poll-interval-seconds }}
QBRAID_MAX_CONSECUTIVE_ERRORS: ${{ inputs.max-consecutive-errors }}
run: |
COURSE_ID="${{ steps.create-course.outputs.course_custom_id }}${{ steps.update-course.outputs.course_custom_id }}"
if [[ -z "$COURSE_ID" ]]; then
echo "::error::course_custom_id output is empty after create/update step. This usually means the API response shape changed or did not include article.customId."
exit 1
fi
python ${{ github.action_path }}/src/scripts/poll_files_progress.py '${{ inputs.api-key }}' "$COURSE_ID"
- name: Create deployment summary
if: success()
shell: bash
run: |
cat >> $GITHUB_STEP_SUMMARY << 'DELIMITER'
# 🎉 Course Deployment Successful
Your course has been successfully deployed to qBraid!
**Course Name:** ${{ steps.validate-course.outputs.course_name }}
**Course Custom ID:** ${{ steps.create-course.outputs.course_custom_id }}${{ steps.update-course.outputs.course_custom_id }}
**qBook URL:** ${{ steps.poll-status.outputs.qbook_url }}
## Next Steps
You can now access your course at the qBook URL above.
DELIMITER
- name: Send notification comment
if: success()
uses: actions/github-script@v7
with:
script: |
try {
await github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: `🎓 **Course Deployment Complete!**\n\nYour course is now live on qBraid.\n\n**View your course:** ${{ steps.poll-status.outputs.qbook_url }}\n\nCourse name: \`${{ steps.validate-course.outputs.course_name }}\`\n\nCourse Custom ID: \`${{ steps.create-course.outputs.course_custom_id }}${{ steps.update-course.outputs.course_custom_id }}\``
});
} catch (error) {
if (error.status === 403) {
core.warning('Could not create commit comment due to missing permissions. Please ensure the workflow has "contents: write" permission or "Read and write permissions" are enabled in repository settings.');
} else {
core.warning(`Failed to send notification: ${error.message}`);
}
}
- name: Send failure notification
if: failure()
uses: actions/github-script@v7
with:
script: |
try {
await github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: `❌ **Course Deployment Failed**\n\nThe deployment to qBraid failed. Please check the logs for more details.`
});
} catch (error) {
core.warning(`Failed to send notification: ${error.message}`);
}