|
| 1 | +name: Collect Coder Analytics |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 */6 * * *' # Every 6 hours |
| 6 | + workflow_dispatch: # Allow manual triggers |
| 7 | + |
| 8 | +env: |
| 9 | + CODER_URL: https://platform.vectorinstitute.ai |
| 10 | + |
| 11 | +jobs: |
| 12 | + collect: |
| 13 | + name: Collect Workspace Analytics |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + id-token: write # Required for GCP authentication |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 1 |
| 24 | + |
| 25 | + - name: Set up Python |
| 26 | + uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: '3.12' |
| 29 | + |
| 30 | + - name: Install Python dependencies |
| 31 | + run: | |
| 32 | + echo "Installing Python dependencies..." |
| 33 | + pip install -e . |
| 34 | + echo "✓ Dependencies installed" |
| 35 | +
|
| 36 | + - name: Install Coder CLI |
| 37 | + run: | |
| 38 | + echo "Installing Coder CLI..." |
| 39 | + curl -fsSL https://coder.com/install.sh | sh |
| 40 | + coder version |
| 41 | + echo "✓ Coder CLI installed successfully" |
| 42 | +
|
| 43 | + - name: Authenticate to Google Cloud |
| 44 | + id: auth |
| 45 | + uses: google-github-actions/auth@v2 |
| 46 | + with: |
| 47 | + workload_identity_provider: ${{ secrets.WIF_PROVIDER }} |
| 48 | + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} |
| 49 | + token_format: access_token |
| 50 | + |
| 51 | + - name: Set up Cloud SDK |
| 52 | + uses: google-github-actions/setup-gcloud@v2 |
| 53 | + |
| 54 | + - name: Authenticate with Coder |
| 55 | + env: |
| 56 | + CODER_SESSION_TOKEN: ${{ secrets.CODER_TOKEN }} |
| 57 | + run: | |
| 58 | + echo "Authenticating with Coder..." |
| 59 | + echo "$CODER_SESSION_TOKEN" | coder login "$CODER_URL" --token |
| 60 | + echo "✓ Authenticated to Coder" |
| 61 | +
|
| 62 | + - name: Collect and upload analytics |
| 63 | + run: | |
| 64 | + echo "Running analytics collection script..." |
| 65 | + python3 scripts/collect_coder_analytics.py |
| 66 | +
|
| 67 | + - name: Generate summary |
| 68 | + if: success() |
| 69 | + run: | |
| 70 | + # Read the latest snapshot to get counts |
| 71 | + SNAPSHOT=$(gsutil cat gs://coder-analytics-snapshots/latest.json) |
| 72 | + WORKSPACE_COUNT=$(echo "$SNAPSHOT" | jq '[.workspaces[]? // []] | length') |
| 73 | + TEMPLATE_COUNT=$(echo "$SNAPSHOT" | jq '[.templates[]? // []] | length') |
| 74 | + TIMESTAMP=$(echo "$SNAPSHOT" | jq -r '.timestamp') |
| 75 | +
|
| 76 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 77 | + ## 📊 Coder Analytics Collection Summary |
| 78 | +
|
| 79 | + **Timestamp:** $TIMESTAMP |
| 80 | +
|
| 81 | + ### Data Collected |
| 82 | + - **Workspaces:** $WORKSPACE_COUNT |
| 83 | + - **Templates:** $TEMPLATE_COUNT |
| 84 | +
|
| 85 | + ### Storage |
| 86 | + - **Bucket:** \`gs://coder-analytics-snapshots/\` |
| 87 | + - **Latest:** [latest.json](https://console.cloud.google.com/storage/browser/coder-analytics-snapshots) |
| 88 | +
|
| 89 | + --- |
| 90 | + *Next collection scheduled in 6 hours* |
| 91 | + EOF |
0 commit comments