Skip to content

infra: CI/CD pipelines and shared workflow templates #50

infra: CI/CD pipelines and shared workflow templates

infra: CI/CD pipelines and shared workflow templates #50

name: Add to Project
on:
issues:
types: [opened, labeled]
pull_request:
types: [opened, labeled]
jobs:
add-to-project:
runs-on: ubuntu-latest
steps:
- uses: actions/add-to-project@v1.0.2
id: add
with:
project-url: https://github.com/orgs/AzureLocal/projects/3
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
set-fields:
needs: add-to-project
runs-on: ubuntu-latest
if: always() && github.event_name == 'issues'
env:
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
PROJECT_ID: "PVT_kwDOCxeiOM4BR2KZ"
SOLUTION_FIELD: "PVTSSF_lADOCxeiOM4BR2KZzg_jXuY"
PRIORITY_FIELD: "PVTSSF_lADOCxeiOM4BR2KZzg_jXvs"
CATEGORY_FIELD: "PVTSSF_lADOCxeiOM4BR2KZzg_jXxA"
steps:
- name: Get project item ID
id: find-item
run: |
ITEM_ID=$(gh project item-list 3 --owner AzureLocal --format json --limit 200 \
| jq -r --arg url "${{ github.event.issue.html_url }}" \
'.items[] | select(.content.url == $url) | .id')
echo "item_id=$ITEM_ID" >> "$GITHUB_OUTPUT"
- name: Set Solution field
if: steps.find-item.outputs.item_id != ''
run: |
ITEM_ID="${{ steps.find-item.outputs.item_id }}"
LABELS='${{ toJson(github.event.issue.labels.*.name) }}'
OPTION_ID=""
if echo "$LABELS" | grep -q '"solution/sofs"'; then
OPTION_ID="a33c6c71"
elif echo "$LABELS" | grep -q '"solution/avd"'; then
OPTION_ID="502138a1"
elif echo "$LABELS" | grep -q '"solution/loadtools"'; then
OPTION_ID="822e566b"
elif echo "$LABELS" | grep -q '"solution/vmconvert"'; then
OPTION_ID="4c6202b4"
elif echo "$LABELS" | grep -q '"solution/docs-site"'; then
OPTION_ID="21b55444"
elif echo "$LABELS" | grep -q '"solution/workspace"'; then
OPTION_ID="4cec6642"
elif echo "$LABELS" | grep -q '"solution/toolkit"'; then
OPTION_ID="2bd203d9"
fi
if [ -n "$OPTION_ID" ]; then
gh project item-edit --project-id "$PROJECT_ID" --id "$ITEM_ID" \
--field-id "$SOLUTION_FIELD" --single-select-option-id "$OPTION_ID"
fi
- name: Set Priority field
if: steps.find-item.outputs.item_id != ''
run: |
ITEM_ID="${{ steps.find-item.outputs.item_id }}"
LABELS='${{ toJson(github.event.issue.labels.*.name) }}'
OPTION_ID=""
if echo "$LABELS" | grep -q '"priority/critical"'; then
OPTION_ID="74334e8d"
elif echo "$LABELS" | grep -q '"priority/high"'; then
OPTION_ID="2e3ede9d"
elif echo "$LABELS" | grep -q '"priority/medium"'; then
OPTION_ID="7709e85d"
elif echo "$LABELS" | grep -q '"priority/low"'; then
OPTION_ID="2182b5f9"
fi
if [ -n "$OPTION_ID" ]; then
gh project item-edit --project-id "$PROJECT_ID" --id "$ITEM_ID" \
--field-id "$PRIORITY_FIELD" --single-select-option-id "$OPTION_ID"
fi
- name: Set Category field
if: steps.find-item.outputs.item_id != ''
run: |
ITEM_ID="${{ steps.find-item.outputs.item_id }}"
LABELS='${{ toJson(github.event.issue.labels.*.name) }}'
OPTION_ID=""
if echo "$LABELS" | grep -q '"type/feature"'; then
OPTION_ID="7a4fa8ea"
elif echo "$LABELS" | grep -q '"type/bug"'; then
OPTION_ID="206e624a"
elif echo "$LABELS" | grep -q '"type/docs"'; then
OPTION_ID="355ce6c1"
elif echo "$LABELS" | grep -q '"type/infra"'; then
OPTION_ID="05996f93"
elif echo "$LABELS" | grep -q '"type/refactor"'; then
OPTION_ID="7f5509ab"
elif echo "$LABELS" | grep -q '"type/security"'; then
OPTION_ID="d2af4749"
fi
if [ -n "$OPTION_ID" ]; then
gh project item-edit --project-id "$PROJECT_ID" --id "$ITEM_ID" \
--field-id "$CATEGORY_FIELD" --single-select-option-id "$OPTION_ID"
fi