|
| 1 | +name: Sync awesome skills to mirror repo |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'awesome-med-research-skills/**' |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: sync-awesome-skills |
| 12 | + cancel-in-progress: false |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + sync: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Generate App token for target repo |
| 22 | + id: app-token |
| 23 | + uses: actions/create-github-app-token@v1 |
| 24 | + with: |
| 25 | + app-id: ${{ vars.APP_ID }} |
| 26 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 27 | + owner: aipoch |
| 28 | + repositories: awesome-medical-research-skills |
| 29 | + |
| 30 | + - name: Checkout source |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 1 |
| 34 | + |
| 35 | + - name: Clone target |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 38 | + run: | |
| 39 | + git clone "https://x-access-token:${GH_TOKEN}@github.com/aipoch/awesome-medical-research-skills.git" target |
| 40 | +
|
| 41 | + - name: Flatten skills and sync into target |
| 42 | + run: | |
| 43 | + set -euo pipefail |
| 44 | + SRC="awesome-med-research-skills" |
| 45 | + TARGET="target" |
| 46 | +
|
| 47 | + if [ ! -d "$SRC" ]; then |
| 48 | + echo "Source dir '$SRC' missing, nothing to sync." |
| 49 | + exit 0 |
| 50 | + fi |
| 51 | +
|
| 52 | + # Remove existing top-level entries except git metadata and LICENSE |
| 53 | + find "$TARGET" -mindepth 1 -maxdepth 1 \ |
| 54 | + ! -name '.git' \ |
| 55 | + ! -name '.github' \ |
| 56 | + ! -name 'LICENSE' \ |
| 57 | + -exec rm -rf {} + |
| 58 | +
|
| 59 | + # Copy each <category>/<skill> -> <skill> at target root |
| 60 | + count=0 |
| 61 | + while IFS= read -r -d '' skill; do |
| 62 | + name=$(basename "$skill") |
| 63 | + cp -R "$skill" "$TARGET/$name" |
| 64 | + count=$((count + 1)) |
| 65 | + done < <(find "$SRC" -mindepth 2 -maxdepth 2 -type d -print0) |
| 66 | + echo "Flattened $count skill(s) into target/" |
| 67 | +
|
| 68 | + - name: Commit and push if changed |
| 69 | + working-directory: target |
| 70 | + run: | |
| 71 | + set -euo pipefail |
| 72 | + git config user.name "aipoch-skills-sync[bot]" |
| 73 | + git config user.email "${{ vars.APP_ID }}+aipoch-skills-sync[bot]@users.noreply.github.com" |
| 74 | + git add -A |
| 75 | + if git diff --cached --quiet; then |
| 76 | + echo "No changes to sync." |
| 77 | + exit 0 |
| 78 | + fi |
| 79 | + src_sha="${GITHUB_SHA::7}" |
| 80 | + git commit -m "sync: from medical-research-skills@${src_sha}" |
| 81 | + git push origin HEAD:main |
0 commit comments