forked from red-hat-data-services/konflux-central
-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (95 loc) · 3.88 KB
/
pipelinerun-replicator.yml
File metadata and controls
110 lines (95 loc) · 3.88 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Replicate Tekton Pipelineruns
run-name: Replicate Pipelineruns ${{ inputs.source_branch }} -> ${{ inputs.target_branch }} for version ${{ inputs.rhoai_version }}
on:
workflow_dispatch:
inputs:
dry_run:
type: boolean
description: 'Dry Run (No changes are committed)'
required: true
default: true
source_branch:
description: 'Source branch to copy Tekton files from (e.g., rhoai-3.3, rhoai-3.4-ea.1)'
required: true
target_branch:
description: 'Target branch to create (e.g., rhoai-3.4-ea.1, rhoai-3.4)'
required: true
rhoai_version:
description: 'RHOAI Version without v prefix (e.g., 3.4.0-ea.1, 3.4.0)'
permissions:
contents: write
jobs:
replicate:
runs-on: ubuntu-latest
env:
source_branch: ${{ github.event.inputs.source_branch }}
target_branch: ${{ github.event.inputs.target_branch }}
rhoai_version: ${{ github.event.inputs.rhoai_version }}
PIPELINERUNS_DIR: "pipelineruns"
steps:
- name: Sanitize and Print Inputs
run: |
version="${rhoai_version#v}"
if [[ "$version" != "$rhoai_version" ]]; then
echo "::warning::Stripped 'v' prefix from rhoai_version: $rhoai_version -> $version"
echo "rhoai_version=$version" >> $GITHUB_ENV
fi
echo "====================================="
echo "Workflow Inputs"
echo "====================================="
echo "dry_run: ${{ github.event.inputs.dry_run }}"
echo "source_branch: ${{ env.source_branch }}"
echo "target_branch: ${{ env.target_branch }}"
echo "rhoai_version: $version"
echo "====================================="
- name: Check if target branch already exists
run: |
if git ls-remote --exit-code --heads origin "$target_branch" &>/dev/null; then
echo "::error::Target branch '$target_branch' already exists."
exit 1
else
echo "Target branch '$target_branch' does not exist. Proceeding."
fi
- name: Checkout source branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.source_branch }}
token: ${{ github.token }}
- name: Create target branch
run: git checkout -b ${{ github.event.inputs.target_branch }}
- name: Checkout scripts from main
uses: actions/checkout@v3
with:
path: tmp
- name: Replicate pipelineruns for ${{ github.event.inputs.target_branch }}
run: |
./tmp/script/rhoai_pipelinerun_manager.sh \
--mode create \
--from ${{ env.source_branch }} \
--target ${{ env.target_branch }} \
--rhoai-version ${{ env.rhoai_version }} \
--dir ${{ env.PIPELINERUNS_DIR }}
- name: Remove tmp clone
run: rm -rf tmp
- name: Commit Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global color.ui always
set -x
git add ${{ env.PIPELINERUNS_DIR }}
git diff --staged
set +x
# Check if there are any changes to commit
if git diff --staged --quiet; then
echo "No changes to commit."
else
JOB_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
git commit -m "[skip-sync] Onboarding ${{ env.target_branch }}" -m "Triggered by: ${JOB_URL}"
fi
# Check if dry_run is false and push changes if true
if [[ "${{ github.event.inputs.dry_run }}" == 'false' ]]; then
git push origin ${{ github.event.inputs.target_branch }}
else
echo "'dry_run' is enabled. No changes will be pushed."
fi