@@ -106,6 +106,11 @@ jobs:
106106 - npm-merge
107107
108108 steps :
109+ - name : Checkout repository
110+ uses : actions/checkout@v4
111+ with :
112+ fetch-depth : 0
113+
109114 - name : Download NPM packages artifact
110115 uses : actions/download-artifact@v4
111116 with :
@@ -126,14 +131,35 @@ jobs:
126131 $files = Get-ChildItem -Recurse npm-packages/*.tgz
127132
128133 foreach ($file in $files) {
129- Write-Host "Publishing $($File.Name)..."
134+ Write-Host "Processing $($file.Name)..."
135+
136+ $match = [regex]::Match($file.Name, '^(?<name>.+)-(?<version>\d+\.\d+\.\d+)\.tgz$')
137+
138+ if (-not $match.Success) {
139+ Write-Host "Unable to parse package name/version from $($file.Name), skipping."
140+ continue
141+ }
142+
143+ $pkgName = $match.Groups['name'].Value
144+
145+ # Normalize scope for npm lookups: "devolutions-foo" => "@devolutions/foo"
146+ if ($pkgName -like 'devolutions-*') {
147+ $scopedName = "@devolutions/$($pkgName.Substring(12))"
148+ } else {
149+ $scopedName = $pkgName
150+ }
151+
152+ $pkgVersion = $match.Groups['version'].Value
153+
154+ # Check if this version exists on npm; exit code 0 means it does.
155+ npm view "$scopedName@$pkgVersion" | Out-Null
156+
157+ if ($LASTEXITCODE -eq 0) {
158+ Write-Host "$scopedName@$pkgVersion already exists on npm; skipping publish."
159+ continue
160+ }
130161
131- $publishCmd = @(
132- 'npm',
133- 'publish',
134- "$File",
135- '--access=public'
136- )
162+ $publishCmd = @('npm','publish',"$file",'--access=public')
137163
138164 if ($isDryRun) {
139165 $publishCmd += '--dry-run'
@@ -143,7 +169,42 @@ jobs:
143169 Invoke-Expression $publishCmd
144170 }
145171
172+ - name : Create version tags
173+ if : ${{ needs.preflight.outputs.dry-run == 'false' }}
174+ shell : bash
175+ env :
176+ GIT_AUTHOR_NAME : github-actions
177+ GIT_AUTHOR_EMAIL : github-actions@github.com
178+ GIT_COMMITTER_NAME : github-actions
179+ GIT_COMMITTER_EMAIL : github-actions@github.com
180+ run : |
181+ set -e
182+
183+ git fetch --tags
184+
185+ for file in npm-packages/*.tgz; do
186+ base=$(basename "$file" .tgz)
187+
188+ # Split base at the last hyphen to separate name and version
189+ pkg=${base%-*}
190+ # Strip the unscoped prefix introduced by `npm pack` for @devolutions/<pkg>.
191+ pkg=${pkg#devolutions-}
192+
193+ version=${base##*-}
194+
195+ tag="npm-${pkg}-v${version}"
196+
197+ if git rev-parse "$tag" >/dev/null 2>&1; then
198+ echo "Tag $tag already exists; skipping."
199+ continue
200+ fi
201+
202+ git tag "$tag" "$GITHUB_SHA"
203+ git push origin "$tag"
204+ done
205+
146206 - name : Update Artifactory Cache
207+ if : ${{ needs.preflight.outputs.dry-run == 'false' }}
147208 run : |
148209 gh workflow run update-artifactory-cache.yml --repo Devolutions/scheduled-tasks --field package_name="iron-remote-desktop"
149210 gh workflow run update-artifactory-cache.yml --repo Devolutions/scheduled-tasks --field package_name="iron-remote-desktop-rdp"
0 commit comments