Skip to content

Commit 614bb1b

Browse files
committed
Add common code
1 parent 66aa899 commit 614bb1b

File tree

12 files changed

+1052
-0
lines changed

12 files changed

+1052
-0
lines changed

.github/workflows/checkBuild.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Check Build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ develop ]
7+
paths-ignore:
8+
- '**.md'
9+
pull_request:
10+
branches: [ develop ]
11+
paths-ignore:
12+
- '**.md'
13+
14+
env:
15+
PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }}
16+
DEMO_MAVEN_MODULE: ${{ github.event.repository.name }}-demo
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
matrix:
24+
java: [17]
25+
distribution: [temurin]
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
30+
- name: Set up JDK
31+
uses: actions/setup-java@v3
32+
with:
33+
distribution: ${{ matrix.distribution }}
34+
java-version: ${{ matrix.java }}
35+
cache: 'maven'
36+
37+
- name: Build with Maven
38+
run: mvn -B clean package
39+
40+
- name: Check for uncommited changes
41+
run: |
42+
if [[ "$(git status --porcelain)" != "" ]]; then
43+
echo ----------------------------------------
44+
echo git status
45+
echo ----------------------------------------
46+
git status
47+
echo ----------------------------------------
48+
echo git diff
49+
echo ----------------------------------------
50+
git diff
51+
echo ----------------------------------------
52+
echo Troubleshooting
53+
echo ----------------------------------------
54+
echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && mvn -B clean package"
55+
exit 1
56+
fi
57+
58+
- name: Upload demo files
59+
uses: actions/upload-artifact@v3
60+
with:
61+
name: demo-files-java-${{ matrix.java }}
62+
path: ${{ env.DEMO_MAVEN_MODULE }}/target/${{ env.DEMO_MAVEN_MODULE }}.jar
63+
if-no-files-found: error

.github/workflows/release.yml

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
env:
8+
PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }}
9+
DEMO_MAVEN_MODULE: ${{ github.event.repository.name }}-demo
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
check_code: # Validates the code
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Set up JDK
22+
uses: actions/setup-java@v3
23+
with:
24+
java-version: '17'
25+
distribution: 'temurin'
26+
cache: 'maven'
27+
28+
- name: Build with Maven
29+
run: mvn -B clean package
30+
31+
- name: Check for uncommited changes
32+
run: |
33+
if [[ "$(git status --porcelain)" != "" ]]; then
34+
echo ----------------------------------------
35+
echo git status
36+
echo ----------------------------------------
37+
git status
38+
echo ----------------------------------------
39+
echo git diff
40+
echo ----------------------------------------
41+
git diff
42+
echo ----------------------------------------
43+
echo Troubleshooting
44+
echo ----------------------------------------
45+
echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && mvn -B clean package"
46+
exit 1
47+
fi
48+
49+
prepare_release:
50+
runs-on: ubuntu-latest
51+
needs: [check_code]
52+
outputs:
53+
upload_url: ${{ steps.create_release.outputs.upload_url }}
54+
steps:
55+
- uses: actions/checkout@v3
56+
57+
- name: Configure Git
58+
run: |
59+
git config --global user.email "[email protected]"
60+
git config --global user.name "GitHub Actions"
61+
62+
- name: Un-SNAP root
63+
run: mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false
64+
65+
- name: Un-SNAP demo
66+
run: mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false
67+
working-directory: ${{ env.DEMO_MAVEN_MODULE }}
68+
69+
- name: Un-SNAP
70+
run: mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false
71+
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
72+
73+
- name: Get version
74+
id: version
75+
run: |
76+
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
77+
echo "release=$version" >> $GITHUB_OUTPUT
78+
echo "releasenumber=${version//[!0-9]/}" >> $GITHUB_OUTPUT
79+
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
80+
81+
- name: Commit and Push
82+
run: |
83+
git add -A
84+
git commit -m "Release ${{ steps.version.outputs.release }}"
85+
git push origin
86+
git tag v${{ steps.version.outputs.release }}
87+
git push origin --tags
88+
89+
- name: Create Release
90+
id: create_release
91+
uses: shogo82148/actions-create-release@v1
92+
with:
93+
tag_name: v${{ steps.version.outputs.release }}
94+
release_name: v${{ steps.version.outputs.release }}
95+
commitish: master
96+
body: |
97+
## [Changelog](https://github.com/xdev-software/${{ env.PRIMARY_MAVEN_MODULE }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }})
98+
See [Changelog#v${{ steps.version.outputs.release }}](https://github.com/xdev-software/${{ env.PRIMARY_MAVEN_MODULE }}/blob/develop/CHANGELOG.md#${{ steps.version.outputs.releasenumber }}) for more information.
99+
100+
## Installation
101+
Add the following lines to your pom:
102+
```XML
103+
<dependency>
104+
<groupId>com.xdev-software</groupId>
105+
<artifactId>${{ env.PRIMARY_MAVEN_MODULE }}</artifactId>
106+
<version>${{ steps.version.outputs.release }}</version>
107+
</dependency>
108+
```
109+
110+
publish_central: # Publish the code to central
111+
runs-on: ubuntu-latest
112+
needs: [prepare_release]
113+
steps:
114+
- uses: actions/checkout@v3
115+
116+
- name: Init Git and pull
117+
run: |
118+
git config --global user.email "[email protected]"
119+
git config --global user.name "GitHub Actions"
120+
git pull
121+
122+
- name: Set up JDK Apache Maven Central
123+
uses: actions/setup-java@v3
124+
with: # running setup-java again overwrites the settings.xml
125+
java-version: '17'
126+
distribution: 'temurin'
127+
server-id: ossrh
128+
server-username: MAVEN_CENTRAL_USERNAME
129+
server-password: MAVEN_CENTRAL_TOKEN
130+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
131+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
132+
133+
- name: Publish to Apache Maven Central
134+
run: mvn -B deploy -Possrh
135+
env:
136+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
137+
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
138+
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
139+
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
140+
141+
publish-pages:
142+
name: Publish dependencies and licenses to github pages
143+
runs-on: ubuntu-latest
144+
needs: [prepare_release]
145+
steps:
146+
- uses: actions/checkout@v3
147+
148+
- name: Init Git and pull
149+
run: |
150+
git config --global user.email "[email protected]"
151+
git config --global user.name "GitHub Actions"
152+
git pull
153+
154+
- name: Setup - Java
155+
uses: actions/setup-java@v3
156+
with:
157+
java-version: '17'
158+
distribution: 'temurin'
159+
cache: 'maven'
160+
161+
- name: Build dependencies/licenses files
162+
run: mvn -B project-info-reports:dependencies
163+
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
164+
165+
- name: Upload licenses - Upload Artifact
166+
uses: actions/upload-artifact@v3
167+
with:
168+
name: dependencies-licenses
169+
path: ${{ env.PRIMARY_MAVEN_MODULE }}/target/site
170+
171+
- name: Generate docs/dependencies dir
172+
run: mkdir -p docs/dependencies
173+
174+
- name: Move built files into docs/dependencies
175+
run: mv ${{ env.PRIMARY_MAVEN_MODULE }}/target/site/* docs/dependencies
176+
177+
- name: Rename dependencies.html to index.html
178+
working-directory: docs/dependencies
179+
run: mv dependencies.html index.html
180+
181+
- name: Copy Readme into docs (as index.md)
182+
run: cp README.md docs/index.md
183+
184+
- name: Configure Pages
185+
working-directory: docs
186+
run: |-
187+
echo "theme: jekyll-theme-tactile" > _config.yml
188+
189+
- name: Deploy to Github pages
190+
uses: peaceiris/actions-gh-pages@v3
191+
with:
192+
github_token: ${{ secrets.GITHUB_TOKEN }}
193+
publish_dir: ./docs
194+
enable_jekyll: true
195+
196+
after_release:
197+
runs-on: ubuntu-latest
198+
needs: [publish_central]
199+
steps:
200+
- uses: actions/checkout@v3
201+
202+
- name: Init Git and pull
203+
run: |
204+
git config --global user.email "[email protected]"
205+
git config --global user.name "GitHub Actions"
206+
git pull
207+
208+
- name: Inc Version and SNAP root
209+
run: mvn -B build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false -DnextSnapshot=true
210+
211+
- name: Inc Version and SNAP demo
212+
run: mvn -B build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false -DnextSnapshot=true
213+
working-directory: ${{ env.DEMO_MAVEN_MODULE }}
214+
215+
- name: Inc Version and SNAP
216+
run: mvn -B build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false -DnextSnapshot=true
217+
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
218+
219+
- name: Git Commit and Push
220+
run: |
221+
git add -A
222+
git commit -m "Preparing for next development iteration"
223+
git push origin
224+
225+
- name: pull-request
226+
uses: repo-sync/pull-request@v2
227+
with:
228+
destination_branch: "develop"
229+
pr_title: "Sync back"
230+
pr_body: "An automated PR to sync changes back"
231+

.github/workflows/sonar.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Sonar
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ develop ]
7+
paths-ignore:
8+
- '**.md'
9+
- 'assets/**'
10+
- 'config/**'
11+
pull_request:
12+
types: [opened, synchronize, reopened]
13+
paths-ignore:
14+
- '**.md'
15+
- 'assets/**'
16+
- 'config/**'
17+
18+
env:
19+
SONARCLOUD_ORG: ${{ github.event.organization.login }}
20+
SONARCLOUD_HOST: https://sonarcloud.io
21+
22+
jobs:
23+
sonar:
24+
name: SonarCloud Scan
25+
runs-on: ubuntu-latest
26+
# Dependabot PRs have no access to secrets (SONAR_TOKEN) -> Ignore them
27+
if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'dependabot/') }}
28+
steps:
29+
- uses: actions/checkout@v3
30+
with:
31+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
32+
33+
- name: Set up JDK
34+
uses: actions/setup-java@v3
35+
with:
36+
distribution: 'temurin'
37+
java-version: 17
38+
39+
- name: Cache SonarCloud packages
40+
uses: actions/cache@v3
41+
with:
42+
path: ~/.sonar/cache
43+
key: ${{ runner.os }}-sonar
44+
restore-keys: ${{ runner.os }}-sonar
45+
46+
- name: Cache Maven packages
47+
uses: actions/cache@v3
48+
with:
49+
path: ~/.m2
50+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
51+
restore-keys: ${{ runner.os }}-m2
52+
53+
- name: Build with Maven
54+
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=${{ env.SONARCLOUD_ORG }}_${{ github.event.repository.name }} -Dsonar.organization=${{ env.SONARCLOUD_ORG }} -Dsonar.host.url=${{ env.SONARCLOUD_HOST }}
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
57+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/test-deploy.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test Deployment
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
PRIMARY_MAVEN_MODULE: ${{ github.event.repository.name }}
8+
9+
jobs:
10+
publish_central: # Publish the code to central
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Set up JDK OSSRH
16+
uses: actions/setup-java@v3
17+
with: # running setup-java again overwrites the settings.xml
18+
distribution: 'temurin'
19+
java-version: '17'
20+
server-id: ossrh
21+
server-username: MAVEN_CENTRAL_USERNAME
22+
server-password: MAVEN_CENTRAL_TOKEN
23+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
24+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
25+
26+
- name: Publish to OSSRH
27+
run: mvn -B deploy -Possrh
28+
working-directory: ${{ env.PRIMARY_MAVEN_MODULE }}
29+
env:
30+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
31+
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
32+
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

0 commit comments

Comments
 (0)