Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 68 additions & 7 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ jobs:
- npm-merge

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download NPM packages artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -126,14 +131,35 @@ jobs:
$files = Get-ChildItem -Recurse npm-packages/*.tgz

foreach ($file in $files) {
Write-Host "Publishing $($File.Name)..."
Write-Host "Processing $($file.Name)..."

$match = [regex]::Match($file.Name, '^(?<name>.+)-(?<version>\d+\.\d+\.\d+)\.tgz$')

if (-not $match.Success) {
Write-Host "Unable to parse package name/version from $($file.Name), skipping."
continue
}

$pkgName = $match.Groups['name'].Value

# Normalize scope for npm lookups: "devolutions-foo" => "@devolutions/foo"
if ($pkgName -like 'devolutions-*') {
$scopedName = "@devolutions/$($pkgName.Substring(12))"
} else {
$scopedName = $pkgName
}

$pkgVersion = $match.Groups['version'].Value

# Check if this version exists on npm; exit code 0 means it does.
npm view "$scopedName@$pkgVersion" | Out-Null

if ($LASTEXITCODE -eq 0) {
Write-Host "$scopedName@$pkgVersion already exists on npm; skipping publish."
continue
}

$publishCmd = @(
'npm',
'publish',
"$File",
'--access=public'
)
$publishCmd = @('npm','publish',"$file",'--access=public')

if ($isDryRun) {
$publishCmd += '--dry-run'
Expand All @@ -143,7 +169,42 @@ jobs:
Invoke-Expression $publishCmd
}

- name: Create version tags
if: ${{ needs.preflight.outputs.dry-run == 'false' }}
shell: bash
env:
GIT_AUTHOR_NAME: github-actions
GIT_AUTHOR_EMAIL: github-actions@github.com
GIT_COMMITTER_NAME: github-actions
GIT_COMMITTER_EMAIL: github-actions@github.com
run: |
set -e

git fetch --tags

for file in npm-packages/*.tgz; do
base=$(basename "$file" .tgz)

# Split base at the last hyphen to separate name and version
pkg=${base%-*}
# Strip the unscoped prefix introduced by `npm pack` for @devolutions/<pkg>.
pkg=${pkg#devolutions-}

version=${base##*-}

tag="npm-${pkg}-v${version}"

if git rev-parse "$tag" >/dev/null 2>&1; then
echo "Tag $tag already exists; skipping."
continue
fi

git tag "$tag" "$GITHUB_SHA"
git push origin "$tag"
done

- name: Update Artifactory Cache
if: ${{ needs.preflight.outputs.dry-run == 'false' }}
run: |
gh workflow run update-artifactory-cache.yml --repo Devolutions/scheduled-tasks --field package_name="iron-remote-desktop"
gh workflow run update-artifactory-cache.yml --repo Devolutions/scheduled-tasks --field package_name="iron-remote-desktop-rdp"
Expand Down
Loading