Skip to content

Fix error in comment #4

Fix error in comment

Fix error in comment #4

Workflow file for this run

name: Sync Skills to Downstream Repos
on:
push:
branches: [main]
paths:
- 'skills/**'
- 'skill-mapping.csv'
workflow_dispatch:
inputs:
skill_branch:
description: 'Skill repo branch to sync from'
required: false
default: 'main'
# Per-repo branch parameters. Set to empty string ("") to skip syncing to that repo.
extension_repo_branch:
description: 'Extension repo branch to sync into (leave empty to skip)'
required: false
default: 'main'
cli_repo_branch:
description: 'CLI repo branch to sync into (leave empty to skip)'
required: false
default: 'main'
permissions:
contents: read
jobs:
sync-extension:
name: Sync to Extension Repo
runs-on: ubuntu-latest
# Skipped when extension_repo_branch is explicitly set to empty string
if: >-
(github.event_name == 'push') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.extension_repo_branch != '')
steps:
- name: Checkout skill repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.skill_branch || 'main' }}
path: skill-repo
- name: Checkout extension repo
uses: actions/checkout@v4
with:
repository: devdiv-azure-service-dmitryr/azure-java-migration-copilot-vscode-extension
ref: ${{ github.event.inputs.extension_repo_branch || 'main' }}
path: extension-repo
token: ${{ secrets.DOWNSTREAM_REPO_PAT }}
- name: Sync skill files from CSV mapping
run: |
chmod +x skill-repo/scripts/sync-skills.sh
# Read skill-mapping.csv row by row (skip header), sync each skill file
tail -n +2 skill-repo/skill-mapping.csv | while IFS=',' read -r SKILL_PATH EXT_PATH _CLI_PATH; do
SKILL_PATH="$(echo "$SKILL_PATH" | xargs)"
EXT_PATH="$(echo "$EXT_PATH" | xargs)"
SKILL_FILE="skill-repo/skills/$SKILL_PATH"
DOWNSTREAM_FILE="extension-repo/$EXT_PATH"
bash skill-repo/scripts/sync-skills.sh "$SKILL_FILE" "$DOWNSTREAM_FILE"
done
- name: Create Pull Request in Extension Repo
id: create-extension-pr
uses: peter-evans/create-pull-request@v7
with:
path: extension-repo
token: ${{ secrets.DOWNSTREAM_REPO_PAT }}
branch: automated/sync-skills/${{ github.event.inputs.skill_branch || 'main' }}-to-${{ github.event.inputs.extension_repo_branch || 'main' }}/${{ github.run_id }}
commit-message: "chore: sync skill files from skill repo"
title: "chore: sync skill files from skill repo (${{ github.event.inputs.skill_branch || 'main' }} -> ${{ github.event.inputs.extension_repo_branch || 'main' }})"
body: |
This PR was automatically created by the [Sync Skills workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
It syncs skill file content from the skill repo into this repo.
- **Skill repo branch:** `${{ github.event.inputs.skill_branch || 'main' }}`
- **Current repo branch:** `${{ github.event.inputs.extension_repo_branch || 'main' }}`
labels: automated,skill-sync
- name: Close old PRs with same branch pair
if: steps.create-extension-pr.outputs.pull-request-number
env:
GH_TOKEN: ${{ secrets.DOWNSTREAM_REPO_PAT }}
run: |
NEW_PR=${{ steps.create-extension-pr.outputs.pull-request-number }}
SKILL_BRANCH="${{ github.event.inputs.skill_branch || 'main' }}"
DOWNSTREAM_BRANCH="${{ github.event.inputs.extension_repo_branch || 'main' }}"
BRANCH_PREFIX="automated/sync-skills/${SKILL_BRANCH}-to-${DOWNSTREAM_BRANCH}/"
NEW_BRANCH="automated/sync-skills/${SKILL_BRANCH}-to-${DOWNSTREAM_BRANCH}/${{ github.run_id }}"
# List open PRs with the same branch prefix
gh pr list \
--repo devdiv-azure-service-dmitryr/azure-java-migration-copilot-vscode-extension \
--state open \
--label skill-sync \
--json number,headRefName \
--jq ".[] | select(.headRefName | startswith(\"${BRANCH_PREFIX}\")) | select(.headRefName != \"${NEW_BRANCH}\") | .number" | \
while read -r OLD_PR; do
echo "Closing old PR #${OLD_PR} in favor of #${NEW_PR}"
gh pr comment "$OLD_PR" \
--repo devdiv-azure-service-dmitryr/azure-java-migration-copilot-vscode-extension \
--body "Closing this PR in favor of #${NEW_PR}"
gh pr close "$OLD_PR" \
--repo devdiv-azure-service-dmitryr/azure-java-migration-copilot-vscode-extension
done
sync-cli:
name: Sync to CLI Repo
runs-on: ubuntu-latest
# Skipped when cli_repo_branch is explicitly set to empty string
if: >-
(github.event_name == 'push') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.cli_repo_branch != '')
steps:
- name: Checkout skill repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.skill_branch || 'main' }}
path: skill-repo
- name: Checkout CLI repo
uses: actions/checkout@v4
with:
repository: devdiv-azure-service-dmitryr/modernize-cli
ref: ${{ github.event.inputs.cli_repo_branch || 'main' }}
path: cli-repo
token: ${{ secrets.DOWNSTREAM_REPO_PAT }}
- name: Sync skill files from CSV mapping
run: |
chmod +x skill-repo/scripts/sync-skills.sh
# Read skill-mapping.csv row by row (skip header), sync each skill file
tail -n +2 skill-repo/skill-mapping.csv | while IFS=',' read -r SKILL_PATH _EXT_PATH CLI_PATH; do
SKILL_PATH="$(echo "$SKILL_PATH" | xargs)"
CLI_PATH="$(echo "$CLI_PATH" | xargs)"
SKILL_FILE="skill-repo/skills/$SKILL_PATH"
DOWNSTREAM_FILE="cli-repo/$CLI_PATH"
bash skill-repo/scripts/sync-skills.sh "$SKILL_FILE" "$DOWNSTREAM_FILE"
done
- name: Create Pull Request in CLI Repo
id: create-cli-pr
uses: peter-evans/create-pull-request@v7
with:
path: cli-repo
token: ${{ secrets.DOWNSTREAM_REPO_PAT }}
branch: automated/sync-skills/${{ github.event.inputs.skill_branch || 'main' }}-to-${{ github.event.inputs.cli_repo_branch || 'main' }}/${{ github.run_id }}
commit-message: "chore: sync skill files from skill repo"
title: "chore: sync skill files from skill repo (${{ github.event.inputs.skill_branch || 'main' }} -> ${{ github.event.inputs.cli_repo_branch || 'main' }})"
body: |
This PR was automatically created by the [Sync Skills workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
It syncs skill file content from the skill repo into this repo.
- **Skill repo branch:** `${{ github.event.inputs.skill_branch || 'main' }}`
- **Downstream repo branch:** `${{ github.event.inputs.cli_repo_branch || 'main' }}`
labels: automated,skill-sync
- name: Close old PRs with same branch pair
if: steps.create-cli-pr.outputs.pull-request-number
env:
GH_TOKEN: ${{ secrets.DOWNSTREAM_REPO_PAT }}
run: |
NEW_PR=${{ steps.create-cli-pr.outputs.pull-request-number }}
SKILL_BRANCH="${{ github.event.inputs.skill_branch || 'main' }}"
DOWNSTREAM_BRANCH="${{ github.event.inputs.cli_repo_branch || 'main' }}"
BRANCH_PREFIX="automated/sync-skills/${SKILL_BRANCH}-to-${DOWNSTREAM_BRANCH}/"
NEW_BRANCH="automated/sync-skills/${SKILL_BRANCH}-to-${DOWNSTREAM_BRANCH}/${{ github.run_id }}"
# List open PRs with the same branch prefix
gh pr list \
--repo devdiv-azure-service-dmitryr/modernize-cli \
--state open \
--label skill-sync \
--json number,headRefName \
--jq ".[] | select(.headRefName | startswith(\"${BRANCH_PREFIX}\")) | select(.headRefName != \"${NEW_BRANCH}\") | .number" | \
while read -r OLD_PR; do
echo "Closing old PR #${OLD_PR} in favor of #${NEW_PR}"
gh pr comment "$OLD_PR" \
--repo devdiv-azure-service-dmitryr/modernize-cli \
--body "Closing this PR in favor of #${NEW_PR}"
gh pr close "$OLD_PR" \
--repo devdiv-azure-service-dmitryr/modernize-cli
done