-
Notifications
You must be signed in to change notification settings - Fork 116
162 lines (148 loc) · 6.02 KB
/
meta-balena-esr.yml
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
161
162
name: "Creates ESR branch and tag"
# Runs quarterly on the first day to create an ESR branch on the latest patch
# of the last minor version
on:
# Run at 00:06 the first day every 3rd month (quarterly)
# Run weekly too to keep the workflow enabled
schedule:
- cron: "6 0 1 */3 *"
- cron: "6 0 * * 1"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
esr-version:
required: false
type: string
description: ESR version override, for example 2022.10. By default it uses current year and month.
env:
# get the user id of the GitHub App
# gh api /users/balenaos-esr%5Bbot%5D
GIT_AUTHOR_NAME: balenaos-esr[bot]
GIT_AUTHOR_EMAIL: 146746583+balenaos-esr[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: balenaos-esr[bot]
GIT_COMMITTER_EMAIL: 146746583+balenaos-esr[bot]@users.noreply.github.com
jobs:
fetch:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
outputs:
status: ${{ join(steps.*.conclusion) }}
steps:
- name: "Exit on weekly runs"
if: github.event_name == 'schedule' && github.event.schedule != '6 0 1 */3 *'
run: exit 1
- name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
id: gh_app_token
with:
app_id: ${{ vars.ESR_BOT_APP_ID || '400859' }}
installation_retrieval_mode: organization
installation_retrieval_payload: ${{ github.event.repository.owner.login }}
private_key: ${{ secrets.ESR_BOT_PRIVATE_KEY }}
repositories: >
["${{ github.event.repository.name }}"]
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
# The default GITHUB_TOKEN does not have workflow scope
# This is needed to push a new branch with workflow files
token: ${{ steps.gh_app_token.outputs.token }}
- name: "Only run for meta-balena repository"
id: assert-meta-balena-repository
run: |
if [ -f "$(pwd)/repo.yml" ]; then
if grep -q "yocto layer" repo.yml; then
exit 0
fi
fi
exit 1
- name: "Assert ESR version"
id: assert-esr-version
run: |
if [ "${{ inputs.esr-version }}" != "" ]; then
if ! [[ "${{ inputs.esr-version }}" =~ ^[1-3][0-9]{3}\.[0-1]?[0-9]$ ]]; then
echo "Invalid ESR version ${{ inputs.esr-version }}"
exit 1
fi
esr_version=${{ inputs.esr-version }}
else
esr_version="$(date '+%Y').$(echo $(date '+%m') | sed "s/^0*//")"
if ! [[ "${esr_version}" =~ ^[1-3][0-9]{3}\.[0-1]?[0-9]$ ]]; then
echo "No scheduled ESR release for ${esr-version}."
exit 1
fi
fi
echo "ESR version: ${esr_version}"
echo "esr_version=${esr_version}" >> $GITHUB_OUTPUT
- name: "Calculate versions"
id: calculate-versions
run: |
# The ESR branch starts at the HEAD of the latest minor version
git fetch --tags origin
current_os_version=$(git describe --abbrev=0 $(git rev-list --tags --max-count=1))
current_os_version=${current_os_version:1}
va=(${current_os_version//./ })
if [ ${#va[@]} -ne 3 ]; then
echo "Invalid current version: ${current_os_version}"
exit 1
fi
if [ "${va[1]}" != 0 ]; then
((va[1]--))
os_version=$(git tag --sort -version:refname | grep "v${va[0]}\.${va[1]}" | head -n1)
else
((va[0]--))
os_version=$(git tag --sort -version:refname | grep "v${va[0]}\." | head -n1)
fi
os_version=${os_version:1}
ov_arr=( ${os_version//./ } )
os_esr_branch=${ov_arr[0]}.${ov_arr[1]}.x
if git ls-remote --exit-code --heads origin ${os_esr_branch} > /dev/null; then
echo "Branch ${os_esr_branch} already exists"
exit 1
fi
echo "os_version=${os_version}" >> $GITHUB_OUTPUT
echo "os_esr_branch=${os_esr_branch}" >> $GITHUB_OUTPUT
echo "OS version is ${os_version} and branch ${os_esr_branch}"
exit 0
- name: Setup Python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
with:
python-version: ${{ matrix.python-version }}
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install pyyaml semver
- name: "Create ESR branch"
id: meta-balena-esr-branch
run: |
os_version=${{ steps.calculate-versions.outputs.os_version }}
os_esr_branch=${{ steps.calculate-versions.outputs.os_esr_branch }}
esr_version=${{ steps.assert-esr-version.outputs.esr_version }}
git checkout -b "${os_esr_branch}" refs/tags/v"${os_version}"
# Modify repo.yml
python3 <<-EOF
import sys
import yaml
import semver
filePath = './repo.yml'
parsed_os_version = semver.VersionInfo.parse('${os_version}')
version = str(parsed_os_version.major) + '.' + str(parsed_os_version.minor)
with open(filePath, 'r') as original:
ydata = yaml.safe_load(original)
if 'esr' in ydata:
# Nothing to do
print("ESR branch already configured")
sys.exit(1)
ydata['esr'] = {'version': version, 'bsp-branch-pattern': '${esr_version}.x'}
with open(filePath, 'w') as modified:
yaml.dump(ydata, modified)
EOF
git add repo.yml
git commit -F- <<-EOF
Declare ESR ${os_esr_branch:0:-2}
Change-type: none
EOF
git push origin refs/heads/${os_esr_branch}
git tag -a -m "" ${os_esr_branch} ${os_esr_branch}
git push origin refs/tags/${os_esr_branch}