-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (82 loc) · 3.79 KB
/
deploy.yml
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
name: Deploy
on:
workflow_run:
workflows: [Build & Text]
types: [completed]
branches: [ release/* ]
jobs:
on-success-build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment: production
steps:
- name: 📝 Fetch Sources
uses: actions/checkout@v3
- name: 🛠 Import environment
uses: ./.github/workflows/environment
- name: 🛠 Setup JDK
uses: actions/setup-java@v3
with:
java-version: 17
distribution: corretto
- name: 📦 Download artifacts
uses: dawidd6/action-download-artifact@v2
with:
name: plugin-artifacts-ubuntu-latest
path: ${{ env.ARTIFACTS_FOLDER }}
run_id: ${{ github.event.workflow_run.id }}
if_no_artifact_found: fail
- name: 📦 Tree artifacts
shell: pwsh
run: |
tree ${{ env.ARTIFACTS_FOLDER }}
- name: 📦 Extract metadata
shell: pwsh
run: |
$PLUGIN_VERSION = (cat "${{ env.ARTIFACTS_FOLDER }}/${{ env.ARTIFACTS_VERSION }}")
echo "PLUGIN_VERSION=$PLUGIN_VERSION" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
$PLUGIN_ID = (cat "${{ env.ARTIFACTS_FOLDER }}/${{ env.ARTIFACTS_PLUGIN_ID }}")
echo "PLUGIN_ID=$PLUGIN_ID" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: 🚀 Create Release
uses: ncipollo/release-action@v1
with:
name: ${{ env.PLUGIN_VERSION }}
commit: ${{ github.sha }} # Commit SHA
tag: v${{ env.PLUGIN_VERSION }} # 'v' + version from gradle.properties
draft: true
bodyFile: ${{ env.ARTIFACTS_FOLDER }}/${{ env.ARTIFACTS_CHANGELOG }}
artifacts: "${{ env.ARTIFACTS_FOLDER }}/${{ env.PLUGIN_NAME }}-${{ env.PLUGIN_VERSION }}.zip"
token: ${{ secrets.GITHUB_TOKEN }}
- name: 🚀 Publish Plugin
shell: pwsh
run: |
$uploadUrl = '${{ env.PLUGINS_REPOSITORY }}/api/updates/upload'
$token = '${{ secrets.JB_PUBLISH_TOKEN }}'
Write-Host "Upload URL: $uploadUrl"
$pluginXmlId = Get-Content -Raw -Path '${{ env.ARTIFACTS_FOLDER }}/${{ env.ARTIFACTS_PLUGIN_ID }}'
Write-Host "Plugin ID to upload: $pluginXmlId"
$channel = 'stable'
Write-Host "Channel: $channel"
$pluginPath = '${{ env.ARTIFACTS_FOLDER }}/${{ env.PLUGIN_NAME }}-${{ env.PLUGIN_VERSION }}.zip'
Write-Host "Plugin archive location: $pluginPath"
$content = [System.Net.Http.MultipartFormDataContent]::new()
$content.Add((New-Object System.Net.Http.StringContent $pluginXmlId.Trim()), 'xmlId')
$content.Add((New-Object System.Net.Http.StringContent $channel), 'channel')
$filePart = [System.Net.Http.StreamContent]::new([System.IO.File]::OpenRead($pluginPath))
$filePart.Headers.ContentDisposition = 'form-data; name="file"; filename="{0}"' -f (Split-Path -Leaf $pluginPath)
$content.Add($filePart, 'file')
Write-Host "Multipart form data created"
Write-Host "Requesting POST $uploadUrl..."
$client = [System.Net.Http.HttpClient]::new()
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue('Bearer', $token)
$result = $client.PostAsync($uploadUrl, $content).Result
$status = $result.StatusCode
$isSuccess = $result.IsSuccessStatusCode
Write-Host "Status Code: $status"
Write-Host "Is Success: $isSuccess"
$responseContent = $result.Content.ReadAsStringAsync().Result
echo "Response: $responseContent"
if (-not $isSuccess) {
Write-Host "Request failed. Exiting."
exit 1
}