name: Custom Deploy IssueOps
on:
issues:
types: [opened, reopened]
jobs:
process_custom_deploy:
# Only run if issue contains our custom ID
if: contains(github.event.issue.body, '"id":"custom-deploy"')
runs-on: ubuntu-latest
steps:
- name: Parse Issue Body
id: parse
uses: actions/github-script@v7
with:
script: |
const body = context.payload.issue.body;
const jsonMatch = body.match(/<!--\s*({[\s\S]*?})\s*-->/);
if (!jsonMatch) {
core.setFailed('No JSON payload found in issue');
return;
}
const payload = JSON.parse(jsonMatch[1]);
// Validate required fields
if (payload.id !== 'custom-deploy') {
core.setFailed('Not a custom-deploy request');
return;
}
if (!payload.version || !payload.environment) {
core.setFailed('Missing required fields: version and environment');
return;
}
// Set outputs for next steps
core.setOutput('version', payload.version);
core.setOutput('environment', payload.environment);
core.setOutput('branch', payload.branch || 'main');
- name: Post Processing Comment
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `🔄 Processing deployment request:
- Version: ${{ steps.parse.outputs.version }}
- Environment: ${{ steps.parse.outputs.environment }}
- Branch: ${{ steps.parse.outputs.branch }}
Please wait while I deploy...`
});
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ steps.parse.outputs.branch }}
- name: Authenticate to Salesforce
uses: flxbl-io/sfops-gh-actions/auth-hybrid@main
with:
environment: ${{ steps.parse.outputs.environment }}
- name: Deploy Version
id: deploy
run: |
# Your deployment logic here
echo "Deploying version ${{ steps.parse.outputs.version }}"
# Example: Deploy using sfp
sfp release \
--targetorg ${{ steps.parse.outputs.environment }} \
--releasedefn ${{ steps.parse.outputs.version }}
- name: Post Success Comment
if: success()
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `✅ Deployment completed successfully!
**Deployment Details:**
- Version: ${{ steps.parse.outputs.version }}
- Environment: ${{ steps.parse.outputs.environment }}
- Status: Success
- Time: ${new Date().toISOString()}
You can now access the environment and verify the deployment.`
});
// Close the issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed'
});
- name: Post Error Comment
if: failure()
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `❌ Deployment failed!
Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
You may need to:
- Verify the version exists
- Check environment permissions
- Review any validation errors`
});