Sync skills from monorepo #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync skills from monorepo | |
| on: | |
| schedule: | |
| - cron: "37 6 * * 1" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| if: github.repository == 'triggerdotdev/skills' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Fetch monorepo skills | |
| run: | | |
| git clone --depth 1 --filter=blob:none --no-checkout \ | |
| https://github.com/triggerdotdev/trigger.dev.git monorepo | |
| git -C monorepo sparse-checkout set --no-cone packages/cli-v3/skills | |
| git -C monorepo checkout | |
| echo "MONOREPO_SHA=$(git -C monorepo rev-parse HEAD)" >> "$GITHUB_ENV" | |
| - name: Apply sync map | |
| run: | | |
| set -euo pipefail | |
| SRC=monorepo/packages/cli-v3/skills | |
| jq -r 'to_entries[] | "\(.key)\t\(.value)"' sync-map.json | | |
| while IFS=$'\t' read -r src dst; do | |
| [ -d "$SRC/$src" ] || { echo "::warning::mapped skill '$src' not found in monorepo"; continue; } | |
| rm -rf "./$dst" | |
| cp -R "$SRC/$src" "./$dst" | |
| done | |
| comm -23 \ | |
| <(find "$SRC" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort) \ | |
| <(jq -r 'keys[]' sync-map.json | sort) \ | |
| | sed 's/^/::warning::unmapped monorepo skill: /' | |
| rm -rf monorepo | |
| - name: Open or update pull request | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| if [ -z "$(git status --porcelain)" ]; then | |
| echo "No changes to sync." | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git checkout -B sync/monorepo-skills | |
| git add -A | |
| git commit -m "chore: sync skills from triggerdotdev/trigger.dev@${MONOREPO_SHA:0:7}" | |
| git push --force-with-lease origin sync/monorepo-skills | |
| body="Automated weekly sync from [\`triggerdotdev/trigger.dev@${MONOREPO_SHA:0:7}\`](https://github.com/triggerdotdev/trigger.dev/commit/${MONOREPO_SHA}). | |
| Mappings live in \`sync-map.json\`. To publish a new monorepo skill, add an entry there. See the workflow run for any unmapped skills." | |
| existing=$(gh pr list --head sync/monorepo-skills --state open --json number --jq '.[0].number // empty') | |
| if [ -n "$existing" ]; then | |
| gh pr edit "$existing" --body "$body" | |
| else | |
| gh pr create --head sync/monorepo-skills --base main \ | |
| --title "chore: sync skills from monorepo" --body "$body" | |
| fi |