Skip to content

Virto-shell CI

Virto-shell CI #687

Workflow file for this run

# v2.0.0
name: Virto-shell CI
on:
workflow_dispatch:
push:
paths-ignore:
- '.github/**'
- '.deployment/**'
- 'docs/**'
- 'README.md'
- 'LICENSE'
branches: [ main ]
jobs:
CI:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
VERSION_SUFFIX: ''
ARTIFACT_URL: ''
GITHUB_USER: '${{ github.repository_owner }}'
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'
always-auth: true
- name: Set GITHUB_USER to lowercase
run: |
echo "GITHUB_USER=${GITHUB_USER,,}" >> $GITHUB_ENV
- name: Install dependencies
run: |
yarn
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
- name: Get Image Version
uses: VirtoCommerce/vc-github-actions/get-image-version@master
id: image
with:
projectType: theme
- name: Set release variables
if: ${{ github.ref == 'refs/heads/main' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.prefix }}" >> $GITHUB_ENV
- name: Set release-alpha variables
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.fullVersion }}" >> $GITHUB_ENV
- name: Set PR variables
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.taggedVersion }}" >> $GITHUB_ENV
- name: Build virto-shell
run: |
yarn build
- name: Add auth token
run: |
yarn config set --json npmRegistries '{ "//registry.npmjs.org": { "npmAuthToken": "'"${NPM_TOKEN}"'" } }'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish virto-shell npm
# if: ${{ github.ref == 'refs/heads/main' }}
run: yarn run publish
- name: Update npm dist tags
if: always()
run: |
declare -A PACKAGE_PATHS=(
["@vc-shell/framework"]="framework"
["@vc-shell/ts-config"]="configs/ts-config"
["@vc-shell/release-config"]="configs/release-config"
["@vc-shell/create-vc-app"]="cli/create-vc-app"
["@vc-shell/config-generator"]="configs/vite-config"
["@vc-shell/api-client-generator"]="cli/api-client"
)
PACKAGES=(
"@vc-shell/framework"
"@vc-shell/ts-config"
"@vc-shell/release-config"
"@vc-shell/create-vc-app"
"@vc-shell/config-generator"
"@vc-shell/api-client-generator"
)
for PACKAGE in "${PACKAGES[@]}"; do
echo "Processing $PACKAGE"
PKG_DIR="${PACKAGE_PATHS[$PACKAGE]}"
if [ -z "$PKG_DIR" ]; then
echo "Error: Path not found for $PACKAGE"
continue
fi
if [ ! -f "${PKG_DIR}/package.json" ]; then
echo "Error: package.json not found for $PACKAGE in ${PKG_DIR}"
continue
fi
CURRENT_VERSION=$(node -p "require('./${PKG_DIR}/package.json').version")
if [ $? -ne 0 ]; then
echo "Error: Failed to get current version for $PACKAGE"
continue
fi
if [[ "$CURRENT_VERSION" == *"-alpha"* ]]; then
echo "Setting alpha tag for $PACKAGE@${CURRENT_VERSION}"
npm dist-tag add "$PACKAGE@${CURRENT_VERSION}" alpha --force
# Get the latest stable version
STABLE_VERSION=$(npm view "$PACKAGE" versions --json | jq -r 'map(select(test("^\\d+\\.\\d+\\.\\d+$"))) | .[-1]')
if [ ! -z "$STABLE_VERSION" ]; then
echo "Restoring latest tag to stable version $PACKAGE@${STABLE_VERSION}"
npm dist-tag add "$PACKAGE@${STABLE_VERSION}" latest --force
fi
elif [[ "$CURRENT_VERSION" == *"-beta"* ]]; then
echo "Setting beta tag for $PACKAGE@${CURRENT_VERSION}"
npm dist-tag add "$PACKAGE@${CURRENT_VERSION}" beta --force
# Get the latest stable version
STABLE_VERSION=$(npm view "$PACKAGE" versions --json | jq -r 'map(select(test("^\\d+\\.\\d+\\.\\d+$"))) | .[-1]')
if [ ! -z "$STABLE_VERSION" ]; then
echo "Restoring latest tag to stable version $PACKAGE@${STABLE_VERSION}"
npm dist-tag add "$PACKAGE@${STABLE_VERSION}" latest --force
fi
else
echo "Setting latest tag for $PACKAGE@${CURRENT_VERSION}"
npm dist-tag add "$PACKAGE@${CURRENT_VERSION}" latest --force
fi
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Verify npm dist tags
run: |
PACKAGES=(
"@vc-shell/framework"
"@vc-shell/ts-config"
"@vc-shell/release-config"
"@vc-shell/create-vc-app"
"@vc-shell/config-generator"
"@vc-shell/api-client-generator"
)
for PACKAGE in "${PACKAGES[@]}"; do
echo "Tags for $PACKAGE:"
npm dist-tag ls "$PACKAGE"
echo "-------------------"
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Storybook:
needs: 'CI'
uses: VirtoCommerce/vc-shell/.github/workflows/storybook-ci.yml@main
with:
event_name: ${{ github.event_name }}
secrets:
VCMP_PLATFORM_TOKEN: ${{ secrets.VCMP_PLATFORM_TOKEN }}