0.1.1 #2
Workflow file for this run
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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
name: "Publish Deno Package" | |
on: | |
release: | |
types: | |
- "published" | |
jobs: | |
main: | |
permissions: | |
contents: "read" | |
id-token: "write" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Checkout Repository" | |
uses: "actions/checkout@v4" | |
- name: "Setup Deno" | |
uses: "denoland/setup-deno@v2" | |
with: | |
deno-version: "^2.0.0" | |
- name: "Get Deno Cache Path" | |
id: "deno-cache-path" | |
shell: "pwsh" | |
run: |- | |
[PSCustomObject]$DenoInfo = deno info --json | | |
ConvertFrom-Json -Depth 100 | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "value=$($DenoInfo.denoDir)" -Confirm:$False -Encoding 'UTF8NoBOM' | |
- name: "Restore Deno Cache" | |
id: "deno-cache-restore" | |
uses: "actions/cache/restore@v4" | |
with: | |
key: "${{runner.os}}/Deno/${{github.run_id}}-${{github.run_attempt}}-${{github.job}}" | |
restore-keys: |- | |
${{runner.os}}/Deno/${{github.run_id}}-${{github.run_attempt}}- | |
${{runner.os}}/Deno/${{github.run_id}}- | |
${{runner.os}}/Deno/ | |
path: "${{steps.deno-cache-path.outputs.value}}" | |
- name: "Resolve Metadata" | |
id: "metadata" | |
shell: "pwsh" | |
run: |- | |
[PSCustomObject]$Config = Get-Content -LiteralPath '.\deno.jsonc' -Encoding 'UTF8NoBOM' | | |
ConvertFrom-Json -Depth 100 | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "build=$(($Null -ine $Config.tasks.build).ToString().ToLower())" | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "jsr-publish=$(($Null -ine $Config.tasks.('jsr-publish')).ToString().ToLower())" | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "jsr-publish-provenance=$(($Null -ine $Config.tasks.('jsr-publish-provenance')).ToString().ToLower())" | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "npm-build=$(($Null -ine $Config.tasks.('npm-build')).ToString().ToLower())" | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "npm-root=$(Join-Path -Path $Env:GITHUB_WORKSPACE -ChildPath ($Config._behaviour.npm.root ?? 'npm'))" | |
- name: "Build Repository" | |
if: "${{steps.metadata.outputs.build == 'true'}}" | |
run: |- | |
deno task build | |
- name: "Publish Package To JSR (Provenance)" | |
id: "jsr-publish-provenance" | |
if: "${{steps.metadata.outputs.jsr-publish-provenance == 'true'}}" | |
run: |- | |
deno task jsr-publish-provenance | |
- name: "Publish Package To JSR" | |
if: "${{!cancelled() && ((steps.metadata.outputs.jsr-publish-provenance == 'true' && steps.jsr-publish-provenance.outcome == 'failure') || (steps.metadata.outputs.jsr-publish-provenance == 'false' && steps.metadata.outputs.jsr-publish == 'true'))}}" | |
run: |- | |
deno task jsr-publish | |
- name: "Build Package For NPM" | |
id: "npm-build" | |
if: "${{!cancelled() && steps.metadata.outputs.npm-build == 'true'}}" | |
run: |- | |
deno task npm-build | |
- name: "Save NPM Package Artifact" | |
id: "npm-artifact" | |
if: "${{!cancelled() && steps.metadata.outputs.npm-build == 'true' && steps.npm-build.outcome == 'success'}}" | |
uses: "actions/upload-artifact@v4" | |
with: | |
name: "npm-artifact" | |
path: "${{steps.metadata.outputs.npm-root}}" | |
if-no-files-found: "error" | |
retention-days: "1" | |
include-hidden-files: "true" | |
- name: "Save Deno Cache" | |
if: "${{!cancelled() && steps.deno-cache-restore.outcome == 'success'}}" | |
uses: "actions/cache/save@v4" | |
with: | |
key: "${{runner.os}}/Deno/${{github.run_id}}-${{github.run_attempt}}-${{github.job}}" | |
path: "${{steps.deno-cache-path.outputs.value}}" | |
outputs: | |
npm-artifact: "${{steps.npm-artifact.outcome == 'success'}}" | |
npm-build: "${{steps.metadata.outputs.npm-build}}" | |
npm: | |
name: "NPM" | |
permissions: | |
contents: "write" | |
id-token: "write" | |
needs: | |
- "main" | |
if: "${{!cancelled() && needs.main.outputs.npm-build == 'true' && needs.main.outputs.npm-artifact == 'true'}}" | |
runs-on: "ubuntu-latest" | |
env: | |
NODE_AUTH_TOKEN: "${{secrets.NPM_TOKEN}}" | |
steps: | |
- name: "Restore NPM Package Artifact" | |
uses: "actions/download-artifact@v4" | |
with: | |
name: "npm-artifact" | |
path: "${{github.workspace}}" | |
- name: "Setup NodeJS" | |
uses: "actions/setup-node@v4" | |
with: | |
node-version: "lts/*" | |
check-latest: true | |
registry-url: "https://registry.npmjs.org/" | |
- name: "Get NPM Cache Path" | |
id: "npm-cache-path" | |
shell: "pwsh" | |
run: |- | |
[String]$NpmCachePath = ( | |
npm config get cache | | |
Join-String -Separator "`n" | |
).Trim() | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "value=$($NpmCachePath)" -Confirm:$False -Encoding 'UTF8NoBOM' | |
- name: "Restore NPM Cache" | |
id: "npm-cache-restore" | |
uses: "actions/cache/restore@v4" | |
with: | |
key: "${{runner.os}}/NPM/${{github.run_id}}-${{github.run_attempt}}-${{github.job}}" | |
restore-keys: |- | |
${{runner.os}}/NPM/${{github.run_id}}-${{github.run_attempt}}- | |
${{runner.os}}/NPM/${{github.run_id}}- | |
${{runner.os}}/NPM/ | |
path: "${{steps.npm-cache-path.outputs.value}}" | |
- name: "Resolve Metadata" | |
id: "metadata" | |
shell: "pwsh" | |
run: |- | |
[PSCustomObject]$Manifest = Get-Content -LiteralPath '.\package.json' -Encoding 'UTF8NoBOM' | | |
ConvertFrom-Json -Depth 100 | |
[SemVer]$VersionManifest = [SemVer]::Parse($Manifest.version) | |
[SemVer]$VersionTag = [SemVer]::Parse(('${{github.event.release.tag_name}}' -ireplace '^v', '')) | |
If ($VersionTag -ine $VersionManifest) { | |
npm version $VersionTag.ToString() | |
$VersionManifest = $VersionTag | |
} | |
[String]$Name = $Manifest.Name | |
[Boolean]$VersionIsPreRelease = $Null -ine $VersionManifest.PreReleaseLabel | |
[Boolean]$TagLatest = !$VersionIsPreRelease | |
[Boolean]$TagPre = $True | |
Try { | |
[PSCustomObject]$NpmMetadata = npm show $Name --json | | |
ConvertFrom-Json -Depth 100 | |
If ($LASTEXITCODE -ne 0) { | |
Throw 'Package not found!' | |
} | |
If ($VersionManifest -ile [SemVer]::Parse(($NpmMetadata.'dist-tags'.latest ?? '0.0.0'))) { | |
$TagLatest = $False | |
} | |
If ($VersionManifest -ile [SemVer]::Parse(($NpmMetadata.'dist-tags'.pre ?? '0.0.0'))) { | |
$TagPre = $False | |
} | |
} | |
Catch { | |
Write-Warning -Message "Unable to resolve package NPM publish tags: $_" | |
$LASTEXITCODE = 0 | |
} | |
[String[]]$Tags = @() | |
If ($TagLatest) { | |
$Tags += 'latest' | |
} | |
If ($TagPre) { | |
$Tags += 'pre' | |
} | |
If (!$VersionIsPreRelease) { | |
$Tags += "latest-$($VersionManifest.Major)" | |
} | |
$Tags += "pre-$($VersionManifest.Major)" | |
If ($Tags.Count -eq 0) { | |
Write-Error -Message 'No NPM publish tags!' -ErrorAction 'Stop' | |
} | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "name=$($Name)" -Confirm:$False -Encoding 'UTF8NoBOM' | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "version=$($VersionManifest.ToString())" -Confirm:$False -Encoding 'UTF8NoBOM' | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "descriptor=$($Name)@$($VersionManifest.ToString())" -Confirm:$False -Encoding 'UTF8NoBOM' | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "build=$(($Null -ne $Manifest.scripts.'build').ToString().ToLower())" -Confirm:$False -Encoding 'UTF8NoBOM' | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "tags-first=$($Tags[0])" -Confirm:$False -Encoding 'UTF8NoBOM' | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "tags-rest=$( | |
$Tags | | |
Select-Object -SkipIndex 0 | | |
Join-String -Separator ',' | |
)" -Confirm:$False -Encoding 'UTF8NoBOM' | |
Add-Content -LiteralPath $Env:GITHUB_OUTPUT -Value "ballname=$($Name -ireplace '^@', '' -ireplace '\/', '-')-$($VersionManifest.ToString()).tgz" -Confirm:$False -Encoding 'UTF8NoBOM' | |
- name: "Install Dependencies" | |
if: "${{steps.metadata.outputs.build == 'true'}}" | |
run: |- | |
npm install | |
- name: "Build Repository" | |
if: "${{steps.metadata.outputs.build == 'true'}}" | |
run: |- | |
npm run build | |
- name: "Publish Package To NPM With Tag `${{steps.metadata.outputs.tags-first}}` (Provenance)" | |
id: "npm-publish-provenance" | |
shell: "pwsh" | |
run: |- | |
npm publish --provenance --tag '${{steps.metadata.outputs.tags-first}}' | |
- name: "Publish Package To NPM With Tag `${{steps.metadata.outputs.tags-first}}`" | |
if: "${{!cancelled() && steps.npm-publish-provenance.outcome == 'failure'}}" | |
id: "npm-publish-raw" | |
shell: "pwsh" | |
run: |- | |
npm publish --tag '${{steps.metadata.outputs.tags-first}}' | |
- name: "Publish Package To NPM With Rest Tags" | |
if: "${{!cancelled() && (steps.npm-publish-provenance.outcome == 'success' || steps.npm-publish-raw.outcome == 'success') && steps.metadata.outputs.tags-rest != ''}}" | |
shell: "pwsh" | |
run: |- | |
[String]$Descriptor = '${{steps.metadata.outputs.descriptor}}' | |
[String[]]$TagsRest = '${{steps.metadata.outputs.tags-rest}}' -isplit ',' | |
ForEach ($TagRest In $TagsRest) { | |
npm dist-tag add $Descriptor $TagRest | |
} | |
- name: "Upload Package `${{steps.metadata.outputs.ballname}}` To GitHub Release Tag `${{github.event.release.tag_name}}`" | |
if: "${{!cancelled() && steps.metadata.outcome == 'success'}}" | |
env: | |
GH_TOKEN: "${{secrets.GITHUB_TOKEN}}" | |
shell: "pwsh" | |
run: |- | |
npm pack | |
gh release upload '${{github.event.release.tag_name}}' '${{steps.metadata.outputs.ballname}}' --clobber --repo $Env:GITHUB_REPOSITORY | |
- name: "Save NPM Cache" | |
if: "${{!cancelled() && steps.npm-cache-restore.outcome == 'success'}}" | |
uses: "actions/cache/save@v4" | |
with: | |
key: "${{runner.os}}/NPM/${{github.run_id}}-${{github.run_attempt}}-${{github.job}}" | |
path: "${{steps.npm-cache-path.outputs.value}}" |