ci: split the workflows - #60
Conversation
There was a problem hiding this comment.
Pull Request Overview
Splits CI into separate workflows to avoid using PAT_TOKEN and enable manually triggered template generation, while adjusting CI to verify builds and adding a template-based CI path.
- Introduces a manual "Generate Template" workflow to create a branch, generate from example, push changes, and open a PR using GITHUB_TOKEN.
- Removes in-CI template generation from the main CI workflow and switches Maven phase to verify.
- Adds a separate workflow to generate a project from the template and run CI against the generated app.
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| generate-cookiecutter-template-from-example-project.sh | Renames working directory from example-tryout to example-template to align with new workflows. |
| .github/workflows/generate-template.yaml | New manual workflow to generate template, push a branch, and auto-create a PR. |
| .github/workflows/ci.yaml | Simplifies CI to run mvn verify and removes template generation job. |
| .github/workflows/ci-from-template.yaml | New workflow to generate from cookiecutter and run CI on the generated project. |
| .github/dependabot.yml | Updates reviewers to a team. |
| branches: | ||
| - main | ||
| jobs: | ||
| generate-template: |
There was a problem hiding this comment.
workflow_dispatch does not support a branches filter. Remove the branches block; if you need to restrict execution to main, gate the job with a condition like if: github.ref == 'refs/heads/main'.
| branches: | |
| - main | |
| jobs: | |
| generate-template: | |
| jobs: | |
| generate-template: | |
| if: github.ref == 'refs/heads/main' |
| - name: Create new branch | ||
| id: create_branch | ||
| run: | | ||
| # create unique branch name starting with "generated-template" |
There was a problem hiding this comment.
Comment and implementation are inconsistent: the comment says the prefix is generated-template, but the code uses template-. Update the comment or the branch prefix for consistency.
| # create unique branch name starting with "generated-template" | |
| # create unique branch name starting with "template-" |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| - 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 |
There was a problem hiding this comment.
The create-pull-request action will not open a PR if there are no uncommitted changes at this step (you already committed and pushed earlier), so this step can silently do nothing. Replace this with a PR-creation step that opens a PR for an already-pushed branch (for example, actions/github-script calling pulls.create, or gh pr create), or let peter-evans/create-pull-request handle both committing and PR creation by removing the prior manual git commit/push.
| @@ -0,0 +1,54 @@ | |||
| name: Generate Template | |||
| on: | |||
| workflow_dispatch: | |||
There was a problem hiding this comment.
This workflow pushes a branch and creates a PR using GITHUB_TOKEN but does not declare explicit permissions. Add a top-level permissions block (contents: write and pull-requests: write) to ensure the token has sufficient rights across all repo/org settings.
| workflow_dispatch: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write |
| - 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 |
There was a problem hiding this comment.
[nitpick] "cart-service" is hard-coded; if the app_name in test-config.yml changes, this step will break. Consider centralizing the generated directory name in a single workflow env var (kept in sync with test-config.yml) and reference it here to avoid drift.
| - 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 | |
| - name: Extract generated app name from test-config.yml | |
| id: extract_app_name | |
| run: | | |
| echo "GENERATED_APP_NAME=$(python -c "import yaml; print(yaml.safe_load(open('test-config.yml'))['app_name'])")" >> $GITHUB_ENV | |
| env: | |
| PYTHONPATH: "" | |
| - name: Upload generated app as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.GENERATED_APP_NAME }} | |
| path: ./${{ env.GENERATED_APP_NAME }} | |
| cart-service-ci: | |
| needs: generate-from-template | |
| defaults: | |
| run: | |
| working-directory: ./${{ env.GENERATED_APP_NAME }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download generated cart-service artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ env.GENERATED_APP_NAME }} |
| cart-service-ci: | ||
| needs: generate-from-template | ||
| defaults: | ||
| run: | ||
| working-directory: ./cart-service | ||
| runs-on: ubuntu-latest |
There was a problem hiding this comment.
[nitpick] The job name and working-directory are hard-coded to cart-service; if the generated app_name changes, the job will fail or become misleading. Use a workflow env var (e.g., GENERATED_DIR) for both the job's working-directory and artifact name/path to keep them aligned with test-config.yml.
| @@ -1,14 +1,14 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
[nitpick] Add strict mode to improve robustness and fail fast on errors. For example, place set -euo pipefail immediately after the shebang.
| #!/bin/bash | |
| #!/bin/bash | |
| set -euo pipefail |
| 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 |
There was a problem hiding this comment.
[nitpick] Consider adding -B to Maven commands in CI (non-interactive/batch mode): mvn -B clean verify -ntp. This is a common CI convention that also reduces noise from interactive prompts.
| run: mvn clean verify -ntp | |
| run: mvn -B clean verify -ntp |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
According to github's security we cannot use PAT_TOKEN for workflows. We need to generate the template code from the example and push the changes hence had to split the workflow based on manual trigger
Checklist: