Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/back-merge-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Opens a PR from master → development after changes land on master (back-merge).
#
# Org/repo Settings → Actions → General → Workflow permissions: read and write
# (so GITHUB_TOKEN can create pull requests). Or use a PAT in secret GH_TOKEN.

name: Back-merge master to development

on:
push:
branches: [master]
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
open-back-merge-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Open back-merge PR if needed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git fetch origin development master

MASTER_SHA=$(git rev-parse origin/master)
DEV_SHA=$(git rev-parse origin/development)

if [ "$MASTER_SHA" = "$DEV_SHA" ]; then
echo "master and development are at the same commit; nothing to back-merge."
exit 0
fi

EXISTING=$(gh pr list --repo "${{ github.repository }}" \
--base development \
--head master \
--state open \
--json number \
--jq 'length')

if [ "$EXISTING" -gt 0 ]; then
echo "An open PR from master to development already exists; skipping."
exit 0
fi

gh pr create --repo "${{ github.repository }}" \
--base development \
--head master \
--title "chore: back-merge master into development" \
--body "Automated back-merge after changes landed on \`master\`. Review and merge to keep \`development\` in sync."

echo "Created back-merge PR master → development."
20 changes: 0 additions & 20 deletions .github/workflows/check-branch.yml

This file was deleted.

82 changes: 82 additions & 0 deletions .github/workflows/check-version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Runs only when production code under contentstack_utils/ changes. Version must be > latest v* tag (not vs base branch).

name: Check Version Bump

on:
pull_request:

jobs:
check-version-bump:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version and changelog updates
shell: bash
run: |
set -euo pipefail

VERSION_FILE="setup.py"
INIT_FILE="contentstack_utils/__init__.py"
CHANGELOG_FILE="CHANGELOG.md"
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"

mapfile -t CHANGED_FILES < <(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
if [ "${#CHANGED_FILES[@]}" -eq 0 ]; then
echo "No changed files detected."
exit 0
fi

is_production_source_change() {
local f="$1"
[[ "$f" == contentstack_utils/* ]]
}

has_source_changes=false
for file in "${CHANGED_FILES[@]}"; do
if is_production_source_change "$file"; then
has_source_changes=true
break
fi
done

if [ "$has_source_changes" = false ]; then
echo "Skipping: no contentstack_utils/ production code changes."
exit 0
fi

changed_file() {
local target="$1"
for file in "${CHANGED_FILES[@]}"; do
if [ "$file" = "$target" ]; then
return 0
fi
done
return 1
}

changed_file "$VERSION_FILE" || { echo "Version bump required in $VERSION_FILE."; exit 1; }
changed_file "$CHANGELOG_FILE" || { echo "Matching changelog update required in $CHANGELOG_FILE."; exit 1; }

head_version=$(python3 -c 'import re; c=open("setup.py").read(); m=re.search(r"version\s*=\s*[\"\x27]([^\"\x27]+)[\"\x27]", c); print(m.group(1) if m else "")')
CHANGELOG_HEAD=$(sed -nE 's/^## v?([^[:space:]]+).*/\1/p' "$CHANGELOG_FILE" | head -1)

[ -n "$CHANGELOG_HEAD" ] || { echo "::error::Could not find a top changelog heading like '## vX.Y.Z' in $CHANGELOG_FILE."; exit 1; }
[ "$CHANGELOG_HEAD" = "$head_version" ] || { echo "::error::$CHANGELOG_FILE top version ($CHANGELOG_HEAD) does not match project version ($head_version)."; exit 1; }

if [ -f "$INIT_FILE" ]; then
init_head_version=$(python3 -c 'import re; c=open("contentstack_utils/__init__.py").read(); m=re.search(r"__version__\s*=\s*[\"\x27]([^\"\x27]+)[\"\x27]", c); print(m.group(1) if m else "")')
[ "$head_version" = "$init_head_version" ] || { echo "Version mismatch: setup.py ($head_version) must match $INIT_FILE ($init_head_version)."; exit 1; }
fi

latest_tag=$(git tag --list 'v*' --sort=-version:refname | sed -n '1p')
latest_version="${latest_tag#v}"
[ -n "$latest_version" ] || latest_version="0.0.0"

version_gt() {
python3 -c 'import sys;v=lambda s:[int(x) if x.isdigit() else 0 for x in (s.strip().lstrip("v").split("-",1)[0].split("+",1)[0].split(".")+["0","0","0"])[:3]];print("true" if v(sys.argv[1])>v(sys.argv[2]) else "false")' "$1" "$2"
}

[ "$(version_gt "$head_version" "$latest_version")" = "true" ] || { echo "Version must be greater than latest tag version ($latest_version). Found $head_version."; exit 1; }
10 changes: 6 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will upload a Python Package using Twine when a release is created
# This workflow uploads a Python package when a GitHub Release is created for a version tag.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
Expand All @@ -10,18 +10,20 @@ name: Upload Python Package

on:
release:
types: [published]
types: [created]

permissions:
contents: read

jobs:
deploy:

if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.draft }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event.release.tag_name }}
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -36,4 +38,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PYPI_API_TOKEN }}
95 changes: 95 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Changelog

## v1.5.0

### New feature: Variants utility (CDA entry variant aliases)

- Added `Utils.get_variant_aliases` to read variant alias strings from `publish_details.variants` on a CDA entry (single dict or list of entries).
- Added support for optional `content_type_uid` when `_content_type_uid` is absent on the entry.
- Added `Utils.get_variant_metadata_tags` to build a `data-csvariants` HTML data-attribute value (JSON string of multi-entry alias results).

### New feature: Live Preview editable tags (CSLP)

- Added JS-parity editable tagging helpers in `contentstack_utils/entry_editable.py`.
- Added `addEditableTags` and `addTags` to mutate an entry with a `$` map of CSLP tags.
- Added support for nested objects, arrays, references, and applied variants.
- Added locale and `contentTypeUid` case normalization behavior aligned with JS.
- Added `getTag` helper for recursive tag map construction.
- Exported `addEditableTags`, `addTags`, and `getTag` at package level.
- Added delegation via `Utils` for backward compatibility.

### Bug fix: Test compatibility

- Fixed deprecated unittest assertion usage in `tests/convert_style.py` for newer Python versions.

## v1.4.0

### New feature: Variants utility (CDA entry variant aliases)

- Added `Utils.get_variant_aliases` to read variant alias strings from `publish_details.variants` on a CDA entry (single dict or list of entries).
- Added support for optional `content_type_uid` when `_content_type_uid` is absent on the entry.
- Added `Utils.get_variant_metadata_tags` to build a `data-csvariants` HTML data-attribute value (JSON string of multi-entry alias results).

## v1.3.3

### Bug fix

- Fixed security issues.

## v1.3.2

### Bug fix

- Fixed security issues.
- Bumped `setuptools` package version.

## v1.3.1

### Bug fix

- Fixed link type attributes issue.

## v1.3.0

### New feature

- Added `Reference` attribute node support.

## v1.2.3

### New feature

- Added `fragment` style attribute support.

## v1.2.2

### Improvements

- Minor bug fixes and code improvements.
- Added package release support.

## v1.2.1

### New feature: GraphQL SRTE

- Added GraphQL SRTE support.

## v1.2.0

### New feature: GraphQL supercharged RTE

- Added `GQL.jsonToHtml` support.

## v1.1.0

### New feature: Supercharged RTE

- Added `Utils.jsonToHtml` support.

## v0.2.0 (02-Sept-2021)

- Initial release of `contentstack_utils`.

## v0.1.0 (02-Sept-2021)

- Initial release of `contentstack_utils`.
Loading
Loading