Deploy #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |