|
| 1 | +name: "Copilot Setup Steps" |
| 2 | + |
| 3 | +# Automatically run the setup steps when they are changed to allow for easy validation, and |
| 4 | +# allow manual testing through the repository's "Actions" tab |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + push: |
| 8 | + paths: |
| 9 | + - .github/workflows/copilot-setup-steps.yml |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - .github/workflows/copilot-setup-steps.yml |
| 13 | + |
| 14 | +jobs: |
| 15 | + # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. |
| 16 | + copilot-setup-steps: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + # Set the permissions to the lowest permissions possible needed for your steps. |
| 20 | + # Copilot will be given its own token for its operations. |
| 21 | + permissions: |
| 22 | + # If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete. |
| 23 | + contents: read |
| 24 | + |
| 25 | + # You can define any steps you want, and they will run before the agent starts. |
| 26 | + # If you do not check out your code, Copilot will do this for you. |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v5 |
| 30 | + |
| 31 | + - name: Parse COPILOT_AGENT_PROMPT and extract attachments |
| 32 | + env: |
| 33 | + COPILOT_AGENT_INPUTS: ${{ inputs.COPILOT_AGENT_INPUTS }} |
| 34 | + PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 35 | + run: | |
| 36 | + # Use a temp directory in the repo so Copilot agent can access it |
| 37 | + ATTACHMENTS_DIR=".github/temp/attachments" |
| 38 | + mkdir -p "$ATTACHMENTS_DIR" |
| 39 | + rm -rf "$ATTACHMENTS_DIR"/* 2>/dev/null || true |
| 40 | + |
| 41 | + # Extract COPILOT_AGENT_PROMPT from COPILOT_AGENT_INPUTS (it's a nested JSON string) |
| 42 | + PROMPT_BASE64=$(echo "$COPILOT_AGENT_INPUTS" | jq -r '.COPILOT_AGENT_PROMPT // empty') |
| 43 | + |
| 44 | + if [ -z "$PROMPT_BASE64" ]; then |
| 45 | + echo "COPILOT_AGENT_PROMPT not found in inputs" |
| 46 | + exit 0 |
| 47 | + fi |
| 48 | + |
| 49 | + echo "=== Decoding COPILOT_AGENT_PROMPT ===" |
| 50 | + PROMPT_CONTENT=$(echo "$PROMPT_BASE64" | base64 -d) |
| 51 | + echo "$PROMPT_CONTENT" |
| 52 | + |
| 53 | + # Extract issue description content between <issue_description> tags |
| 54 | + ISSUE_BODY=$(echo "$PROMPT_CONTENT" | sed -n '/<issue_description>/,/<\/issue_description>/p' | sed 's/<[^>]*>//g') |
| 55 | + echo "=== Issue Body ===" |
| 56 | + echo "$ISSUE_BODY" |
| 57 | + |
| 58 | + # Extract all GitHub user-attachments URLs (covers both /files/ and /assets/ paths) |
| 59 | + # URLs end with ) in markdown links or " in HTML attributes |
| 60 | + ALL_URLS=$(echo "$PROMPT_CONTENT" | grep -oE 'https://github\.com/user-attachments/[^)"]+' | sort -u || true) |
| 61 | + |
| 62 | + if [ -z "$ALL_URLS" ]; then |
| 63 | + echo "No attachment URLs found in COPILOT_AGENT_PROMPT" |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + |
| 67 | + echo "=== Found Attachment URLs ===" |
| 68 | + echo "$ALL_URLS" |
| 69 | + |
| 70 | + # Print extracted filenames |
| 71 | + echo "=== Attachment Filenames ===" |
| 72 | + echo "$ALL_URLS" | while read -r URL; do |
| 73 | + if [ -n "$URL" ]; then |
| 74 | + FILENAME=$(basename "$URL" | sed 's/?.*//') |
| 75 | + echo "$FILENAME" |
| 76 | + fi |
| 77 | + done |
| 78 | + |
| 79 | + # Download each attachment |
| 80 | + echo "$ALL_URLS" | while read -r URL; do |
| 81 | + if [ -n "$URL" ]; then |
| 82 | + FILENAME=$(basename "$URL" | sed 's/?.*//') |
| 83 | + echo "Downloading: $URL -> $ATTACHMENTS_DIR/$FILENAME" |
| 84 | + curl -L -H "Authorization: token ${PERSONAL_ACCESS_TOKEN}" \ |
| 85 | + "$URL" \ |
| 86 | + -o "$ATTACHMENTS_DIR/$FILENAME" || echo "Failed to download: $URL" |
| 87 | + fi |
| 88 | + done |
| 89 | + |
| 90 | + echo "=== Downloaded Files ===" |
| 91 | + ls -la "$ATTACHMENTS_DIR" |
| 92 | + |
| 93 | + echo "=== Attachment File Paths ===" |
| 94 | + for f in "$ATTACHMENTS_DIR"/*; do |
| 95 | + if [ -f "$f" ]; then |
| 96 | + echo "$f" |
| 97 | + fi |
| 98 | + done |
| 99 | +
|
0 commit comments