Skip to content

Apply Library Repo Templates and Create PR #60

Apply Library Repo Templates and Create PR

Apply Library Repo Templates and Create PR #60

name: Apply Library Repo Templates and Create PR
on:
workflow_dispatch:
inputs:
template_type:
description: 'Select the type of template to apply to the target repository.'
default: 'Generated Connector Template (Standard)'
type: choice
options:
- Generated Connector Template (Standard)
target_repo:
description: 'The repository where the selected template will be applied.'
required: true
example: 'module-ballerinax-openai.chat'
module_name:
description: 'The module name as defined in the Ballerina.toml file.'
required: true
example: 'openai.chat'
ballerina_version:
description: 'The Ballerina version that the library should be compatible with.'
required: true
example: '2201.9.0'
module_version:
description: 'The version number of the library module.'
required: true
default: '0.1.0'
example: '1.0.0'
target_branch:
description: 'The branch in the target repository where changes will be applied.'
required: false
default: 'main'
library_name:
description: 'A descriptive name for the library, used in the documentation. If not provided, the module name will be used instead.'
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: Fork the target repository
run: gh repo fork ballerina-platform/${{ github.event.inputs.target_repo }} --remote
env:
GH_TOKEN: ${{ secrets.BALLERINA_BOT_TOKEN }}
- name: Checkout target repository
uses: actions/checkout@v3
with:
repository: ballerina-bot/${{ 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 }}
working-directory: ./target-repo
run: |
gh pr create \
--repo ballerina-platform/${{ github.event.inputs.target_repo }} \
--base ${{ github.event.inputs.target_branch }} \
--title "Add ${{ github.event.inputs.template_type }}" \
--body "This PR applies ${{ github.event.inputs.template_type }} template to this repository."