-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (138 loc) · 5.28 KB
/
renovate-ci.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: Renovate CI
on:
pull_request:
jobs:
get-last-commit-message:
if: contains(github.head_ref, 'renovate/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Get last commit message
id: get-last-commit-message
run: |
echo "last_commit_message=$(git log -1 --pretty=%B)" >> $GITHUB_OUTPUT
update-config:
needs: get-last-commit-message
if: "!contains(${{ needs.get-last-commit-message.outputs.last_commit_message }}, '[ready]')"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
token: ${{ secrets.PERSONAL_TOKEN }}
- name: Get changed files
uses: jitterbit/get-changed-files@v1
id: files
- name: Apply config update
run: |
for changed_file in ${{ steps.files.outputs.all }}; do
echo "Changed file: $changed_file" # example: apps/jackett/docker-compose.yml
if [[ $changed_file == *"docker-compose.yml"* ]]; then
app_name=$(echo $changed_file | cut -d'/' -f 2)
echo "App name: $app_name"
./.github/workflows/renovate-app-version.sh $app_name
fi
done
- name: Commit and push changes
uses: EndBug/add-and-commit@v9
with:
author_name: Tipi CI
author_email: [email protected]
message: "Update app version [ready]"
commit: --no-verify
push: origin HEAD:${{ github.head_ref }}
ci:
needs:
- update-config
- get-last-commit-message
if: contains(${{ needs.get-last-commit-message.outputs.last_commit_message }}, '[ready]')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/[email protected]
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Run global tests
run: pnpm test
- name: Run linter
run: pnpm run lint
- name: Check bumped version
id: check-bumped-version
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const semver = require('semver')
const { data } = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const modifiedFiles = data.map(file => file.filename);
const filesInAppsFolder = modifiedFiles.filter(file => file.includes('apps/'))
if (filesInAppsFolder.length < modifiedFiles.length) {
console.log('Not all files are in apps folder, skipping automerge')
core.setOutput('major_bump', 'true')
return
}
const configs = modifiedFiles.filter(file => file.includes('config.json'))
let majorBump = 'false'
for (const configFile of configs) {
const baseContent = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: configFile,
ref: context.payload.pull_request.base.ref
});
const baseConfig = JSON.parse(Buffer.from(baseContent.data.content, 'base64').toString('utf-8'))
const currentContent = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: configFile,
ref: context.payload.pull_request.head.ref
});
const currentConfig = JSON.parse(Buffer.from(currentContent.data.content, 'base64').toString('utf-8'))
const baseVersion = semver.coerce(baseConfig.version)
const currentVersion = semver.coerce(currentConfig.version)
if (currentVersion?.major > baseVersion?.major) {
console.log('Major bump detected, skipping automerge')
majorBump = 'true'
break
}
}
core.setOutput('major_bump', majorBump)
- name: Label this PR as "automerge" if major_bump is false
if: steps.check-bumped-version.outputs.major_bump == 'false'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.PERSONAL_TOKEN }}
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["automerge"]
})