A custom workflow extension for WSO2 API Manager that triggers GitHub Actions workflows when APIs are promoted through the lifecycle. This extension integrates with the API Manager's lifecycle management system to automatically trigger CI/CD pipelines when APIs transition to "Promoted" state.
This project implements a custom workflow executor that extends APIStateChangeSimpleWorkflowExecutor to intercept API lifecycle state transitions. When an API is promoted from "Published" to "Promoted" state, the workflow executor triggers a GitHub Actions workflow using the GitHub API.
- Lifecycle Integration: Hooks into WSO2 API Manager's lifecycle transitions
- GitHub Actions Integration: Automatically triggers GitHub workflows on API promotion
- Configurable Parameters: Supports configuration of GitHub repository, workflow file, and authentication
- Error Handling: Comprehensive error handling with logging for troubleshooting
- Java 1.8 with Maven build system
- **WSO2 API Manager 4.x (this was tested with 4.5)
- JUnit 4.11 for testing
- Apache HTTP Client for GitHub API integration
lifecycle_demo/
├── lifecycle/ # Main Maven project
│ ├── src/main/java/
│ │ └── com/example/wso2/
│ │ └── PromoteWorkflowExecutor.java
│ ├── src/test/java/
│ └── pom.xml
├── workflow_definition/ # WSO2 configuration files
│ └── workflow_extensions_template.xml
├── lifecycle.json # API lifecycle definition
└── README.md
- Java 1.8 or higher
- Maven 3.6+
- WSO2 API Manager 4.x (this was tested with 4.5)
- Access to GitHub repository for workflow triggers
All build commands should be executed from the lifecycle/ directory:
cd lifecycle/
# Compile the project
mvn clean compile
# Run tests
mvn test
# Create JAR package
mvn package
# Full build and install
mvn clean installThe build creates: target/promote-workflows-1.0-SNAPSHOT.jar
Connection to Github requires the following information:
githubToken: GitHub Personal Access Token withrepoandactionsscopesgithubOwner: GitHub username or organization namegithubRepo: Repository name containing the workflowworkflowFileName: Name of the GitHub Actions workflow file (e.g.,deploy.yml)
-
Copy the JAR file to WSO2 API Manager:
cp lifecycle/target/promote-workflows-1.0-SNAPSHOT.jar <APIM_HOME>/repository/components/lib/
-
Configure workflows through the WSO2 registry:
a. Access Management Console:
- Navigate to
https://<Server Host>:9443/carbon - Sign in with administrator credentials
b. Navigate to Workflow Extensions:
- Go to Resources → Browse
- Navigate to
/_system/governance/apimgt/applicationdata/workflow-extensions.xml
c. Configure Custom Workflow:
- Click Edit as text
- Replace the default
APIStateChangeconfiguration with:
<APIStateChange executor="com.example.wso2.PromoteWorkflowExecutor"> <Property name="githubToken">YOUR_GITHUB_TOKEN</Property> <Property name="githubOwner">YOUR_GITHUB_USERNAME</Property> <Property name="githubRepo">YOUR_REPOSITORY_NAME</Property> <Property name="workflowFileName">YOUR_WORKFLOW_FILE.yml</Property> </APIStateChange>
d. Save and Restart:
- Save the configuration
- Restart the WSO2 API Manager server
- Navigate to
The project includes a custom lifecycle configuration in lifecycle.json that defines the API states and transitions:
- Created → Pre-Released → Published → Promoted → Deprecated → Retired
The workflow executor triggers when transitioning from Published to Promoted state.
You need to follow instructions here to configure the lifecycle: https://apim.docs.wso2.com/en/latest/manage-apis/design/lifecycle-management/customize-api-life-cycle/
Note: the file as reference is in JSON format to help format/edit, the outer {} must be removed before you paste it in the UI.
Create a GitHub Actions workflow file in your repository (e.g., .github/workflows/api-promote.yml):
name: API Promotion Workflow
on:
workflow_dispatch:
inputs:
apiName:
description: 'Name of the API being promoted'
required: true
apiVersion:
description: 'Version of the API being promoted'
required: true
jobs:
promote:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Process API Promotion
run: |
echo "Processing promotion for API: ${{ github.event.inputs.apiName }}"
echo "API Version: ${{ github.event.inputs.apiVersion }}"
# Add your custom promotion logic here-
Deploy the Extension:
- Build and deploy the JAR file to WSO2 API Manager
- Configure the workflow extension in the registry
-
Create an API:
- Use the API Manager Publisher to create a new API
- Progress through the lifecycle states: Created → Pre-Released → Published
-
Promote the API:
- In the API Publisher, click Lifecycle tab
- Click Promote button
- The custom workflow executor will trigger the GitHub Actions workflow
-
Monitor Execution:
- Check WSO2 API Manager logs for workflow execution details
- Monitor GitHub Actions workflow execution in your repository
-
JAR not found:
- Ensure the JAR file is in
<APIM_HOME>/repository/components/lib/ - Restart the WSO2 API Manager server
- Ensure the JAR file is in
-
GitHub API authentication failed:
- Verify the GitHub token has correct permissions (
repo,actions) - Check that the token is not expired
- Verify the GitHub token has correct permissions (
-
Workflow not triggered:
- Verify the workflow extension configuration in the registry
- Check that the executor class name is correct:
com.example.wso2.PromoteWorkflowExecutor
-
GitHub workflow not found:
- Ensure the workflow file exists in
.github/workflows/directory - Verify the
workflowFileNameproperty matches the actual file name
- Ensure the workflow file exists in
Monitor the following log files for debugging:
<APIM_HOME>/repository/logs/wso2carbon.log<APIM_HOME>/repository/logs/http_access.log
Look for log entries from com.example.wso2.PromoteWorkflowExecutor class.
- Token Security: Store GitHub tokens securely and rotate them regularly
- Network Security: Ensure WSO2 API Manager can reach GitHub API (https://api.github.com)
- Access Control: Use principle of least privilege for GitHub token permissions
To extend the workflow executor for other lifecycle transitions:
- Modify the condition in
PromoteWorkflowExecutor.java:47 - Add additional logic for different
lcActionvalues - Rebuild and redeploy the JAR file
Run unit tests:
cd lifecycle/
mvn testAdd integration tests in src/test/java/com/example/ directory.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For issues related to:
- WSO2 API Manager: Consult WSO2 Documentation
- GitHub Actions: Check GitHub Actions Documentation
- This Extension: Create an issue in this repository