Apply Library Repo Templates and Create PR #17
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
name: Apply Library Repo Templates and Create PR | |
on: | |
workflow_dispatch: | |
inputs: | |
template_type: | |
description: 'Template type' | |
default: 'Generated Connector Template (Standard)' | |
type: choice | |
options: | |
- Generated Connector Template (Standard) | |
target_repo: | |
description: 'Target repository to apply the template' | |
required: true | |
example: 'module-ballerinax-openai.chat' | |
module_name: | |
description: 'Module name of the library used in Ballerina.toml' | |
required: true | |
example: 'openai.chat' | |
ballerina_version: | |
description: 'Compatible Ballerina version to be used for the library' | |
required: true | |
example: '2201.9.0' | |
module_version: | |
description: 'Library module version' | |
required: true | |
default: '0.1.0' | |
example: '1.0.0' | |
target_branch: | |
description: 'Target branch' | |
required: false | |
default: 'main' | |
library_name: | |
description: 'Descriptive name of the library to be used in the documentation (If not provided, module name will be used)' | |
required: false | |
example: 'OpenAI Chat' | |
default: '' | |
jobs: | |
apply_templates: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Print Inputs | |
run: | | |
echo "Template Type: ${{ github.event.inputs.template_type }}" | |
echo "Target Repository: ${{ github.event.inputs.target_repo }}" | |
echo "Module Name: ${{ github.event.inputs.module_name }}" | |
echo "Ballerina Version: ${{ github.event.inputs.ballerina_version }}" | |
echo "Module Version: ${{ github.event.inputs.module_version }}" | |
echo "Target Branch: ${{ github.event.inputs.target_branch }}" | |
echo "Library Name: ${{ github.event.inputs.library_name }}" | |
- name: Checkout template repository | |
uses: actions/checkout@v3 | |
with: | |
path: template-repo | |
- name: Checkout target repository | |
uses: actions/checkout@v3 | |
with: | |
repository: ballerina-platform/${{ github.event.inputs.target_repo }} | |
path: target-repo | |
token: ${{ secrets.BALLERINA_BOT_TOKEN }} | |
- name: Setup Ballerina | |
uses: ballerina-platform/setup-ballerina@v1.1.0 | |
with: | |
version: latest | |
- name: Apply templates and replace placeholders | |
if: ${{ github.event.inputs.template_type }} == 'Generated Connector Template (Standard)' | |
run: | | |
cp -r template-repo/library-templates/generated-connector-template/files/* target-repo/ | |
cd template-repo/library-templates/generated-connector-template/scripts/ | |
bal run replace_placeholders.bal -- ../../../../target-repo/ ${{ github.event.inputs.module_name }} ${{ github.event.inputs.target_repo }} ${{ github.event.inputs.module_version }} ${{ github.event.inputs.ballerina_version }} "${{ github.event.inputs.library_name }}" | |
cd ../../../../target-repo | |
git config user.name "ballerina-bot" | |
git config user.email "ballerina-bot@ballerina.org" | |
git checkout -b apply-templates-${{ github.run_number }} | |
git add . | |
git commit -m "Apply library repo template" | |
git push origin apply-templates-${{ github.run_number }} | |
- name: Create Pull Request | |
env: | |
GITHUB_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }} | |
run: | | |
gh pr create \ | |
--repo ballerina-platform/${{ github.event.inputs.target_repo }} \ | |
--base ${{ github.event.inputs.target_branch }} \ | |
--head apply-templates-${{ github.run_number }} \ | |
--title "Add ${{ github.event.inputs.template_type }}" \ | |
--body "This PR applies ${{ github.event.inputs.template_type }} template to this repository." |