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