Skip to content

Publishing to GitHub Packages #182

Publishing to GitHub Packages

Publishing to GitHub Packages #182

name: Publishing to GitHub Packages
on:
workflow_dispatch:
inputs:
tag:
description: "Choose a tag: 'daily' when publishing a daily build with a timestamp version, 'stable' when publishing a stable build from a release branch"
type: choice
options:
- daily
- stable
default: 'daily'
required: false
filter:
type: string
description: Package file filter pattern
required: false
env:
FILTER: ${{ github.event_name == 'workflow_dispatch' && inputs.filter || '' }}
SET_TIMESTAMP_VERSION: ${{ inputs.tag == 'daily' }}
MOVE_DAILY_TAG: ${{ inputs.tag == 'daily' }}
MOVE_STABLE_TAG: ${{ inputs.tag == 'stable' }}
jobs:
build:
name: Build packages
runs-on: windows-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: npx ts-node tools/scripts/set-timestamp-version
- name: Build npm packages
env:
BUILD_INTERNAL_PACKAGE: true
run: npm run all:build
- name: Clone deps scanner
uses: actions/checkout@v4
with:
repository: DevExpress/npmdeps-scanner
token: ${{ secrets.NPM_DEPS_SCANNER_PAT }}
path: deps-scanner
- name: Build deps scanner
working-directory: deps-scanner
run: dotnet build npmDepsScanner.csproj /p:Configuration=Release
- name: Run deps scanner
run: |
./deps-scanner/bin/Release/npmDepsScanner.exe scan_cache ${{ github.workspace }} reportGithub.json
mkdir -p ./artifacts/deps-scanner
cp reportGithub.json ./artifacts/deps-scanner/
- name: Build artifacts package
run: npx ts-node tools/scripts/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
shell: bash
run: ls *.tgz | grep -E -i "$FILTER" | sed -r 's/^(.*).tgz$/"\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: Get sources
uses: actions/checkout@v4
with:
sparse-checkout: |
/tools
/packages/devextreme-monorepo-tools
package.json
sparse-checkout-cone-mode: false
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: packages
- name: Install dependencies
run: npm install --no-audit --no-fund --legacy-peer-deps --ignore-scripts
- name: Change package scope
id: scopedPackage
env:
PACKAGE: ${{ matrix.package }}
run: |
SCOPE=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]');
PACKAGE_DIR=$(npx ts-node tools/scripts/change-package-scope --tgz $PACKAGE.tgz --scope $SCOPE)
echo "packageDir=$PACKAGE_DIR" >> "$GITHUB_OUTPUT";
cd $PACKAGE_DIR;
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";
# --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.
- name: Publish to npm.pkg.github.com
working-directory: ${{ steps.scopedPackage.outputs.packageDir }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm set //npm.pkg.github.com/:_authToken="$NODE_AUTH_TOKEN";
npm publish --quiet --ignore-scripts --registry https://npm.pkg.github.com;
- name: Move 'daily' tag
if: ${{ env.MOVE_DAILY_TAG == 'true' }}
env:
PACKAGE_NAME: ${{ steps.scopedPackage.outputs.name }}
PACKAGE_VERSION: ${{ steps.scopedPackage.outputs.version }}
PACKAGE_VERSION_MAJOR: ${{ steps.scopedPackage.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-daily
- name: Move 'stable' tag
if: ${{ env.MOVE_STABLE_TAG == 'true' }}
env:
PACKAGE_NAME: ${{ steps.scopedPackage.outputs.name }}
PACKAGE_VERSION: ${{ steps.scopedPackage.outputs.version }}
PACKAGE_VERSION_MAJOR: ${{ steps.scopedPackage.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
notify:
runs-on: devextreme-shr2
name: Send notifications
needs: [ build, publish ]
if: failure()
steps:
- uses: actions/checkout@v4
- uses: DevExpress/github-actions/send-teams-notification@v1
with:
hook_url: ${{secrets.TEAMS_ALERT}}
bearer_token: ${{secrets.GITHUB_TOKEN}}
specific_repo: DevExpress/DevExtreme