Skip to content

Commit 79fd783

Browse files
authored
Merge branch 'main' into dependabot/maven/example/org.jacoco-jacoco-maven-plugin-0.8.14
2 parents 4235956 + 86fa62a commit 79fd783

File tree

8 files changed

+199
-101
lines changed

8 files changed

+199
-101
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ updates:
88
time: "23:30"
99
open-pull-requests-limit: 10
1010
reviewers:
11-
- paul58914080
11+
- devs-from-matrix/app-generator-team
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Continuous Integration For Example Project
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
paths:
7+
- 'example/**'
8+
- '.github/workflows/ci-for-example.yaml'
9+
workflow_dispatch:
10+
jobs:
11+
example-ci:
12+
defaults:
13+
run:
14+
working-directory: ./example
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Set up JDK 21
20+
uses: actions/setup-java@v4
21+
with:
22+
distribution: temurin
23+
java-version: 21
24+
- name: Cache Maven dependencies
25+
uses: actions/cache@v4
26+
with:
27+
path: ~/.m2/repository
28+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
29+
restore-keys: |
30+
${{ runner.os }}-maven-
31+
- name: Build with Maven
32+
run: mvn clean verify -ntp
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Continuous Integration From Template
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
paths:
7+
- '{{cookiecutter.app_name}}/**'
8+
workflow_dispatch:
9+
jobs:
10+
generate-from-template:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout PR branch
14+
uses: actions/checkout@v4
15+
with:
16+
# checkout the pull request head ref when available, otherwise fallback to the workflow ref
17+
ref: ${{ github.head_ref || github.ref }}
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.x'
23+
- name: Install cookiecutter
24+
run: |
25+
pip install --upgrade pip cookiecutter
26+
- name: Generate from default context (cookiecutter.json)
27+
run: |
28+
# Generate using the config file test-config.yml from the repo root.
29+
# Use the repo root as the template directory (.) and overwrite any existing generated output.
30+
cookiecutter --no-input --config-file test-config.yml --overwrite-if-exists --output-dir . .
31+
- name: Upload generated cart-service as artifact
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: cart-service
35+
path: ./cart-service
36+
cart-service-ci:
37+
needs: generate-from-template
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Download generated cart-service artifact
41+
uses: actions/download-artifact@v4
42+
with:
43+
name: cart-service
44+
path: ./cart-service
45+
- name: Show downloaded files
46+
run: |
47+
echo "Working dir: $(pwd)"
48+
ls -la ./cart-service
49+
- name: Set up JDK 21
50+
uses: actions/setup-java@v4
51+
with:
52+
distribution: temurin
53+
java-version: 21
54+
- name: Cache Maven dependencies
55+
uses: actions/cache@v4
56+
with:
57+
path: ~/.m2/repository
58+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
59+
restore-keys: |
60+
${{ runner.os }}-maven-
61+
- name: Build with Maven
62+
run: git init && mvn clean verify -Dgit-code-format.skip=true -DargLine="--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" -ntp
63+
working-directory: ./cart-service

.github/workflows/ci.yaml

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Generate Template
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
10+
jobs:
11+
generate-template:
12+
runs-on: ubuntu-latest
13+
env:
14+
GENERATED_BRANCH_NAME: generated-template
15+
steps:
16+
- name: Checkout main
17+
uses: actions/checkout@v4
18+
with:
19+
ref: main
20+
fetch-depth: 0
21+
token: ${{ secrets.PAT_TOKEN }}
22+
23+
- name: Configure Git for push
24+
run: |
25+
git config user.name "github-actions[bot]"
26+
git config user.email "github-actions[bot]@users.noreply.github.com"
27+
git remote set-url origin "https://${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git"
28+
29+
- name: Check Branch & PR
30+
id: check_branch_pr
31+
env:
32+
GH_TOKEN: ${{ secrets.PAT_TOKEN }} # PAT or GITHUB_TOKEN with write access
33+
run: |
34+
git fetch origin
35+
36+
# --- Check if branch exists remotely ---
37+
if git show-ref --verify --quiet refs/remotes/origin/$GENERATED_BRANCH_NAME; then
38+
echo "✅ Branch $GENERATED_BRANCH_NAME exists remotely."
39+
git checkout $GENERATED_BRANCH_NAME
40+
git pull origin $GENERATED_BRANCH_NAME
41+
echo "branch_exists=true" >> $GITHUB_OUTPUT
42+
else
43+
echo "🚫 Branch $GENERATED_BRANCH_NAME does not exist."
44+
git checkout -b $GENERATED_BRANCH_NAME
45+
git push -u origin $GENERATED_BRANCH_NAME
46+
echo "branch_exists=false" >> $GITHUB_OUTPUT
47+
fi
48+
echo "branch=${GENERATED_BRANCH_NAME}" >> $GITHUB_OUTPUT
49+
50+
# --- Check if PR already exists for this branch ---
51+
OPEN_PR=$(gh pr list --head "$GENERATED_BRANCH_NAME" --state open --json number --jq '.[0].number')
52+
if [ -n "$OPEN_PR" ]; then
53+
echo "open_pr=true" >> $GITHUB_OUTPUT
54+
echo "open_pr_number=$OPEN_PR" >> $GITHUB_OUTPUT
55+
echo "📬 Open PR #$OPEN_PR found for branch $GENERATED_BRANCH_NAME."
56+
else
57+
echo "open_pr=false" >> $GITHUB_OUTPUT
58+
echo "📭 No open PR found for branch $GENERATED_BRANCH_NAME."
59+
fi
60+
61+
- name: Make script executable
62+
run: chmod +x ./generate-cookiecutter-template-from-example-project.sh
63+
64+
- name: Generate cookiecutter template
65+
run: ./generate-cookiecutter-template-from-example-project.sh
66+
67+
- name: Copy generated template to {{cookiecutter.app_name}}
68+
run: |
69+
rsync -a --delete --exclude='.git' ./example-template/ ./{{cookiecutter.app_name}}/
70+
71+
- name: Commit and push changes
72+
id: commit
73+
run: |
74+
git add .
75+
if git diff --cached --quiet; then
76+
echo "no_changes=true" >> $GITHUB_OUTPUT
77+
echo "✅ No changes detected."
78+
else
79+
git commit -m "ci: update generated cookiecutter template from example"
80+
git push origin $GENERATED_BRANCH_NAME
81+
echo "no_changes=false" >> $GITHUB_OUTPUT
82+
fi
83+
84+
- name: Create or update Pull Request
85+
if: steps.commit.outputs.no_changes == 'false' && steps.check_branch_pr.outputs.open_pr == 'false'
86+
env:
87+
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
88+
run: |
89+
gh pr create \
90+
--base main \
91+
--head $GENERATED_BRANCH_NAME \
92+
--title "ci: update generated cookiecutter template from example" \
93+
--body "Automated PR created by workflow."

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*.iml
44

55
## Generated projects
6-
# The generated project from scaffold-code-from-example.sh
7-
example-tryout
6+
# The generated project from generate-cookiecutter-template-from-example-project.sh
7+
example-template
88
# The generated project from cookiecutter
99
cart-service
1010

example/pom.xml

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<jib-maven.plugin.version>3.4.6</jib-maven.plugin.version>
3232
<git-code-format-maven-plugin.version>5.4</git-code-format-maven-plugin.version>
3333
<githook-maven-plugin.version>1.0.5</githook-maven-plugin.version>
34-
<pitest-maven-plugin.version>1.20.5</pitest-maven-plugin.version>
34+
<pitest-maven-plugin.version>1.21.0</pitest-maven-plugin.version>
3535
<pitest-junit5-plugin.version>1.2.3</pitest-junit5-plugin.version>
3636
</properties>
3737
<modules>
@@ -207,36 +207,6 @@
207207
</execution>
208208
</executions>
209209
</plugin>
210-
<plugin>
211-
<groupId>com.cosium.code</groupId>
212-
<artifactId>git-code-format-maven-plugin</artifactId>
213-
<version>${git-code-format-maven-plugin.version}</version>
214-
<executions>
215-
<!-- On commit, format the modified java files -->
216-
<execution>
217-
<id>install-formatter-hook</id>
218-
<goals>
219-
<goal>install-hooks</goal>
220-
</goals>
221-
</execution>
222-
<!-- On Maven verify phase, fail if any file
223-
(including unmodified) is badly formatted -->
224-
<execution>
225-
<id>validate-code-format</id>
226-
<goals>
227-
<goal>validate-code-format</goal>
228-
</goals>
229-
</execution>
230-
</executions>
231-
<dependencies>
232-
<!-- Enable https://github.com/google/google-java-format -->
233-
<dependency>
234-
<groupId>com.cosium.code</groupId>
235-
<artifactId>google-java-format</artifactId>
236-
<version>${git-code-format-maven-plugin.version}</version>
237-
</dependency>
238-
</dependencies>
239-
</plugin>
240210
<plugin>
241211
<groupId>io.github.phillipuniverse</groupId>
242212
<artifactId>githook-maven-plugin</artifactId>
@@ -251,10 +221,6 @@
251221
<pre-commit>
252222
echo "Validating..."
253223
exec mvn test
254-
echo "Formatting code..."
255-
exec mvn git-code-format:format-code
256-
echo "Validating format..."
257-
exec mvn git-code-format:validate-code-format
258224
</pre-commit>
259225
</hooks>
260226
</configuration>

generate-cookiecutter-template-from-example-project.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/bash
22
# This script is used to rename files and directories in the example project to that of the cookiecutter template.
33

4-
# Remove previous example-tryout directory if it exists
5-
if [ -d "example-tryout" ]; then
6-
rm -rf "example-tryout"
4+
# Remove previous example-template directory if it exists
5+
if [ -d "example-template" ]; then
6+
rm -rf "example-template"
77
fi
8-
# Create a new example-tryout directory and copy the example project into it
9-
mkdir "example-tryout"
10-
rsync -a ./example/ ./example-tryout/
11-
cd ./example-tryout
8+
# Create a new example-template directory and copy the example project into it
9+
mkdir "example-template"
10+
rsync -a ./example/ ./example-template/
11+
cd ./example-template
1212

1313
# sets the locale for all commands run in the current shell session to the "C" locale, which is the default POSIX locale. This makes programs like sed and find treat files as raw bytes, ignoring any character encoding issues. It helps avoid errors like illegal byte sequence when processing files with mixed or unknown encodings.
1414
export LC_ALL=C

0 commit comments

Comments
 (0)