Skip to content

Publishing to GitHub Packages #18

Publishing to GitHub Packages

Publishing to GitHub Packages #18

name: Publishing to GitHub Packages
on:
schedule:
- cron: '0 0 * * 1-5'
workflow_dispatch:
inputs:
filter:
type: string
description: Package file filter pattern
required: false
timestamp-version:
type: boolean
description: Set timestamp version
required: false
default: true
next-tag:
type: boolean
description: Move 'next' tag
required: false
default: true
stable-tag:
type: boolean
description: Move 'stable' tag
required: false
default: false
env:
FILTER: ${{ github.event_name == 'workflow_dispatch' && inputs.filter || '' }}
SET_TIMESTAMP_VERSION: ${{ (github.event_name == 'workflow_dispatch' && inputs.timestamp-version) || (github.event_name != 'workflow_dispatch' && true) }}
MOVE_NEXT_TAG: ${{ (github.event_name == 'workflow_dispatch' && inputs.next-tag) || (github.event_name != 'workflow_dispatch' && true) }}
MOVE_STABLE_TAG: ${{ (github.event_name == 'workflow_dispatch' && inputs.stable-tag) || (github.event_name != 'workflow_dispatch' && false) }}
jobs:
build:
name: Build packages
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.filter.outputs.packages }}
steps:
- name: Get sources
uses: actions/checkout@v4
- name: Set up nodejs
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install --no-audit --no-fund
- name: Set timestamp version
if: ${{ env.SET_TIMESTAMP_VERSION == 'true' }}
run: npm run ts-script build/set-timestamp-version
- name: Build npm packages
env:
BUILD_INTERNAL_PACKAGE: true
run: npm run all:build
- name: Build artifacts package
run: npm run ts-script build/make-artifacts-package
- uses: actions/upload-artifact@v3
with:
name: packages
path: artifacts/npm/*.tgz
retention-days: 2
- name: Filter packages
id: filter
working-directory: artifacts/npm
run: ls *.tgz | grep -E -i "$FILTER" | sed -r 's/^(.*)$/"\1"/g' | paste -sd "," - | sed -r 's/(.*)/packages=[\1]/' >> "$GITHUB_OUTPUT"
publish:
name: Publish package
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
package: ${{ fromJSON(needs.build.outputs.packages) }}
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: packages
- name: Publish to npm.pkg.github.com
id: publish
env:
PACKAGE: ${{ matrix.package }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AUTHOR: ${{ github.repository_owner }}
# --ignore-scripts is required for publishing devextreme-angular which fails with error:
# 'Trying to publish a package that has been compiled by Ivy in full compilation mode.'
# Should be removed.
run: |
tar -xzf $PACKAGE
cd package
npm init -y --scope $AUTHOR
npm pkg delete repository
npm set //npm.pkg.github.com/:_authToken="$NODE_AUTH_TOKEN"
npm publish --quiet --ignore-scripts --registry https://npm.pkg.github.com
npm pkg get name --workspaces=false | tr -d '"' | sed -r 's/(.*)/name=\1/' >> "$GITHUB_OUTPUT"
npm pkg get version --workspaces=false | tr -d '"' | sed -r 's/(.*)/version=\1/' >> "$GITHUB_OUTPUT"
npm pkg get version --workspaces=false | tr -d '"' | sed -r 's/([0-9]+\.[0-9]+).*/majorVersion=\1/' >> "$GITHUB_OUTPUT"
- name: Move 'next' tag
if: ${{ env.MOVE_NEXT_TAG == 'true' }}
env:
PACKAGE_NAME: ${{ steps.publish.outputs.name }}
PACKAGE_VERSION: ${{ steps.publish.outputs.version }}
PACKAGE_VERSION_MAJOR: ${{ steps.publish.outputs.majorVersion }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm set //npm.pkg.github.com/:_authToken="$NODE_AUTH_TOKEN"
npm --registry=https://npm.pkg.github.com dist-tag add $PACKAGE_NAME@$PACKAGE_VERSION $PACKAGE_VERSION_MAJOR-next
- name: Move 'stable' tag
if: ${{ env.MOVE_STABLE_TAG == 'true' }}
env:
PACKAGE_NAME: ${{ steps.publish.outputs.name }}
PACKAGE_VERSION: ${{ steps.publish.outputs.version }}
PACKAGE_VERSION_MAJOR: ${{ steps.publish.outputs.majorVersion }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm set //npm.pkg.github.com/:_authToken="$NODE_AUTH_TOKEN"
npm --registry=https://npm.pkg.github.com dist-tag add $PACKAGE_NAME@$PACKAGE_VERSION $PACKAGE_VERSION_MAJOR-stable