-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from luisfalconmx/main
Pull Request Support and New Configuration Inputs
- Loading branch information
Showing
3 changed files
with
183 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,10 @@ To overcome this limitation, and help developers such as myself automate this te | |
| `FILES` | list of files that should be compiled. | `false` | ||
| `DELIMITER` | you can change the default **DELIMITER** if it causes issue with your data. | `${{ }}` | ||
| `GLOBAL_TEMPLATE_REPOSITORY` | you can set a global repository template where all the files are stored. | `false` | ||
| `committer_name` | Specify the committer name | `Dynamic Readme` | | ||
| `committer_email` | Specify the committer email | `[email protected]` | | ||
| `commit_message` | set a custom commit message | `💬 - File Rebuilt - Github Action Runner : ${GITHUB_RUN_NUMBER}` | | ||
| `confirm_and_push` | Commit the changes and push directly to repository | `true` | | ||
<!-- END RAW_CONTENT --> | ||
|
||
## :writing_hand: Syntax | ||
|
@@ -143,6 +147,54 @@ Reusable Includes Custom Markdown : | |
> | ||
> :information_source: Even though **Reusable includes** and **Inline Includes** do the same work, they can come in handy when you are generating a template and saving it in the same file. It preserves the include comment which will be parsed again when re-generating the template, and the contents of the include will be updated accordingly. | ||
### Pull Request Support | ||
|
||
This action modifies the files, creates a commit and uploads them directly to the default branch of the repository. | ||
|
||
If the default branch of the repository is protected by the rule `Require a pull request before merging` then you will need to set the option `confirm_and_push: false` so that the commit is not made and the changes are not uploaded to the default branch. | ||
|
||
``` yaml | ||
- name: "💫 Dynamic Template Render" | ||
uses: varunsridharan/action-dynamic-readme@main | ||
with: | ||
GLOBAL_TEMPLATE_REPOSITORY: {repository-owner}/{repository-name} | ||
files: | | ||
FILE.md | ||
FILE2.md=output_filename.md | ||
folder1/file.md=folder2/output.md | ||
confirm_and_push: false # Important if use "Require a pull request before merging" rule | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
``` | ||
In addition to the previous configuration, it is necessary to use other actions to be able to confirm the changes and generate a Pull Request towards the default branch | ||
``` yaml | ||
- name: "📥 Fetching Repository Contents" | ||
uses: actions/checkout@main | ||
|
||
- name: "💫 Dynamic Template Render" | ||
uses: varunsridharan/action-dynamic-readme@main | ||
with: | ||
GLOBAL_TEMPLATE_REPOSITORY: {repository-owner}/{repository-name} | ||
files: | | ||
FILE.md | ||
FILE2.md=output_filename.md | ||
folder1/file.md=folder2/output.md | ||
confirm_and_push: false # Important if use "Require a pull request before merging" rule | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create pull request | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
``` | ||
Thanks to this configuration, the necessary files can be dynamically generated by adding them to a different branch that then we can merge with the default branch, complying with the rule `Require a pull request before merging`. | ||
|
||
Check out the example workflow (Pull Request Support) for a more advanced configuration | ||
|
||
--- | ||
|
||
<h3 align="center"> For live Demo Please Check <a href="https://github.com/varunsridharan/demo-dynamic-readme">Demo Repository</a> </h3> | ||
|
@@ -187,6 +239,80 @@ jobs: | |
|
||
<!-- END RAW_CONTENT --> | ||
|
||
## 🚀 Example Workflow File (Pull Request Support) | ||
|
||
<!-- START RAW_CONTENT --> | ||
```yaml | ||
name: Dynamic Template | ||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
jobs: | ||
update_templates: | ||
name: "Update Templates" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "📥 Fetching Repository Contents" | ||
uses: actions/checkout@main | ||
- name: "💾 Github Repository Metadata" | ||
uses: varunsridharan/action-repository-meta@main | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: "💫 Dynamic Template Render" | ||
uses: varunsridharan/action-dynamic-readme@main | ||
with: | ||
GLOBAL_TEMPLATE_REPOSITORY: {repository-owner}/{repository-name} | ||
files: | | ||
FILE.md | ||
FILE2.md=output_filename.md | ||
folder1/file.md=folder2/output.md | ||
committer_name: github-actions[bot] | ||
committer_email: github-actions[bot]@users.noreply.github.com | ||
commit_message: 'docs: update readme file [skip ci]' | ||
confirm_and_push: false | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Create pull request | ||
id: cpr | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: 'docs: documentation files updated [skip ci]' | ||
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | ||
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | ||
signoff: false | ||
branch: github-actions/repository-maintenance | ||
delete-branch: true | ||
title: Update documentation files | ||
body: All documentation files has been updated to last recent version | ||
labels: | | ||
skip-changelog | ||
docs | ||
- name: Enable pull request automerge | ||
if: steps.cpr.outputs.pull-request-operation == 'created' | ||
uses: peter-evans/enable-pull-request-automerge@v1 | ||
with: | ||
token: ${{ secrets.PAT }} | ||
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} | ||
- name: Auto approve | ||
if: steps.cpr.outputs.pull-request-operation == 'created' | ||
uses: juliangruber/approve-pull-request-action@v1 | ||
with: | ||
github-token: ${{ secrets.PAT }} | ||
number: ${{ steps.cpr.outputs.pull-request-number }} | ||
``` | ||
|
||
<!-- END RAW_CONTENT --> | ||
|
||
--- | ||
|
||
<!-- START common-footer.mustache --> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,59 @@ | ||
name: 'Dynamic Readme' | ||
name: "Dynamic Readme" | ||
|
||
description: 'Convert Static Readme into Dynamic Readme' | ||
description: "Convert Static Readme into Dynamic Readme" | ||
|
||
author: 'varunsridharan' | ||
author: "varunsridharan" | ||
|
||
branding: | ||
icon: 'book-open' | ||
color: 'orange' | ||
icon: "book-open" | ||
color: "orange" | ||
|
||
inputs: | ||
files: | ||
description: 'Enter Multiple by , seperated' | ||
description: "Enter Multiple by , seperated" | ||
default: false | ||
required: true | ||
|
||
delimiter: | ||
description: 'Delimiter which can be used to identify the template tags ' | ||
default: '' | ||
description: "Delimiter which can be used to identify the template tags " | ||
default: "" | ||
required: false | ||
|
||
template_engine: | ||
description: 'Compiles the template files with provided template engine.' | ||
default: 'mustache' | ||
description: "Compiles the template files with provided template engine." | ||
default: "mustache" | ||
required: false | ||
|
||
global_template_repository: | ||
description: 'You Can Provide A Global Repository Where All Your Common Files Are Stored' | ||
description: "You Can Provide A Global Repository Where All Your Common Files Are Stored" | ||
default: false | ||
required: false | ||
|
||
committer_name: | ||
description: "Specify the committer name" | ||
default: Dynamic Readme | ||
required: false | ||
|
||
committer_email: | ||
description: "Specify the committer email" | ||
default: [email protected] | ||
required: false | ||
|
||
commit_message: | ||
description: "set a custom commit message" | ||
default: "💬 - File Rebuilt - Github Action Runner : ${GITHUB_RUN_NUMBER}" | ||
required: false | ||
|
||
confirm_and_push: | ||
description: "Commit the changes and push directly to repository" | ||
default: true | ||
required: false | ||
|
||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
using: "docker" | ||
image: "Dockerfile" | ||
args: | ||
- ${{ inputs.files }} | ||
- ${{ inputs.delimiter }} | ||
- ${{ inputs.template_engine }} | ||
- ${{ inputs.global_template_repository }} | ||
- ${{ inputs.global_template_repository }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,12 @@ source /gh-toolkit/shell.sh | |
|
||
gh_log "" | ||
|
||
gitconfig "Dynamic Readme" "[email protected]" | ||
CONFIRM_AND_PUSH=$(gh_input "CONFIRM_AND_PUSH") | ||
|
||
COMMITTER_NAME=$(gh_input "COMMITTER_NAME") | ||
COMMITTER_EMAIL=$(gh_input "COMMITTER_EMAIL") | ||
|
||
gitconfig "$COMMITTER_NAME" "$COMMITTER_EMAIL" | ||
|
||
gh_validate_input "FILES" "FILES List is required" | ||
|
||
|
@@ -51,15 +56,25 @@ for FILE in "${FILES[@]}"; do | |
php /dynamic-readme/app.php "${SRC_FILE}" "${DEST_FILE}" | ||
gh_log "" | ||
|
||
git add "${GITHUB_WORKSPACE}/${DEST_FILE}" -f | ||
if [ "$CONFIRM_AND_PUSH" == true ]; then | ||
gh_log "🚀 Confirm and push is the strategy used" | ||
|
||
if [ "$(git status --porcelain)" != "" ]; then | ||
git commit -m "💬 - File Rebuilt | Github Action Runner : ${GITHUB_RUN_NUMBER}" | ||
else | ||
gh_log " ✅ No Changes Are Done : ${SRC_FILE}" | ||
git add "${GITHUB_WORKSPACE}/${DEST_FILE}" -f | ||
|
||
if [ "$(git status --porcelain)" != "" ]; then | ||
COMMIT_MESSAGE=$(gh_input "COMMIT_MESSAGE") | ||
git commit -m "$COMMIT_MESSAGE" | ||
else | ||
gh_log " ✅ No Changes Are Done : ${SRC_FILE}" | ||
fi | ||
fi | ||
|
||
gh_log_group_end | ||
done | ||
gh_log "" | ||
git push $GIT_URL | ||
gh_log "" | ||
|
||
if [ "$CONFIRM_AND_PUSH" == true ]; then | ||
git push $GIT_URL | ||
fi | ||
|
||
gh_log "" |