Skip to content

1.0.0-alpha.23

1.0.0-alpha.23 #23

Workflow file for this run

# Publish
#
# Cross-publish package to GitHub Package Registry and NPM when a GitHub release is published or on
# workflow dispatch.
#
# References:
#
# - https://docs.github.com/actions/learn-github-actions/contexts
# - https://docs.github.com/actions/learn-github-actions/expressions
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#release
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# - https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#release
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch
# - https://github.com/actions/checkout
# - https://github.com/actions/setup-node
# - https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#yarn2-configuration
# - https://github.com/hmarr/debug-action
---
name: publish
on:
release:
types:
- published
workflow_dispatch:
inputs:
tag:
description: release tag
required: true
type: string
env:
REF: ${{ format('refs/tags/{0}', inputs.tag || github.event.release.tag_name) }}
TAG: ${{ inputs.tag || github.event.release.tag_name }}
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ inputs.tag || github.event.release.tag_name }}
jobs:
preflight:
permissions:
contents: read
runs-on: ubuntu-latest
outputs:
publish-command: ${{ steps.publish-command.outputs.result }}
version: ${{ steps.version.outputs.result }}
steps:
- id: debug
name: Print environment variables and event payload
uses: hmarr/[email protected]
- id: checkout
name: Checkout ${{ env.TAG }}
uses: actions/[email protected]
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: version
name: Get package version
run: echo "result=$(jq .version package.json -r)" >>$GITHUB_OUTPUT
- id: artifact
name: Get release artifact download URL
run: |
echo "result=${{ github.event_name == 'release' && github.event.release.assets[0].browser_download_url || format('{0}/{1}/releases/download/{2}/%40{3}-{4}-{5}.tgz', github.server_url, github.repository, env.TAG, github.repository_owner, github.event.repository.name, steps.version.outputs.result) }}" >>$GITHUB_OUTPUT
- id: dist-tag
name: Get dist tag
uses: flex-development/[email protected]
with:
target: ${{ steps.version.outputs.result }}
- id: publish-command
name: Get publish command
env:
ARTIFACT: ${{ steps.artifact.outputs.result }}
FLAGS: ${{ steps.dist-tag.outputs.flag }}
run: echo "result=npm publish $ARTIFACT $FLAGS" >>$GITHUB_OUTPUT
gpr:
needs: preflight
permissions:
packages: write
runs-on: ubuntu-latest
environment:
name: gpr
url: |
${{ format('{0}/{1}/pkgs/npm/{2}', github.server_url, github.repository,
github.event.repository.name) }}
steps:
- id: checkout
name: Checkout ${{ env.TAG }}
uses: actions/[email protected]
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: npmrc-cleanup
name: Remove stale .npmrc file
run: rm .npmrc
- id: npmrc
name: Setup .npmrc file
uses: actions/[email protected]
with:
always-auth: true
node-version-file: .nvmrc
registry-url: https://npm.pkg.github.com
scope: ${{ github.repository_owner }}
- id: npmrc-print
name: Print contents of .npmrc file
run: cat $NPM_CONFIG_USERCONFIG
- id: publish
name: Publish package
run: ${{ needs.preflight.outputs.publish-command }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
npm:
needs:
- gpr
- preflight
permissions:
packages: write
runs-on: ubuntu-latest
environment:
name: npm
url: |
${{ format('https://npmjs.com/package/@{0}/v/{1}', github.repository,
needs.preflight.outputs.version) }}
steps:
- id: checkout
name: Checkout ${{ env.TAG }}
uses: actions/[email protected]
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: npmrc-cleanup
name: Remove stale .npmrc file
run: rm .npmrc
- id: npmrc
name: Setup .npmrc file
uses: actions/[email protected]
with:
always-auth: true
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
scope: ${{ github.repository_owner }}
- id: npmrc-print
name: Print contents of .npmrc file
run: cat $NPM_CONFIG_USERCONFIG
- id: publish
name: Publish package
run: ${{ needs.preflight.outputs.publish-command }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}