Skip to content

Deploy

Deploy #30

Workflow file for this run

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
}