Skip to content

Commit 2286580

Browse files
authored
Refactor GitHub Action Workflows (pmd#271)
- Do not rely on build-tools shell scripts anymore - Two stage approach: - build.yml, that works also on forks - publish-snapshot/publish-release with secrets Refs pmd/pmd#4328 Refs pmd/build-tools#68 Refs pmd/pmd-designer#168
2 parents b5a96ac + 22417a9 commit 2286580

File tree

6 files changed

+665
-76
lines changed

6 files changed

+665
-76
lines changed

.ci/files/regenerate_metadata.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
echo "Regenerating metadata for p2-site..."
4+
local releases=($(find . -maxdepth 1 -type d -regex "\./[0-9]+\.[0-9]+\.[0-9]+\..*" -printf '%f\n'| tr '.' '\0' | sort -t '\0' -k1,1nr -k2,2nr -k3,3nr -k4dr |awk -F '\0' '{printf "%s.%s.%s.%s\n", $1, $2, $3, $4}'))
5+
# remove old releases
6+
for i in "${releases[@]:5}"; do
7+
pmd_ci_log_info "Removing old release $i..."
8+
rm -rf "$i"
9+
done
10+
releases=("${releases[@]:0:5}")
11+
12+
# regenerate metadata
13+
local now
14+
now=$(date +%s000)
15+
local children=""
16+
local children_index=""
17+
for i in "${releases[@]}"; do
18+
children="${children} <child location=\"$i\"/>\n"
19+
children_index="${children_index} * [$i]($i/)\n"
20+
echo "This is a Eclipse Update Site for the [PMD Eclipse Plugin](https://github.com/pmd/pmd-eclipse-plugin/) ${i}.
21+
22+
Use <https://pmd.github.io/pmd-eclipse-plugin-p2-site/${i}/> to install the plugin with the Eclipse Update Manager.
23+
24+
<dl>
25+
<dt>Feature ID</dt>
26+
<dd>net.sourceforge.pmd.eclipse</dd>
27+
<dt>Version</dt>
28+
<dd>${i}</dd>
29+
</dl>
30+
31+
" > "$i"/index.md
32+
33+
git add "$i"/index.md
34+
done
35+
36+
local site_name="PMD for Eclipse - Update Site"
37+
local artifactsTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
38+
<?compositeArtifactRepository version=\"1.0.0\"?>
39+
<repository name=\"${site_name}\" type=\"org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository\" version=\"1.0.0\">
40+
<properties size=\"2\">
41+
<property name=\"p2.timestamp\" value=\"${now}\"/>
42+
<property name=\"p2.atomic.composite.loading\" value=\"true\"/>
43+
</properties>
44+
<children size=\"${#releases[@]}\">
45+
${children} </children>
46+
</repository>"
47+
echo -e "${artifactsTemplate}" > compositeArtifacts.xml
48+
49+
local contentTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
50+
<?compositeMetadataRepository version=\"1.0.0\"?>
51+
<repository name=\"${site_name}\" type=\"org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository\" version=\"1.0.0\">
52+
<properties size=\"2\">
53+
<property name=\"p2.timestamp\" value=\"${now}\"/>
54+
<property name=\"p2.atomic.composite.loading\" value=\"true\"/>
55+
</properties>
56+
<children size=\"${#releases[@]}\">
57+
${children} </children>
58+
</repository>"
59+
echo -e "${contentTemplate}" > compositeContent.xml
60+
61+
# p2.index
62+
local p2_index="version = 1
63+
metadata.repository.factory.order = compositeContent.xml,\!
64+
artifact.repository.factory.order = compositeArtifacts.xml,\!"
65+
echo -e "${p2_index}" > p2.index
66+
67+
# regenerate index.md
68+
echo -e "This is a composite Eclipse Update Site for the [PMD Eclipse Plugin](https://github.com/pmd/pmd-eclipse-plugin/).
69+
70+
Use <https://pmd.github.io/pmd-eclipse-plugin-p2-site/> to install the plugin with the Eclipse Update Manager.
71+
72+
----
73+
74+
Versions available at <https://pmd.github.io/pmd-eclipse-plugin-p2-site/>:
75+
76+
${children_index}
77+
78+
For older versions, see <https://sourceforge.net/projects/pmd/files/pmd-eclipse/zipped/>
79+
80+
" > index.md
81+

.github/actions/build/action.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/actions/setup/action.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: 'Setup'
2-
description: 'Setup java and ruby, check environment'
2+
description: 'Setup java and xvfb'
33

44
runs:
55
using: 'composite'
66
steps:
77
- name: Set up JDK 21
8-
id: java21
98
uses: actions/setup-java@v4
109
with:
1110
distribution: temurin
@@ -20,21 +19,11 @@ runs:
2019
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml', '**/*.target') }}
2120
restore-keys: |
2221
${{ runner.os }}-maven-
23-
- name: Set up Ruby 3.3
24-
uses: ruby/setup-ruby@v1
25-
with:
26-
ruby-version: 3.3
27-
- name: Setup Environment
28-
shell: bash
29-
run: |
30-
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
31-
echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3" >> $GITHUB_ENV
32-
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/30/scripts" >> $GITHUB_ENV
33-
- name: Check Environment
22+
- name: Setup xvfb
23+
if: ${{ runner.os == 'Linux' }}
3424
shell: bash
3525
run: |
36-
f=check-environment.sh; \
37-
mkdir -p .ci && \
38-
( [ -e .ci/$f ] || curl -sSL "${PMD_CI_SCRIPTS_URL}/$f" > ".ci/$f" ) && \
39-
chmod 755 .ci/$f && \
40-
.ci/$f
26+
#see https://github.com/GabrielBB/xvfb-action
27+
sudo apt-get install --yes xvfb
28+
sudo apt-get install --yes libgtk2.0-0
29+
echo 'xvfb_cmd=xvfb-run --auto-servernum' >> "$GITHUB_ENV"

.github/workflows/build.yml

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,73 @@
1-
name: build
1+
name: Build
22

33
on:
4+
pull_request:
5+
merge_group:
46
push:
57
branches:
6-
- main
8+
- '**'
9+
# don't run on dependabot branches. Dependabot will create pull requests, which will then be run instead
10+
- '!dependabot/**'
711
tags:
812
- '**'
9-
pull_request:
13+
workflow_dispatch:
1014
schedule:
1115
# build it monthly: At 05:00 on day-of-month 1.
1216
- cron: '0 5 1 * *'
13-
workflow_dispatch:
17+
18+
# if another commit is added to the same branch or PR (same github.ref),
19+
# then cancel already running jobs and start a new build.
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}
22+
cancel-in-progress: true
23+
24+
permissions:
25+
contents: read # to fetch code (actions/checkout)
26+
27+
env:
28+
LANG: 'en_US.UTF-8'
1429

1530
jobs:
1631
# verify build on one node before multiple builds on different os are started
1732
fail-fast-build:
1833
name: verify (ubuntu-latest, 2025-03)
19-
timeout-minutes: 60
34+
timeout-minutes: 30
35+
defaults:
36+
run:
37+
shell: bash
2038
runs-on: ubuntu-latest
2139
steps:
22-
- name: Checkout
23-
uses: actions/checkout@v4
40+
- uses: actions/checkout@v4
2441

2542
- name: Setup Environment
2643
uses: ./.github/actions/setup
2744

2845
- name: Build
29-
uses: ./.github/actions/build
30-
with:
31-
targetPlatform: 2025-03
32-
deploy: true
33-
pmdCiSecretPassphrase: ${{ secrets.PMD_CI_SECRET_PASSPHRASE }}
34-
githubToken: ${{ secrets.GITHUB_TOKEN }}
35-
pmdCiGpgPrivateKey: ${{ secrets.PMD_CI_GPG_PRIVATE_KEY }}
36-
pmdCiGpgPassphrase: ${{ secrets.PMD_CI_GPG_PASSPHRASE }}
46+
run: |
47+
${xvfb_cmd} ./mvnw --show-version --errors --batch-mode \
48+
verify
3749
3850
- name: Upload screenshots of failed unit tests
3951
uses: actions/upload-artifact@v4
4052
if: ${{ failure() }}
4153
with:
42-
name: screenshots-ubuntu-latest-2025-03
54+
name: screenshots-ubuntu-latest
4355
path: net.sourceforge.pmd.eclipse.plugin.test/screenshots
4456
if-no-files-found: ignore
4557

58+
- name: Upload update-site
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: update-site
62+
path: net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-*.zip
4663

4764
build:
4865
needs: fail-fast-build
4966
name: verify (${{ matrix.os }}, ${{ matrix.targetPlatform }})
50-
timeout-minutes: 60
67+
timeout-minutes: 30
68+
defaults:
69+
run:
70+
shell: bash
5171
continue-on-error: false
5272

5373
strategy:
@@ -70,17 +90,18 @@ jobs:
7090

7191
runs-on: ${{ matrix.os }}
7292
steps:
73-
- name: Checkout
74-
uses: actions/checkout@v4
93+
- uses: actions/checkout@v4
7594

7695
- name: Setup Environment
7796
uses: ./.github/actions/setup
7897

7998
- name: Build
80-
uses: ./.github/actions/build
81-
with:
82-
targetPlatform: ${{ matrix.targetPlatform }}
83-
deploy: false
99+
env:
100+
TARGET_PLATFORM: ${{ matrix.targetPlatform }}
101+
run: |
102+
${xvfb_cmd} ./mvnw --show-version --errors --batch-mode \
103+
verify \
104+
-Dtarget.platform="${TARGET_PLATFORM}"
84105
85106
- name: Upload screenshots of failed unit tests
86107
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)