Skip to content

Commit 63b0042

Browse files
committed
Refactor GitHub Actions Workflows
Don't rely on shell scripts from build-tools anymore. Main build.yml can be run on forks, as it doesn't need any secrets. Use two additional workflows for snapshots and releases. Similar to pmd/build-tools#68 Refs pmd/pmd#4328
1 parent eb70e14 commit 63b0042

File tree

3 files changed

+240
-42
lines changed

3 files changed

+240
-42
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,53 @@
1-
name: build
1+
name: Build
22
on:
3+
pull_request:
4+
merge_group:
35
push:
46
branches:
5-
- main
7+
- '**'
8+
# don't run on dependabot branches. Dependabot will create pull requests, which will then be run instead
9+
- '!dependabot/**'
610
tags:
711
- '**'
8-
pull_request:
12+
workflow_dispatch:
913
schedule:
1014
# build it monthly: At 05:00 on day-of-month 1.
1115
- cron: '0 5 1 * *'
12-
workflow_dispatch:
16+
17+
# if another commit is added to the same branch or PR (same github.ref),
18+
# then cancel already running jobs and start a new build.
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
permissions:
24+
contents: read # to fetch code (actions/checkout)
25+
26+
env:
27+
LANG: 'en_US.UTF-8'
1328

1429
jobs:
15-
build:
30+
compile:
1631
runs-on: ubuntu-latest
17-
continue-on-error: false
18-
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
32+
timeout-minutes: 10
33+
defaults:
34+
run:
35+
shell: bash
1936
steps:
20-
- uses: actions/checkout@v4
21-
- uses: actions/cache@v4
22-
with:
23-
path: |
24-
~/.m2/repository
25-
~/.cache
26-
key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
27-
restore-keys: |
28-
${{ runner.os }}-
29-
- name: Set up Ruby 3.3
30-
uses: ruby/setup-ruby@v1
31-
with:
32-
ruby-version: 3.3
33-
- name: Setup Environment
34-
shell: bash
35-
run: |
36-
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
37-
echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3" >> $GITHUB_ENV
38-
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/30/scripts" >> $GITHUB_ENV
39-
- name: Check Environment
40-
shell: bash
41-
run: |
42-
f=check-environment.sh; \
43-
mkdir -p .ci && \
44-
( [ -e .ci/$f ] || curl -sSL "${PMD_CI_SCRIPTS_URL}/$f" > ".ci/$f" ) && \
45-
chmod 755 .ci/$f && \
46-
.ci/$f
47-
- name: Build
48-
run: .ci/build.sh
49-
shell: bash
50-
env:
51-
PMD_CI_SECRET_PASSPHRASE: ${{ secrets.PMD_CI_SECRET_PASSPHRASE }}
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
PMD_CI_GPG_PRIVATE_KEY: ${{ secrets.PMD_CI_GPG_PRIVATE_KEY }}
54-
MAVEN_GPG_PASSPHRASE: ${{ secrets.PMD_CI_GPG_PASSPHRASE }}
37+
- uses: actions/checkout@v4
38+
- uses: actions/setup-java@v4
39+
with:
40+
distribution: 'temurin'
41+
java-version: '11'
42+
cache: 'maven'
43+
- name: Build with Maven
44+
run: |
45+
./mvnw --show-version --errors --batch-mode \
46+
-Pshading \
47+
verify
48+
- uses: actions/upload-artifact@v4
49+
with:
50+
name: compile-artifact
51+
if-no-files-found: error
52+
path: |
53+
target/pmd-designer-*.jar
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Publish Release
2+
3+
on:
4+
workflow_run:
5+
workflows: [Build]
6+
types:
7+
- completed
8+
branches:
9+
- '**'
10+
- '!main'
11+
- '!dependabot/**'
12+
13+
permissions:
14+
contents: read # to fetch code (actions/checkout)
15+
16+
env:
17+
LANG: 'en_US.UTF-8'
18+
19+
jobs:
20+
check-version:
21+
# only run in the official pmd/pmd-designer repo, where we have access to the secrets and not on forks
22+
# and only run for _successful_ push workflow runs on tags.
23+
if: ${{ github.repository == 'pmd/designer'
24+
&& github.event.workflow_run.event == 'push'
25+
&& github.event.workflow_run.head_branch != 'main'
26+
&& github.event.workflow_run.conclusion == 'success' }}
27+
runs-on: ubuntu-latest
28+
timeout-minutes: 10
29+
defaults:
30+
run:
31+
shell: bash
32+
outputs:
33+
VERSION: ${{ steps.version.outputs.VERSION }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
with:
37+
ref: ${{ github.event.workflow_run.head_branch }}
38+
- uses: actions/setup-java@v4
39+
with:
40+
distribution: 'temurin'
41+
java-version: '11'
42+
cache: 'maven'
43+
- name: Determine Version
44+
id: version
45+
env:
46+
REF: ${{ github.event.workflow_run.head_branch }}
47+
run: |
48+
if ! git show-ref --exists "refs/tags/$REF"; then
49+
echo "::error ::Tag $REF does not exist, aborting."
50+
exit 1
51+
fi
52+
53+
VERSION=$(./mvnw --batch-mode --no-transfer-progress help:evaluate -Dexpression=project.version -q -DforceStdout)
54+
echo "Determined VERSION=$VERSION"
55+
if [[ "$VERSION" = *-SNAPSHOT ]]; then
56+
echo "::error ::VERSION=$VERSION is a snapshot version, aborting."
57+
exit 1
58+
fi
59+
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
60+
61+
deploy-to-maven-central:
62+
needs: check-version
63+
# use environment maven-central, where secrets are configured for OSSRH_*
64+
environment:
65+
name: maven-central
66+
url: https://repo.maven.apache.org/maven2/net/sourceforge/pmd/pmd-designer/
67+
runs-on: ubuntu-latest
68+
timeout-minutes: 20
69+
permissions:
70+
contents: write # to create a new release
71+
defaults:
72+
run:
73+
shell: bash
74+
steps:
75+
- uses: actions/checkout@v4
76+
with:
77+
ref: ${{ github.event.workflow_run.head_branch }}
78+
- uses: actions/setup-java@v4
79+
with:
80+
distribution: 'temurin'
81+
java-version: '11'
82+
cache: 'maven'
83+
server-id: ossrh
84+
server-username: MAVEN_USERNAME
85+
server-password: MAVEN_PASSWORD
86+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
87+
gpg-private-key: ${{ secrets.PMD_CI_GPG_PRIVATE_KEY }}
88+
- name: Build and Publish
89+
env:
90+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
91+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
92+
MAVEN_GPG_PASSPHRASE: ${{ secrets.PMD_CI_GPG_PASSPHRASE }}
93+
run: |
94+
./mvnw --show-version --errors --batch-mode \
95+
-Psign,shading \
96+
deploy
97+
- name: Prepare Release Notes
98+
run: |
99+
BEGIN_LINE=$(grep -n "^## " CHANGELOG.md|head -1|cut -d ":" -f 1)
100+
BEGIN_LINE=$((BEGIN_LINE + 1))
101+
END_LINE=$(grep -n "^## " CHANGELOG.md|head -2|tail -1|cut -d ":" -f 1)
102+
END_LINE=$((END_LINE - 1))
103+
RELEASE_BODY="$(head -$END_LINE CHANGELOG.md | tail -$((END_LINE - BEGIN_LINE)))"
104+
echo "$RELEASE_BODY" > release_notes.md
105+
- name: Create Release
106+
env:
107+
TAG_NAME: ${{ github.event.workflow_run.head_branch }}
108+
VERSION: ${{ needs.check-version.outputs.VERSION }}
109+
run: |
110+
# Note: The release asset is the shaded jar
111+
gh release create "$TAG_NAME" "target/pmd-designer-${VERSION}.jar" \
112+
--verify-tag \
113+
--notes-file release_notes.md \
114+
--title "$VERSION"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Publish Snapshot
2+
3+
on:
4+
workflow_run:
5+
workflows: [Build]
6+
types:
7+
- completed
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read # to fetch code (actions/checkout)
13+
14+
env:
15+
LANG: 'en_US.UTF-8'
16+
17+
jobs:
18+
check-version:
19+
# only run in the official pmd/pmd-designer repo, where we have access to the secrets and not on forks
20+
# and only run for _successful_ push workflow runs on branch "main".
21+
if: ${{ github.repository == 'pmd/pmd-designer'
22+
&& github.event.workflow_run.event == 'push'
23+
&& github.event.workflow_run.head_branch == 'main'
24+
&& github.event.workflow_run.conclusion == 'success' }}
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 10
27+
defaults:
28+
run:
29+
shell: bash
30+
outputs:
31+
VERSION: ${{ steps.version.outputs.VERSION }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
ref: main
36+
- uses: actions/setup-java@v4
37+
with:
38+
distribution: 'temurin'
39+
java-version: '11'
40+
cache: 'maven'
41+
- name: Determine Version
42+
id: version
43+
run: |
44+
VERSION=$(./mvnw --batch-mode --no-transfer-progress help:evaluate -Dexpression=project.version -q -DforceStdout)
45+
echo "Determined VERSION=$VERSION"
46+
if [[ "$VERSION" != *-SNAPSHOT ]]; then
47+
echo "::error ::VERSION=$VERSION is not a snapshot version, aborting."
48+
exit 1
49+
fi
50+
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
51+
52+
deploy-to-maven-central:
53+
needs: check-version
54+
# use environment maven-central, where secrets are configured for OSSRH_*
55+
environment:
56+
name: maven-central
57+
url: https://oss.sonatype.org/content/repositories/snapshots/net/sourceforge/pmd/pmd-designer/
58+
runs-on: ubuntu-latest
59+
timeout-minutes: 20
60+
defaults:
61+
run:
62+
shell: bash
63+
steps:
64+
- uses: actions/checkout@v4
65+
with:
66+
ref: main
67+
- uses: actions/setup-java@v4
68+
with:
69+
distribution: 'temurin'
70+
java-version: '11'
71+
cache: 'maven'
72+
server-id: ossrh
73+
server-username: MAVEN_USERNAME
74+
server-password: MAVEN_PASSWORD
75+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
76+
gpg-private-key: ${{ secrets.PMD_CI_GPG_PRIVATE_KEY }}
77+
- name: Build and Publish
78+
env:
79+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
80+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
81+
MAVEN_GPG_PASSPHRASE: ${{ secrets.PMD_CI_GPG_PASSPHRASE }}
82+
run: |
83+
./mvnw --show-version --errors --batch-mode \
84+
-Psign,shading \
85+
deploy

0 commit comments

Comments
 (0)