diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0cb2926..037859f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,4 +8,4 @@ updates: time: "23:30" open-pull-requests-limit: 10 reviewers: - - paul58914080 \ No newline at end of file + - devs-from-matrix/app-generator-team \ No newline at end of file diff --git a/.github/workflows/ci-from-template.yaml b/.github/workflows/ci-from-template.yaml new file mode 100644 index 0000000..93c173a --- /dev/null +++ b/.github/workflows/ci-from-template.yaml @@ -0,0 +1,61 @@ +name: Continuous Integration From Template +on: + pull_request: + branches: + - main + paths: + - '{{cookiecutter.app_name}}/**' + workflow_dispatch: +jobs: + generate-from-template: + runs-on: ubuntu-latest + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + # checkout the pull request head ref when available, otherwise fallback to the workflow ref + ref: ${{ github.head_ref || github.ref }} + token: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + - name: Install cookiecutter + run: | + pip install --upgrade pip cookiecutter + - name: Generate from default context (cookiecutter.json) + run: | + # Generate using the config file test-config.yml from the repo root. + # Use the repo root as the template directory (.) and overwrite any existing generated output. + cookiecutter --no-input --config-file test-config.yml --overwrite-if-exists --output-dir . . + - name: Upload generated cart-service as artifact + uses: actions/upload-artifact@v4 + with: + name: cart-service + path: ./cart-service + cart-service-ci: + needs: generate-from-template + defaults: + run: + working-directory: ./cart-service + runs-on: ubuntu-latest + steps: + - name: Download generated cart-service artifact + uses: actions/download-artifact@v4 + with: + name: cart-service + path: . + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + - name: Cache Maven dependencies + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Build with Maven + run: mvn clean verify -ntp diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 98b23ae..2f3a1a5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,28 +29,4 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - name: Build with Maven - run: mvn clean install -ntp - - name: Clean up - run: mvn clean - generate-template: - needs: example-ci - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - token: ${{ secrets.PAT_TOKEN }} - - name: Make script executable - run: chmod +x ./generate-cookiecutter-template-from-example-project.sh - - name: Generate cookiecutter template - run: ./generate-cookiecutter-template-from-example-project.sh - - name: Copy generated template to {{cookiecutter.app_name}} - run: | - rsync -a --delete --exclude='.git' ./example-tryout/ ./{{cookiecutter.app_name}}/ - - name: Commit & push generated changes - run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git add . - git diff --cached --quiet || git commit -m "ci: update generated cookiecutter template from example" - git push origin ${{ github.head_ref }} + run: mvn clean verify -ntp diff --git a/.github/workflows/generate-template.yaml b/.github/workflows/generate-template.yaml new file mode 100644 index 0000000..7cdb878 --- /dev/null +++ b/.github/workflows/generate-template.yaml @@ -0,0 +1,54 @@ +name: Generate Template +on: + workflow_dispatch: +jobs: + generate-template: + runs-on: ubuntu-latest + steps: + - name: Checkout main + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + - name: Create new branch + id: create_branch + run: | + # create unique branch name starting with "generated-template" + BRANCH="template-$(date +%Y%m%d%H%M%S)" + echo "branch=${BRANCH}" >> $GITHUB_OUTPUT + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + git checkout -b "${BRANCH}" + git push --set-upstream origin "${BRANCH}" + - name: Ensure working on created branch + run: | + git fetch origin + git checkout "${{ steps.create_branch.outputs.branch }}" + - name: Make script executable + run: chmod +x ./generate-cookiecutter-template-from-example-project.sh + - name: Generate cookiecutter template + run: ./generate-cookiecutter-template-from-example-project.sh + - name: Copy generated template to {{cookiecutter.app_name}} + run: | + rsync -a --delete --exclude='.git' ./example-template/ ./{{cookiecutter.app_name}}/ + - name: Commit & push generated changes + env: + BRANCH: ${{ steps.create_branch.outputs.branch }} + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add . + git diff --cached --quiet || git commit -m "ci: update generated cookiecutter template from example" + git push origin "${BRANCH}" + - name: Create Pull Request + id: create_pr + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + base: main + branch: ${{ steps.create_branch.outputs.branch }} + title: "ci: update generated cookiecutter template from example" + body: | + This PR was created automatically by the Generate Template workflow. + Contains updates generated from the example project. + labels: automated-pr diff --git a/.gitignore b/.gitignore index c698b83..be2f91d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,8 @@ *.iml ## Generated projects -# The generated project from scaffold-code-from-example.sh -example-tryout +# The generated project from generate-cookiecutter-template-from-example-project.sh +example-template # The generated project from cookiecutter cart-service diff --git a/generate-cookiecutter-template-from-example-project.sh b/generate-cookiecutter-template-from-example-project.sh index 51538f3..719b1ea 100755 --- a/generate-cookiecutter-template-from-example-project.sh +++ b/generate-cookiecutter-template-from-example-project.sh @@ -1,14 +1,14 @@ #!/bin/bash # This script is used to rename files and directories in the example project to that of the cookiecutter template. -# Remove previous example-tryout directory if it exists -if [ -d "example-tryout" ]; then - rm -rf "example-tryout" +# Remove previous example-template directory if it exists +if [ -d "example-template" ]; then + rm -rf "example-template" fi -# Create a new example-tryout directory and copy the example project into it -mkdir "example-tryout" -rsync -a ./example/ ./example-tryout/ -cd ./example-tryout +# Create a new example-template directory and copy the example project into it +mkdir "example-template" +rsync -a ./example/ ./example-template/ +cd ./example-template # 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. export LC_ALL=C