|
| 1 | +name: syncweaver-source-dispatch |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + source_ref: |
| 9 | + description: Optional source ref to dispatch (defaults to release tag for release events, or current ref for manual runs). |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + source_repo: |
| 13 | + description: Optional source repository override in OWNER/REPO format (defaults to current repository). |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + orchestrator-repo: |
| 17 | + description: Optional orchestrator repository override in OWNER/REPO format. |
| 18 | + required: false |
| 19 | + default: CCBR/syncweaver |
| 20 | + type: string |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | +jobs: |
| 26 | + notify-syncweaver: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + env: |
| 29 | + SOURCE_REPOSITORY: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_repo || github.repository }} |
| 30 | + SOURCE_REF: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.inputs.source_ref || github.ref_name }} |
| 31 | + ORCHESTRATOR_REPO: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs['orchestrator-repo'] || vars['orchestrator-repo'] || 'CCBR/syncweaver' }} |
| 32 | + steps: |
| 33 | + - name: Validate dispatch payload |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + set -euo pipefail |
| 37 | + if [[ -z "${SOURCE_REPOSITORY//[[:space:]]/}" ]]; then |
| 38 | + echo "Error: source repository cannot be empty." >&2 |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + if [[ -z "${SOURCE_REF//[[:space:]]/}" ]]; then |
| 42 | + echo "Error: source ref cannot be empty." >&2 |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + if [[ -z "${ORCHESTRATOR_REPO//[[:space:]]/}" ]]; then |
| 46 | + echo "Error: orchestrator repository cannot be empty." >&2 |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + if [[ "${ORCHESTRATOR_REPO}" != */* ]]; then |
| 50 | + echo "Error: orchestrator repository must be in OWNER/REPO format." >&2 |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + if [[ -z "${{ vars.CCBR_BOT_APP_ID }}" ]]; then |
| 54 | + echo "Error: vars.CCBR_BOT_APP_ID is required to generate a dispatch token." >&2 |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + if [[ -z "${{ secrets.CCBR_BOT_PRIVATE_KEY }}" ]]; then |
| 58 | + echo "Error: secrets.CCBR_BOT_PRIVATE_KEY is required to generate a dispatch token." >&2 |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +
|
| 62 | + - name: Resolve orchestrator repository owner and name |
| 63 | + id: orchestrator_repo |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + set -euo pipefail |
| 67 | + owner="${ORCHESTRATOR_REPO%%/*}" |
| 68 | + repo="${ORCHESTRATOR_REPO#*/}" |
| 69 | + if [[ -z "${owner}" || -z "${repo}" ]]; then |
| 70 | + echo "Error: failed to parse orchestrator repository '${ORCHESTRATOR_REPO}'." >&2 |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + echo "owner=${owner}" >> "$GITHUB_OUTPUT" |
| 74 | + echo "repository=${repo}" >> "$GITHUB_OUTPUT" |
| 75 | +
|
| 76 | + - name: Generate CCBR-bot token |
| 77 | + id: ccbr_bot |
| 78 | + uses: actions/create-github-app-token@v3 |
| 79 | + with: |
| 80 | + client-id: ${{ vars.CCBR_BOT_APP_ID }} |
| 81 | + private-key: ${{ secrets.CCBR_BOT_PRIVATE_KEY }} |
| 82 | + owner: ${{ steps.orchestrator_repo.outputs.owner }} |
| 83 | + repositories: ${{ steps.orchestrator_repo.outputs.repository }} |
| 84 | + |
| 85 | + - name: Dispatch syncweaver-update-hosts workflow in orchestrator repo |
| 86 | + uses: peter-evans/repository-dispatch@v4 |
| 87 | + with: |
| 88 | + token: ${{ steps.ccbr_bot.outputs.token }} |
| 89 | + repository: ${{ env.ORCHESTRATOR_REPO }} |
| 90 | + event-type: syncweaver-update-hosts |
| 91 | + client-payload: >- |
| 92 | + {"source_repository": ${{ toJson(env.SOURCE_REPOSITORY) }}, "ref": ${{ toJson(env.SOURCE_REF) }}} |
0 commit comments