Skip to content

[Feature] Angular CSDK initial support (#550) #363

[Feature] Angular CSDK initial support (#550)

[Feature] Angular CSDK initial support (#550) #363

Workflow file for this run

name: Publish
permissions:
contents: read
pull-requests: write
on:
# Trigger for canary and stable releases:
# - Stable prod release: When PR from changeset-release/* branch is merged with [release] prefix
# - Canary release: Push to dev or release/* branches (not from changeset-release merge)
push:
branches:
- dev
- 'release/**'
paths:
- '**'
# changesets/action runs csdk:prep-release which consumes .changeset/*.md in that runner.
# Canary snapshot must run in a separate job with its own checkout so changesets still exist.
jobs:
stable-release-prep:
runs-on: ubuntu-latest
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
steps:
- name: Generate GitHub App Token
id: generate-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
persist-credentials: false
token: ${{ steps.generate-token.outputs.token }}
- name: Set git configuration
run: |
git config --global user.email builds@sitecore.com
git config --global user.name "content-sdk-bot"
git remote set-url origin https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/${{ github.repository }}
- name: Use Node.js 24
uses: actions/setup-node@v4
with:
node-version: 24
- name: Install dependencies
run: |
yarn cache clean --all
yarn install --immutable
- name: Build packages
run: npm run build
- name: Generate API docs
run: |
yarn generate-docs
if [ -n "$(git status --porcelain)" ]; then
git add ./ref-docs/**/*
git commit -m "Update API docs [skip ci]" || echo "⚠️ Failed to commit API docs (may already be committed)"
git push origin HEAD:${{ github.ref_name }} || echo "⚠️ Failed to push API docs (may already be pushed or no changes)"
else
echo "No API doc changes to commit"
fi
- name: Creating .npmrc
run: |
NPM_REGISTRY="${NPM_REGISTRY%/}"
NPM_REGISTRY="${NPM_REGISTRY}/"
write_npmrc() {
{
echo "@sitecore-content-sdk:registry=https://$NPM_REGISTRY"
echo "registry=https://$NPM_REGISTRY"
echo "//$NPM_REGISTRY:_authToken=$NPM_TOKEN"
} > "$1"
}
write_npmrc "$GITHUB_WORKSPACE/.npmrc"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_REGISTRY: ${{ secrets.NPM_REGISTRY }}
- name: Prepare and Process Changesets Release
id: changesets
uses: changesets/action@v1
with:
version: yarn csdk:prep-release
publish: yarn changeset:publish --tag latest
commit: '[release][ci] Version bump and changelog'
title: ${{ github.ref_name == 'dev' && '[csdk] latest release' || format('[csdk] patch release - {0}', github.ref_name) }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_REGISTRY: ${{ secrets.NPM_REGISTRY }}
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
npm_config_ignore_scripts: true # skip lifecycle scripts to avoid running build again during changeset:publish
canary-snapshot:
runs-on: ubuntu-latest
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Use Node.js 24
uses: actions/setup-node@v4
with:
node-version: 24
- name: Install dependencies
run: |
yarn cache clean --all
yarn install --immutable
- name: Build packages
run: npm run build
- name: Creating .npmrc
run: |
NPM_REGISTRY="${NPM_REGISTRY%/}"
NPM_REGISTRY="${NPM_REGISTRY}/"
write_npmrc() {
{
echo "@sitecore-content-sdk:registry=https://$NPM_REGISTRY"
echo "registry=https://$NPM_REGISTRY"
echo "//$NPM_REGISTRY:_authToken=$NPM_TOKEN"
} > "$1"
}
write_npmrc "$GITHUB_WORKSPACE/.npmrc"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_REGISTRY: ${{ secrets.NPM_REGISTRY }}
- name: Pre-release canary version bump and snapshot cascade
id: canary_snapshot
run: yarn changeset:cascade-snapshot-version
- name: Re-Install dependencies
run: |
yarn install
- name: Compute snapshot npm dist-tag
id: snapshot_tag
if: steps.canary_snapshot.outputs.snapshot_publish == 'true'
uses: actions/github-script@v7
with:
script: |
const sha = context.sha;
const short = sha.slice(0, 7);
const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: sha,
});
const prNums = data.map((p) => p.number).filter((n) => n != null);
const prLabel = prNums.length ? String(Math.max(...prNums)) : 'no-pr';
const tagPr = `canary.pr-${prLabel}`;
const tagSha = `canary.commit-${short}`;
core.setOutput('tag_pr', tagPr);
core.setOutput('tag_sha', tagSha);
core.info(`Snapshot npm dist-tags: ${tagPr} + ${tagSha}`);
- name: Publish canary snapshot packages to npm
if: steps.canary_snapshot.outputs.snapshot_publish == 'true'
env:
COMMIT_NPM_TAG: ${{ steps.snapshot_tag.outputs.tag_sha }}
PR_NPM_TAG: ${{ steps.snapshot_tag.outputs.tag_pr }}
npm_config_ignore_scripts: true # skip lifecycle scripts to avoid running build again during changeset:publish
run: |
BRANCH_NAME="${{ github.ref_name }}"
if [[ "$BRANCH_NAME" =~ ^release/beta ]]; then
NPM_TAG="beta"
elif [[ "$BRANCH_NAME" =~ ^release/ ]]; then
NPM_TAG="hotfix-canary"
else
NPM_TAG="canary"
fi
yarn build
yarn changeset:publish --tag $NPM_TAG --no-git-tag