-
Notifications
You must be signed in to change notification settings - Fork 3
160 lines (138 loc) · 4.85 KB
/
update_sources.yaml
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Update OBS sources
on:
workflow_dispatch:
inputs:
target_branch:
description: 'Target branch to upgrade in OBS'
required: true
default: 'dev'
source_repositories:
description: 'Source repositories to upgrade from'
required: true
default: 'all'
schedule:
- cron: "0 8-22/2 * * 1-5"
concurrency:
group: soucre-update-${{ inputs.target_branch }}
permissions:
contents: write
pull-requests: write
statuses: write
jobs:
set-repositories:
env:
BRANCH: ${{ inputs.target_branch || 'dev' }}
SRC_REPOS: ${{ inputs.source_repositories || 'all' }}
runs-on: ubuntu-latest
outputs:
repos: ${{ steps.sources.outputs.repos }}
steps:
- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Define matrix values
id: sources
run: |
[ ! -f config.yaml ] && exit 1
count=$(yq ".${{ env.BRANCH }} | length" config.yaml)
output="repos=["
for ((n=0;n<${count};n++)); do
repo="$(yq ".${{ env.BRANCH }}.[${n}].repo" config.yaml)"
if [[ "${{ env.SRC_REPOS }}" != "all" ]] && [[ "${{ env.SRC_REPOS }}" != "${repo}" ]]; then
continue
fi
if [[ "${output}" == "repos=[" ]]; then
output+="'${repo}'"
else
output+=", '${repo}'"
fi
done
output+="]"
echo "Computed result: ${output}"
if [[ "${output}" == "repos=[]" ]]; then
echo "Could not find input repository: ${{ env.SRC_REPOS }}"
exit 1
fi
echo "${output}" >> $GITHUB_OUTPUT
update-sources:
needs:
- set-repositories
env:
BRANCH: ${{ inputs.target_branch || 'dev' }}
strategy:
matrix:
repo: ${{ fromJson(needs.set-repositories.outputs.repos) }}
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout builders
run: |
# Ensure Makefile, scripts and config.yaml are not present in target branch
[ -d scripts ] && exit 1
[ -f Makefile ] && exit 1
[ -f config.yaml ] && exit 1
git fetch origin +${{ github.ref_name }}:${{ github.ref_name }}
git checkout ${{ github.ref_name }} -- scripts Makefile config.yaml
- name: Run prepare-sources
run: |
count=$(yq ".${{ env.BRANCH }} | length" config.yaml)
for ((n=0;n<${count};n++)); do
repo="$(yq ".${{ env.BRANCH }}.[${n}].repo" config.yaml)"
if [[ "${{ matrix.repo }}" != "${repo}" ]]; then
continue
fi
export REPO="${repo}"
export BRANCH="$(yq ".${{ env.BRANCH }}.[${n}].branch" config.yaml)"
export V_PARSE="$(yq ".${{ env.BRANCH }}.[${n}].parseVersion" config.yaml)"
export V_OFFSET="$(yq ".${{ env.BRANCH }}.[${n}].versionOffset" config.yaml)"
make prepare-sources
done
- name: Update sources
run: |
make update-sources
- name: Clean paths
run: |
rm -rf scripts
rm -f Makefile config.yaml
- name: Checkout new branch for ${{ matrix.repo }} sources
id: commit
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SRC_REPO: ${{ matrix.repo }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "elementalbot"
branch="${BRANCH}_${SRC_REPO//\//_}"
git checkout -b ${branch}
git add .
if [ -z "$(git status --porcelain)" ]; then
echo "Clean work tree, nothing to do"
echo "clean=true" >> "${GITHUB_OUTPUT}"
exit 0
else
echo "clean=false" >> "${GITHUB_OUTPUT}"
fi
git commit -s -m "Automated commit from GHA workflow"
git push origin ${branch} --force
- if: ${{ steps.commit.outputs.clean != 'true' }}
name: Update/create PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SRC_REPO: ${{ matrix.repo }}
run: |
branch="${BRANCH}_${SRC_REPO//\//_}"
json=$(gh pr list --repo ${{ github.repository }} --json number,baseRefName,headRefName --head ${branch} --base ${{ env.BRANCH }} --limit 1)
if [ "$(echo "${json}" | jq length)" -eq 1 ]; then
number="$(echo "${json}" | jq '.[0].number')"
gh pr comment "${number}" --repo ${{ github.repository }} --body "Updating PR from sources"
else
gh pr create --repo ${{ github.repository }} --head ${branch} --base ${{ env.BRANCH }} \
--body "Automated PR from GH client" --title "Update '${{ env.BRANCH }}' OBS sources from '${{ matrix.repo }}'"
fi