Add Icon to Collection #76
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: Add Icon to Collection | |
| on: | |
| workflow_call: | |
| inputs: | |
| submissionIds: | |
| description: Comma-separated IDs of the PocketBase submissions to import | |
| required: true | |
| type: string | |
| dryRun: | |
| description: When true, skip writes/commit/PocketBase status update | |
| required: false | |
| default: false | |
| type: boolean | |
| secrets: | |
| PB_URL: | |
| required: true | |
| PB_ADMIN_TOKEN: | |
| required: true | |
| workflow_dispatch: | |
| inputs: | |
| submissionIds: | |
| description: Comma-separated IDs of the PocketBase submissions to import | |
| required: true | |
| type: string | |
| dryRun: | |
| description: When true, skip writes/commit/PocketBase status update | |
| required: false | |
| default: false | |
| type: boolean | |
| concurrency: | |
| group: add-icon-queue | |
| cancel-in-progress: false | |
| jobs: | |
| add-icon: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v1 | |
| - name: Configure git user | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Import icons from PocketBase submissions | |
| env: | |
| PB_URL: ${{ secrets.PB_URL }} | |
| PB_ADMIN_TOKEN: ${{ secrets.PB_ADMIN_TOKEN }} | |
| DRY_RUN: ${{ inputs.dryRun }} | |
| run: | | |
| IFS=',' read -ra IDS <<< "${{ inputs.submissionIds }}" | |
| for submission_id in "${IDS[@]}"; do | |
| submission_id=$(echo "$submission_id" | xargs) | |
| if [ -z "$submission_id" ]; then | |
| continue | |
| fi | |
| echo "::group::Processing submission $submission_id" | |
| ARGS=(--submission-id "$submission_id") | |
| if [ "$DRY_RUN" = "true" ]; then | |
| ARGS+=("--dry-run") | |
| fi | |
| output_file="$(mktemp)" | |
| ARGS+=("--gha-output" "$output_file") | |
| bun run scripts/import-icon.ts "${ARGS[@]}" | |
| if [ "$DRY_RUN" != "true" ] && ! git diff --quiet; then | |
| source "$output_file" 2>/dev/null || true | |
| name="${submission_name:-$submission_id}" | |
| approver_name="${approver:-unknown}" | |
| # Build commit message with co-authors | |
| commit_msg="chore: add icon \"${name}\" (submission ${submission_id}, approved by ${approver_name})" | |
| # Add co-author trailers if available | |
| if [ -n "$co_authors" ]; then | |
| # Add a blank line before co-authors | |
| commit_msg="${commit_msg}"$'\n\n'"${co_authors}" | |
| fi | |
| git add . | |
| git commit -m "$commit_msg" | |
| fi | |
| rm -f "$output_file" || true | |
| echo "::endgroup::" | |
| done | |
| - name: Push changes | |
| if: ${{ !inputs.dryRun }} | |
| run: | | |
| if [ "$(git rev-list --count HEAD ^origin/main)" -gt 0 ]; then | |
| git pull --rebase | |
| git push | |
| else | |
| echo "No commits to push" | |
| fi | |