Skip to content

Publish libraries

Publish libraries #99

name: Publish libraries
on:
workflow_dispatch:
inputs:
dry-run:
description: 'Dry run'
required: true
type: boolean
default: 'true'
schedule:
- cron: '49 3 * * 1' # 3:49 AM UTC every Monday
jobs:
preflight:
name: Preflight
runs-on: ubuntu-20.04
outputs:
dry-run: ${{ steps.get-dry-run.outputs.dry-run }}
steps:
- name: Get dry run
id: get-dry-run
shell: pwsh
run: |
Set-PSDebug -Trace 1
$IsDryRun = '${{ github.event.inputs.dry-run }}' -Eq 'true' -Or '${{ github.event_name }}' -Eq 'schedule'
if ($IsDryRun) {
echo "dry-run=true" >> $Env:GITHUB_OUTPUT
} else {
echo "dry-run=false" >> $Env:GITHUB_OUTPUT
}
nuget-build:
name: NuGet package build [${{matrix.library}}]
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
library: [ dotnet-client, dotnet-subscriber, utils ]
include:
- library: dotnet-client
libpath: ./devolutions-gateway/openapi/dotnet-client
- library: dotnet-subscriber
libpath: ./devolutions-gateway/openapi/dotnet-subscriber
- library: utils
libpath: ./utils/dotnet
steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v3
- name: Build
shell: pwsh
run: |
Set-PSDebug -Trace 1
$Path = '${{matrix.libpath}}'
& "$Path/build.ps1"
New-Item -ItemType "directory" -Path . -Name "nuget-packages"
Get-ChildItem -Path $Path -Recurse *.nupkg | ForEach { Copy-Item $_ "./nuget-packages" }
- name: Upload packages
uses: actions/upload-artifact@v3
with:
name: nupkg
path: nuget-packages/*.nupkg
npm-build:
name: NPM package build
runs-on: ubuntu-20.04
steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v3
- name: Build
shell: pwsh
run: |
Set-PSDebug -Trace 1
$Path = './devolutions-gateway/openapi/ts-angular-client'
& "$Path/build.ps1"
New-Item -ItemType "directory" -Path . -Name "npm-packages"
Get-ChildItem -Path $Path -Recurse *.tgz | ForEach { Copy-Item $_ "./npm-packages" }
- name: Upload packages
uses: actions/upload-artifact@v3
with:
name: npm
path: npm-packages/*.tgz
nuget-publish:
name: Publish NuGet packages
runs-on: ubuntu-20.04
environment: publish-prod
if: needs.preflight.outputs.dry-run == 'false'
needs:
- preflight
- nuget-build
steps:
- name: Download NuGet packages artifact
uses: actions/download-artifact@v3
with:
name: nupkg
path: nuget-packages
- name: Publish to nuget.org
shell: pwsh
run: |
Set-PSDebug -Trace 1
$Files = Get-ChildItem -Recurse nuget-packages/*.nupkg
foreach ($File in $Files) {
$PushCmd = @(
'dotnet',
'nuget',
'push',
"$File",
'--api-key',
'${{ secrets.NUGET_API_KEY }}',
'--source',
'https://api.nuget.org/v3/index.json',
'--skip-duplicate'
)
Write-Host "Publishing $($File.Name)..."
$PushCmd = $PushCmd -Join ' '
Invoke-Expression $PushCmd
}
npm-publish:
name: Publish NPM packages
runs-on: ubuntu-20.04
environment: publish-prod
if: needs.preflight.outputs.dry-run == 'false'
needs:
- preflight
- npm-build
steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v3
- name: Download NPM packages artifact
uses: actions/download-artifact@v3
with:
name: npm
path: npm-packages
- name: Configure NPM
shell: pwsh
run: npm config set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
- name: Publish
shell: pwsh
run: |
Set-PSDebug -Trace 1
$Files = Get-ChildItem -Recurse npm-packages/*.tgz
foreach ($File in $Files) {
Write-Host "Publishing $($File.Name)..."
./ci/npm-publish.ps1 -Tarball "$File" -Access 'public'
}