-
Notifications
You must be signed in to change notification settings - Fork 4
130 lines (117 loc) · 6.95 KB
/
deploy-plugin-pr.yml
File metadata and controls
130 lines (117 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Deploy Plugin (PR)
on:
workflow_dispatch:
inputs:
prNumber:
description: 'Pull Request Number'
required: true
type: number
jobs:
Deploy_Plugin:
runs-on: ubuntu-latest
steps:
- name: Get Plugin Path and PR Info
run: |
$prNumber = "${{ github.event.inputs.prNumber }}"
$repository = "${{ github.repository }}"
# Get PR info
$url = "https://api.github.com/repos/$repository/pulls/$prNumber"
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "token ${{ secrets.GITHUB_TOKEN }}" }
# Get changed files in the PR
$filesUrl = $response.url + "/files?per_page=100"
$files = Invoke-RestMethod -Uri $filesUrl -Headers @{Authorization = "token ${{ secrets.GITHUB_TOKEN }}" }
Write-Output "Total files changed: $($files.Count)"
Write-Output "All changed files: $($files.filename -join ', ')"
# Find plugin changes
$pluginChanges = $files | Where-Object { $_.filename -like "plugins/*" } | Select-Object -ExpandProperty filename
Write-Output "Plugin files changed: $($pluginChanges -join ', ')"
if ($pluginChanges) {
$pattern = '(?<=\/[v][0-9]\/).*'
$pluginToDeploy = $pluginChanges -replace $pattern | Sort-Object -Unique | Select-Object -Last 1
$pluginToDeploy = $pluginToDeploy.TrimStart("plugins/").TrimEnd("/")
Write-Output "Plugin to Deploy: $pluginToDeploy"
Write-Output "PLUGIN_PATH=$pluginToDeploy" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# Get PR repo and branch info
$repoUrl = $response.head.repo.html_url + ".git"
$branchName = $response.head.ref
Write-Output "Repo URL: $repoUrl | Branch Name: $branchName"
Write-Output "PR_REPO_URL=$repoUrl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "PR_BRANCH_NAME=$branchName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# Get tenant info from PR body
$repoBody = gh pr view $prNumber --json body --jq '.body' --repo $repository
Write-Output "Repo Body: $repoBody"
$tenantLine = $repoBody | Select-String -Pattern "^Tenant to Deploy to:.*"
Write-Output "Tenant Line: $tenantLine"
if ($tenantLine) {
$tenant = $tenantLine -replace "Tenant to Deploy to:\s*", "" -replace "\s*$", ""
if (-not [string]::IsNullOrWhiteSpace($tenant)) {
Write-Output "Tenant to Deploy to: $tenant"
Write-Output "TENANT_TO_RESTRICT_TO=$tenant" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
} else {
Write-Error "Error: 'Tenant to Deploy to' is blank."
exit 1
}
} else {
Write-Error "Error: 'Tenant to Deploy to' field not found."
exit 1
}
} else {
Write-Output "No plugin changes found - skipping deployment"
Write-Output "SKIP_DEPLOYMENT=true" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
shell: pwsh
timeout-minutes: 10
env:
GH_TOKEN: ${{ github.token }}
- run: |
Write-Output "Deploying Plugin..."
$pluginSuffix = "${{ github.event.inputs.prNumber }}"
$pluginPath = "${{ env.PLUGIN_PATH }}"
$tenantToRestrictTo = "${{ env.TENANT_TO_RESTRICT_TO }}"
$repoUrl = "${{ env.PR_REPO_URL }}"
$branchName = "${{ env.PR_BRANCH_NAME }}"
Write-Output "Deploying Plugin with suffix $pluginSuffix from $pluginPath to $tenantToRestrictTo tenant..."
Write-Output "Repo URL: $repoUrl | Branch Name: $branchName"
try {
Write-Output "Queueing deployment..."
$requestBody = @{
branchName = $branchName
customerRelease = $false
pluginPath = $pluginPath
pluginSuffix = $pluginSuffix
repositoryURL = $repoUrl
tenantToDeployTo = $tenantToRestrictTo
deploymentRequestedBy = "${{ github.actor }}"
} | ConvertTo-Json
Write-Output "Request Body: $requestBody"
$deployerUrl = "${{ secrets.DEPLOYER_BASE_URL }}/queuedeployment"
Write-Output "Deployer URL: $deployerUrl"
$authHeader = "Bearer ${{ secrets.DEPLOYER_API_KEY }}"
$response = Invoke-RestMethod -Uri $deployerUrl -Method Post -Headers @{Authorization=$authHeader} -Body $requestBody -ContentType "application/json"
Write-Output "Deployment request sent successfully"
Write-Output "Deployment ID: $($response.buildId)"
} catch {
Write-Output "Failed to deploy plugin"
Write-Output "Error: $($_.Exception.Message)"
$errMessage = $_.ErrorDetails.Message | ConvertFrom-Json
Write-Output "Error Message: $($errMessage.message)"
exit 1
}
shell: pwsh
name: Deploy Plugin
if: ${{ env.SKIP_DEPLOYMENT != 'true' }}
timeout-minutes: 30
env:
DEPLOYER_BASE_URL: ${{ secrets.DEPLOYER_BASE_URL }}
DEPLOYER_API_KEY: ${{ secrets.DEPLOYER_API_KEY }}
- name: Add deployment summary
run: |
echo "## 🚀 Plugin Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "- **Plugin:** ${{ env.PLUGIN_PATH }}" >> $GITHUB_STEP_SUMMARY
echo "- **PR:** #${{ github.event.inputs.prNumber }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tenant:** ${{ env.TENANT_TO_RESTRICT_TO }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch:** ${{ env.PR_BRANCH_NAME }}" >> $GITHUB_STEP_SUMMARY
echo "- **Repository:** ${{ env.PR_REPO_URL }}" >> $GITHUB_STEP_SUMMARY
echo "- **Requested by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
if: ${{ env.SKIP_DEPLOYMENT != 'true' }}
shell: bash