-
Notifications
You must be signed in to change notification settings - Fork 90
169 lines (167 loc) · 6.46 KB
/
cleanCode.yml
File metadata and controls
169 lines (167 loc) · 6.46 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
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
163
164
165
166
167
168
169
###############################################################################
# Copyright (c) 2025 Contributors to Eclipse Foundation
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0/.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# see git history
###############################################################################
name: Automatic Code Cleanups
on:
workflow_call:
inputs:
author:
description: Defines the committer / author that should be used for the commit
required: true
type: string
bundle-folders:
description: Defines the folders that should be scanned for bundles, must be a valid argument to the 'ls' command, defaults to 'bundles/*/'
required: false
default: 'bundles/*/'
type: string
do-cleanups:
description: Configures if cleanup actions should be performed
required: false
default: false
type: boolean
do-quickfix:
description: Configures if quickfix actions should be performed
required: false
default: false
type: boolean
do-manifest:
description: Configures if organize manifest actions should be performed
required: false
default: false
type: boolean
branch:
description: 'The branch to clean'
type: string
required: false
default: 'master'
submodules:
description: |
Whether to checkout submodules: `true` to checkout submodules or `recursive` to recursively checkout submodules.
When the `ssh-key` input is not provided, SSH URLs beginning with `git@github.com:` are converted to HTTPS.
The value is just passed as it is to the github/actions/checkout action: https://github.com/actions/checkout#usage
type: string
required: false
default: 'false'
mavenVersion:
description: 'The version of Maven set up'
type: string
required: false
default: '3.9.14'
secrets:
token:
description: Personal Access Token to use for creating pull-requests
required: true
jobs:
list-bundles:
runs-on: ubuntu-latest
outputs:
bundles: ${{ steps.list-bundles.outputs.bundles }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
ref: ${{ inputs.branch }}
submodules: ${{ inputs.submodules }}
- name: List all bundles
id: list-bundles
env:
FOLDER_PATTERN: ${{ inputs.bundle-folders }}
run: |
directories=($(ls -d $FOLDER_PATTERN))
directories=("${directories[@]%/}")
json_array=()
for dir in "${directories[@]}"; do
if [ -e ${dir}/META-INF/MANIFEST.MF ]
then
json_array+=("\"$dir\"")
fi
done
json_elements=$(IFS=,; echo "${json_array[*]}")
json_output="{ \"bundles\": [$json_elements] }"
echo "bundles=$json_output" | tee -a "$GITHUB_OUTPUT"
clean-bundles:
runs-on: ubuntu-latest
name: Cleanup ${{ matrix.bundles }}
if: always()
needs: list-bundles
strategy:
matrix: ${{ fromJson(needs.list-bundles.outputs.bundles) }}
max-parallel: 1
fail-fast: false
steps:
- name: List number of open PRs
id: list-prs
run: |
json_output=$(gh pr list -l 'cleanup' -R $OWNER/$REPO -L 20 --json id)
echo "prs=$json_output" | tee -a "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: ${{ fromJson(steps.list-prs.outputs.prs)[9] == null }}
with:
fetch-depth: 0
ref: ${{ inputs.branch }}
- name: Set up Maven
uses: stCarolas/setup-maven@d6af6abeda15e98926a57b5aa970a96bb37f97d1 # v5
if: ${{ fromJson(steps.list-prs.outputs.prs)[9] == null }}
with:
maven-version: ${{ inputs.mavenVersion }}
- name: Set up JDK
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
if: ${{ fromJson(steps.list-prs.outputs.prs)[9] == null }}
with:
java-version: |
8
11
17
21
distribution: 'temurin'
cache: maven
- name: Perform Cleanups on ${{ matrix.bundles }}
working-directory: ${{ matrix.bundles }}
if: ${{ inputs.do-cleanups && fromJson(steps.list-prs.outputs.prs)[9] == null }}
run: >-
xvfb-run mvn -U -B -ntp tycho-cleancode:cleanup@cleanups
- name: Perform QuickFixes on ${{ matrix.bundles }}
working-directory: ${{ matrix.bundles }}
if: ${{ inputs.do-quickfix && fromJson(steps.list-prs.outputs.prs)[9] == null }}
run: >-
xvfb-run mvn -U -B -ntp -e tycho-cleancode:quickfix@quickfixes
- name: Perform Organize Manifest on ${{ matrix.bundles }}
working-directory: ${{ matrix.bundles }}
if: ${{ inputs.do-manifest && fromJson(steps.list-prs.outputs.prs)[9] == null }}
run: >-
xvfb-run mvn -U -B -ntp -e tycho-cleancode:manifest@manifest
- name: Create final PR description
working-directory: ${{ matrix.bundles }}/target
if: ${{ hashFiles(format('{0}/target/quickfix.md', matrix.bundles)) != '' || hashFiles(format('{0}/target/cleanups.md', matrix.bundles)) != '' || hashFiles(format('{0}/target/organizeManifest.md', matrix.bundles)) != '' }}
run: >-
cat *.md > pr.md
- name: Create Pull Request
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
if: ${{ hashFiles(format('{0}/target/pr.md', matrix.bundles)) != '' }}
with:
commit-message: Perform clean code of ${{ matrix.bundles }}
branch: clean-code/${{ matrix.bundles }}
title: Clean Code for ${{ matrix.bundles }}
body-path: ${{ matrix.bundles }}/target/pr.md
delete-branch: true
draft: false
labels: cleanup
token: ${{ secrets.token }}
committer: ${{ inputs.author }}
author: ${{ inputs.author }}
add-paths: |
**/*.java
**/*.MF