ci: fix AI triage (a.k.a. 'traiage') workflow (#19912)

- Updates default template name
- Set `GITHUB_TOKEN` env
- Implement simple `traiage.sh resume` script to download output
artifact
This commit is contained in:
Cian Johnston
2025-09-22 16:42:42 +01:00
committed by GitHub
parent d2da8357cf
commit 6d1c425421
2 changed files with 40 additions and 23 deletions
+14 -21
View File
@@ -10,21 +10,13 @@ on:
template_name: template_name:
description: 'Coder template to use for workspace' description: 'Coder template to use for workspace'
required: true required: true
default: 'ai-workspace' default: 'traiage'
type: string type: string
prefix: prefix:
description: 'Prefix for workspace name' description: 'Prefix for workspace name'
required: false required: false
default: 'traiage' default: 'traiage'
type: string type: string
persistence_mode:
description: 'Persistence mode (push or archive)'
required: false
type: choice
options:
- push
- archive
default: 'archive'
jobs: jobs:
traiage: traiage:
@@ -51,6 +43,7 @@ jobs:
id: extract-context id: extract-context
env: env:
ISSUE_URL: ${{ inputs.issue_url }} ISSUE_URL: ${{ inputs.issue_url }}
GITHUB_TOKEN: ${{ github.token }}
run: | run: |
issue_number="$(gh issue view "${ISSUE_URL}" --json number --jq '.number')" issue_number="$(gh issue view "${ISSUE_URL}" --json number --jq '.number')"
context_key="gh-${issue_number}" context_key="gh-${issue_number}"
@@ -94,6 +87,7 @@ jobs:
env: env:
WORKSPACE_NAME: ${{ steps.create-workspace.outputs.workspace_name }} WORKSPACE_NAME: ${{ steps.create-workspace.outputs.workspace_name }}
ISSUE_URL: ${{ inputs.issue_url }} ISSUE_URL: ${{ inputs.issue_url }}
GITHUB_TOKEN: ${{ github.token }}
run: | run: |
PROMPT_FILE=/tmp/prompt.txt PROMPT_FILE=/tmp/prompt.txt
trap 'rm -f "${PROMPT_FILE}"' EXIT trap 'rm -f "${PROMPT_FILE}"' EXIT
@@ -116,22 +110,14 @@ jobs:
# and exit once the agent has completed the task. # and exit once the agent has completed the task.
PROMPT=$(cat $PROMPT_FILE) ./scripts/traiage.sh prompt PROMPT=$(cat $PROMPT_FILE) ./scripts/traiage.sh prompt
- name: Commit and push changes
id: commit-push
if: ${{ inputs.persistence_mode == 'push' }}
run: |
echo "Committing and pushing changes in workspace: $WORKSPACE_NAME"
./scripts/traiage.sh commit-push
- name: Create and upload archive - name: Create and upload archive
id: create-archive id: create-archive
if: ${{ inputs.persistence_mode == 'archive' }}
env: env:
DESTINATION_PREFIX: ${{ secrets.TRAIAGE_DESTINATION_PREFIX }} BUCKET_PREFIX: "gs://coder-traiage-outputs/traiage"
run: | run: |
echo "Creating archive for workspace: $WORKSPACE_NAME" echo "Creating archive for workspace: $WORKSPACE_NAME"
./scripts/traiage.sh archive ./scripts/traiage.sh archive
echo "archive_url=${DESTINATION_PREFIX%%/}/$WORKSPACE_NAME.tar.gz" >> "${GITHUB_OUTPUT}" echo "archive_url=${BUCKET_PREFIX%%/}/$WORKSPACE_NAME.tar.gz" >> "${GITHUB_OUTPUT}"
- name: Report results - name: Report results
env: env:
@@ -139,17 +125,24 @@ jobs:
CONTEXT_KEY: ${{ steps.extract-context.outputs.context_key }} CONTEXT_KEY: ${{ steps.extract-context.outputs.context_key }}
WORKSPACE_NAME: ${{ steps.create-workspace.outputs.workspace_name }} WORKSPACE_NAME: ${{ steps.create-workspace.outputs.workspace_name }}
ARCHIVE_URL: ${{ steps.create-archive.outputs.archive_url }} ARCHIVE_URL: ${{ steps.create-archive.outputs.archive_url }}
BUCKET_PREFIX: "gs://coder-traiage-outputs/traiage"
run: | run: |
{ {
echo "## TrAIage Results"; echo "## TrAIage Results";
echo "- **Issue URL:** ${ISSUE_URL}"; echo "- **Issue URL:** ${ISSUE_URL}";
echo "- **Context Key:** ${CONTEXT_KEY}"; echo "- **Context Key:** ${CONTEXT_KEY}";
echo "- **Workspace:** ${WORKSPACE_NAME}"; echo "- **Workspace:** ${WORKSPACE_NAME}";
echo "- **Archive URL:** ${ARCHIVE_URL}" echo "- **Archive URL:** ${ARCHIVE_URL}";
echo "To fetch the output to your own workspace:";
echo '';
echo '```bash';
echo "BUCKET_PREFIX=${BUCKET_PREFIX} WORKSPACE_NAME=${WORKSPACE_NAME} ./scripts/traiage.sh resume";
echo '```'
} >> "${GITHUB_STEP_SUMMARY}" } >> "${GITHUB_STEP_SUMMARY}"
- name: Cleanup workspace - name: Cleanup workspace
if: steps.create-workspace.outputs.workspace_name != '' && (inputs.persistence_mode == 'archive' && steps.create-archive.outputs.archive_url != '') if: steps.create-workspace.outputs.workspace_name != '' && steps.create-archive.outputs.archive_url != ''
run: | run: |
echo "Cleaning up workspace: $WORKSPACE_NAME" echo "Cleaning up workspace: $WORKSPACE_NAME"
./scripts/traiage.sh delete || true ./scripts/traiage.sh delete || true
+26 -2
View File
@@ -140,7 +140,7 @@ wait_agentapi_stable() {
} }
archive() { archive() {
requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME DESTINATION_PREFIX requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME BUCKET_PREFIX
ssh_config ssh_config
# We want the heredoc to be expanded locally and not remotely. # We want the heredoc to be expanded locally and not remotely.
@@ -153,7 +153,7 @@ archive() {
set -euo pipefail set -euo pipefail
ARCHIVE_PATH=\$(coder-archive-create) ARCHIVE_PATH=\$(coder-archive-create)
ARCHIVE_NAME=\$(basename "\${ARCHIVE_PATH}") ARCHIVE_NAME=\$(basename "\${ARCHIVE_PATH}")
ARCHIVE_DEST="${DESTINATION_PREFIX%%/}/\${ARCHIVE_NAME}" ARCHIVE_DEST="${BUCKET_PREFIX%%/}/\${ARCHIVE_NAME}"
if [[ ! -f "\${ARCHIVE_PATH}" ]]; then if [[ ! -f "\${ARCHIVE_PATH}" ]]; then
echo "FATAL: Archive not found at expected path: \${ARCHIVE_PATH}" echo "FATAL: Archive not found at expected path: \${ARCHIVE_PATH}"
exit 1 exit 1
@@ -215,6 +215,27 @@ delete() {
exit 0 exit 0
} }
resume() {
requiredenvs CODER_URL CODER_SESSION_TOKEN WORKSPACE_NAME BUCKET_PREFIX
# Note: WORKSPACE_NAME here is really the 'context key'.
# Files are uploaded to the GCS bucket under this key.
# This just happens to be the same as the workspace name.
src="${BUCKET_PREFIX%%/}/${WORKSPACE_NAME}.tar.gz"
dest="${TEMPDIR}/${WORKSPACE_NAME}.tar.gz"
gcloud storage cp "${src}" "${dest}"
if [[ ! -f "${dest}" ]]; then
echo "FATAL: Failed to download archive from ${src}"
exit 1
fi
resume_dest="${HOME}/workspaces/${WORKSPACE_NAME}"
mkdir -p "${resume_dest}"
tar -xzvf "${dest}" -C "${resume_dest}" || exit 1
echo "Workspace restored to ${resume_dest}"
}
main() { main() {
dependencies coder dependencies coder
@@ -241,6 +262,9 @@ main() {
wait-agentapi-stable) wait-agentapi-stable)
wait_agentapi_stable wait_agentapi_stable
;; ;;
resume)
resume
;;
*) *)
echo "Unknown option: $1" echo "Unknown option: $1"
usage usage