11name : Deploy Plugin (PR)
22
33on :
4- pull_request :
5- types : [opened, edited, synchronize]
64 workflow_dispatch :
75 inputs :
86 prNumber :
@@ -14,99 +12,70 @@ jobs:
1412 Deploy_Plugin :
1513 runs-on : ubuntu-latest
1614 steps :
17- - name : Checkout
18- uses : actions/checkout@v4
19- with :
20- fetch-depth : 0
15+ - name : Get Plugin Path and PR Info
16+ run : |
17+ $prNumber = "${{ github.event.inputs.prNumber }}"
18+ $repository = "${{ github.repository }}"
2119
22- - run : |
23- $changes = git diff --name-only origin/main... ./plugins
24- if ( $null -eq $changes ) {
25- Write-Output "Nothing to Deploy as no changes were found in plugins folder..."
26- } else {
27- Write-Output "Changes found in plugins folder: $changes"
28- }
29- $pattern = '(?<=\/[v][0-9]\/).*'
30- $pluginToDeploy = $changes -replace $pattern | Sort-Object -Unique | Select-Object -Last 1
31- if ( $null -eq $pluginToDeploy ) {
32- Write-Output "No plugin to deploy"
33- Write-Output "SKIP_DEPLOYMENT=true" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
34- exit 0
35- }
36- $pluginToDeploy = $pluginToDeploy.TrimStart("plugins/").TrimEnd("/")
37- Write-Output "Plugin to Deploy: $pluginToDeploy"
38- Write-Output "PLUGIN_PATH=$pluginToDeploy" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
39- shell: pwsh
40- name: Get Plugin Path for Deployment
41- if: github.event_name != 'workflow_dispatch'
42- timeout-minutes: 5
20+ # Get PR info
21+ $url = "https://api.github.com/repos/$repository/pulls/$prNumber"
22+ $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "token ${{ secrets.GITHUB_TOKEN }}" }
4323
44- - run : |
45- Write-Output "Getting PR Number based on trigger event..."
46- if ("${{ github.event_name }}" -eq "pull_request") {
47- $prNumber = "${{ github.event.pull_request.number }}"
48- } elseif ("${{ github.event_name }}" -eq "workflow_dispatch") {
49- $prNumber = "${{ github.event.inputs.prNumber }}"
50- } else {
51- Write-Output "Unsupported event: ${{ github.event_name }}"
52- exit -1
53- }
54- if (-not $prNumber) {
55- Write-Output "PR Number is null or empty"
56- exit -1
57- }
58- Write-Output "PR Number: $prNumber"
59- Write-Output "PR_NUMBER=$prNumber" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
60- shell: pwsh
61- name: Get PR Number
62- if: ${{ env. SKIP_DEPLOYMENT != 'true' }}
63- timeout-minutes: 5
24+ # Get changed files in the PR
25+ $filesUrl = $response.url + "/files?per_page=100"
26+ $files = Invoke-RestMethod -Uri $filesUrl -Headers @{Authorization = "token ${{ secrets.GITHUB_TOKEN }}" }
6427
65- - run : |
66- Write-Output "Fetching PR Info..."
67- $prNumber = "${{ env.PR_NUMBER }}"
28+ Write-Output "Total files changed: $($files.Count)"
29+ Write-Output "All changed files: $($files.filename -join ', ')"
6830
69- $repository = "${{ github.repository_owner }}/${{ github.event.repository.name }}"
70- $url = "https://api.github.com/repos/$repository/pulls/$prNumber"
71- $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "token ${{ secrets.GITHUB_TOKEN }}" }
31+ # Find plugin changes
32+ $pluginChanges = $files | Where-Object { $_.filename -like "plugins/*" } | Select-Object -ExpandProperty filename
33+ Write-Output "Plugin files changed: $($pluginChanges -join ', ')"
7234
73- $repoUrl = $response.head.repo.html_url + ".git"
74- $branchName = $response.head.ref
75- Write-Output "Repo URL: $repoUrl | Branch Name: $branchName"
35+ if ($pluginChanges) {
36+ $pattern = '(?<=\/[v][0-9]\/).*'
37+ $pluginToDeploy = $pluginChanges -replace $pattern | Sort-Object -Unique | Select-Object -Last 1
38+ $pluginToDeploy = $pluginToDeploy.TrimStart("plugins/").TrimEnd("/")
39+ Write-Output "Plugin to Deploy: $pluginToDeploy"
40+ Write-Output "PLUGIN_PATH=$pluginToDeploy" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7641
77- Write-Output "PR_REPO_URL=$repoUrl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
78- Write-Output "PR_BRANCH_NAME=$branchName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
42+ # Get PR repo and branch info
43+ $repoUrl = $response.head.repo.html_url + ".git"
44+ $branchName = $response.head.ref
45+ Write-Output "Repo URL: $repoUrl | Branch Name: $branchName"
46+ Write-Output "PR_REPO_URL=$repoUrl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
47+ Write-Output "PR_BRANCH_NAME=$branchName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7948
80- Write-Output "Getting tenant to restrict deployment to..."
81- $repoBody = gh pr view $prNumber --json body --jq '.body' --repo $repository
82- Write-Output "Repo Body: $repoBody"
83- $tenantLine = $repoBody | Select-String -Pattern "^Tenant to Deploy to:.*"
84- Write-Output "Tenant Line: $tenantLine"
85- if ($tenantLine) {
86- $tenant = $tenantLine -replace "Tenant to Deploy to:\s*", "" -replace "\s*$", ""
87- if (-not [string]::IsNullOrWhiteSpace($tenant)) {
88- Write-Output "Tenant to Deploy to: $tenant"
49+ # Get tenant info from PR body
50+ $repoBody = gh pr view $prNumber --json body --jq '.body' --repo $repository
51+ Write-Output "Repo Body: $repoBody"
52+ $tenantLine = $repoBody | Select-String -Pattern "^Tenant to Deploy to:.*"
53+ Write-Output "Tenant Line: $tenantLine"
54+ if ($tenantLine) {
55+ $tenant = $tenantLine -replace "Tenant to Deploy to:\s*", "" -replace "\s*$", ""
56+ if (-not [string]::IsNullOrWhiteSpace($tenant)) {
57+ Write-Output "Tenant to Deploy to: $tenant"
58+ Write-Output "TENANT_TO_RESTRICT_TO=$tenant" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
59+ } else {
60+ Write-Error "Error: 'Tenant to Deploy to' is blank."
61+ exit 1
62+ }
63+ } else {
64+ Write-Error "Error: 'Tenant to Deploy to' field not found."
65+ exit 1
8966 }
90- else {
91- Write-Error "Error: 'Tenant to Deploy to' is blank."
92- exit -1
93- }
94- }
95- else {
96- Write-Error "Error: 'Tenant to Deploy to' field not found."
97- exit -1
67+ } else {
68+ Write-Output "No plugin changes found - skipping deployment"
69+ Write-Output "SKIP_DEPLOYMENT=true" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
9870 }
99- Write-Output "TENANT_TO_RESTRICT_TO=$tenant" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
10071 shell : pwsh
101- name: Fetch PR Info
102- if: ${{ env. SKIP_DEPLOYMENT != 'true' }}
10372 timeout-minutes : 10
10473 env :
10574 GH_TOKEN : ${{ github.token }}
10675
10776 - run : |
10877 Write-Output "Deploying Plugin..."
109- $pluginSuffix = "${{ env.PR_NUMBER }}"
78+ $pluginSuffix = "${{ github.event.inputs.prNumber }}"
11079 $pluginPath = "${{ env.PLUGIN_PATH }}"
11180 $tenantToRestrictTo = "${{ env.TENANT_TO_RESTRICT_TO }}"
11281 $repoUrl = "${{ env.PR_REPO_URL }}"
@@ -142,8 +111,20 @@ jobs:
142111 }
143112 shell: pwsh
144113 name: Deploy Plugin
145- if: ${{ env. SKIP_DEPLOYMENT != 'true' }}
114+ if: ${{ env.SKIP_DEPLOYMENT != 'true' }}
146115 timeout-minutes: 30
147116 env:
148117 DEPLOYER_BASE_URL: ${{ secrets.DEPLOYER_BASE_URL }}
149118 DEPLOYER_API_KEY: ${{ secrets.DEPLOYER_API_KEY }}
119+
120+ - name : Add deployment summary
121+ run : |
122+ echo "## 🚀 Plugin Deployment Summary" >> $GITHUB_STEP_SUMMARY
123+ echo "- **Plugin:** ${{ env.PLUGIN_PATH }}" >> $GITHUB_STEP_SUMMARY
124+ echo "- **PR:** #${{ github.event.inputs.prNumber }}" >> $GITHUB_STEP_SUMMARY
125+ echo "- **Tenant:** ${{ env.TENANT_TO_RESTRICT_TO }}" >> $GITHUB_STEP_SUMMARY
126+ echo "- **Branch:** ${{ env.PR_BRANCH_NAME }}" >> $GITHUB_STEP_SUMMARY
127+ echo "- **Repository:** ${{ env.PR_REPO_URL }}" >> $GITHUB_STEP_SUMMARY
128+ echo "- **Requested by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
129+ if : ${{ env.SKIP_DEPLOYMENT != 'true' }}
130+ shell : bash
0 commit comments