From 715e204d4ba9736050a959c12bcc40e5e8399d42 Mon Sep 17 00:00:00 2001 From: harshitha-cstk Date: Wed, 29 Apr 2026 08:12:57 +0530 Subject: [PATCH 1/3] chore: align release workflows with new development-to-main process --- .github/workflows/back-merge-pr.yml | 54 +++++++++++++++ .github/workflows/check-branch.yml | 20 ------ .github/workflows/check-version-bump.yml | 86 ++++++++++++++++++++++++ skills/code-review/SKILL.md | 2 +- skills/dev-workflow/SKILL.md | 2 +- 5 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/back-merge-pr.yml delete mode 100644 .github/workflows/check-branch.yml create mode 100644 .github/workflows/check-version-bump.yml diff --git a/.github/workflows/back-merge-pr.yml b/.github/workflows/back-merge-pr.yml new file mode 100644 index 0000000..02b378c --- /dev/null +++ b/.github/workflows/back-merge-pr.yml @@ -0,0 +1,54 @@ +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: ${{ github.token }} + run: | + set -euo pipefail + BASE_BRANCH="development" + SOURCE_BRANCH="master" + + git fetch origin "$BASE_BRANCH" "$SOURCE_BRANCH" + + if ! git show-ref --verify --quiet "refs/remotes/origin/$BASE_BRANCH"; then + echo "Base branch '$BASE_BRANCH' does not exist on origin; skipping." + exit 0 + fi + + SOURCE_SHA=$(git rev-parse "origin/$SOURCE_BRANCH") + BASE_SHA=$(git rev-parse "origin/$BASE_BRANCH") + + if [ "$SOURCE_SHA" = "$BASE_SHA" ]; then + echo "$SOURCE_BRANCH and $BASE_BRANCH are at the same commit; nothing to back-merge." + exit 0 + fi + + EXISTING=$(gh pr list --repo "${{ github.repository }}" --base "$BASE_BRANCH" --head "$SOURCE_BRANCH" --state open --json number --jq 'length') + + if [ "$EXISTING" -gt 0 ]; then + echo "An open PR from $SOURCE_BRANCH to $BASE_BRANCH already exists; skipping." + exit 0 + fi + + gh pr create --repo "${{ github.repository }}" --base "$BASE_BRANCH" --head "$SOURCE_BRANCH" --title "chore: back-merge $SOURCE_BRANCH into $BASE_BRANCH" --body "Automated back-merge after changes landed on \\`$SOURCE_BRANCH\\`. Review and merge to keep \\`$BASE_BRANCH\\` in sync." + + echo "Created back-merge PR $SOURCE_BRANCH -> $BASE_BRANCH." diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml deleted file mode 100644 index e79864e..0000000 --- a/.github/workflows/check-branch.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: 'Check Branch' - -on: - pull_request: - -jobs: - check_branch: - runs-on: ubuntu-latest - steps: - - name: Comment PR - if: github.base_ref == 'master' && github.head_ref != 'staging' - uses: thollander/actions-comment-pull-request@v2 - with: - message: | - We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. - - name: Check branch - if: github.base_ref == 'master' && github.head_ref != 'staging' - run: | - echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." - exit 1 \ No newline at end of file diff --git a/.github/workflows/check-version-bump.yml b/.github/workflows/check-version-bump.yml new file mode 100644 index 0000000..8e71000 --- /dev/null +++ b/.github/workflows/check-version-bump.yml @@ -0,0 +1,86 @@ +name: Check Version Bump + +on: + pull_request: + +jobs: + version-bump: + name: Version & Changelog bump + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Detect changed files and version bump + id: detect + run: | + if git rev-parse HEAD^2 >/dev/null 2>&1; then + FILES=$(git diff --name-only HEAD^1 HEAD^2) + else + FILES=$(git diff --name-only HEAD~1 HEAD) + fi + VERSION_FILES_CHANGED=false + echo "$FILES" | grep -qx 'package.json' && VERSION_FILES_CHANGED=true + echo "$FILES" | grep -qx 'CHANGELOG.md' && VERSION_FILES_CHANGED=true + echo "version_files_changed=$VERSION_FILES_CHANGED" >> $GITHUB_OUTPUT + # Only lib/, webpack/, dist/, package.json count as release-affecting; .github/ and test/ do not + CODE_CHANGED=false + echo "$FILES" | grep -qE '^lib/|^webpack/|^dist/' && CODE_CHANGED=true + echo "$FILES" | grep -qx 'package.json' && CODE_CHANGED=true + echo "code_changed=$CODE_CHANGED" >> $GITHUB_OUTPUT + + - name: Skip when only test/docs/.github changed + if: steps.detect.outputs.code_changed != 'true' + run: | + echo "No release-affecting files changed (e.g. only test/docs/.github). Skipping version-bump check." + exit 0 + + - name: Fail when version bump was missed + if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true' + run: | + echo "::error::This PR has code changes but no version bump. Please bump the version in package.json and add an entry in CHANGELOG.md." + exit 1 + + - name: Setup Node + if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true' + uses: actions/setup-node@v4 + with: + node-version: '22.x' + + - name: Check version bump + if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true' + run: | + set -e + PKG_VERSION=$(node -p "require('./package.json').version.replace(/^v/, '')") + if [ -z "$PKG_VERSION" ]; then + echo "::error::Could not read version from package.json" + exit 1 + fi + git fetch --tags --force 2>/dev/null || true + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true) + if [ -z "$LATEST_TAG" ]; then + echo "No existing tags found. Skipping version-bump check (first release)." + exit 0 + fi + LATEST_VERSION="${LATEST_TAG#v}" + LATEST_VERSION="${LATEST_VERSION%%-*}" + if [ "$(printf '%s\n' "$LATEST_VERSION" "$PKG_VERSION" | sort -V | tail -1)" != "$PKG_VERSION" ]; then + echo "::error::Version bump required: package.json version ($PKG_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump the version in package.json." + exit 1 + fi + if [ "$PKG_VERSION" = "$LATEST_VERSION" ]; then + echo "::error::Version bump required: package.json version ($PKG_VERSION) equals latest tag ($LATEST_TAG). Please bump the version in package.json." + exit 1 + fi + CHANGELOG_VERSION=$(sed -nE 's/^## \[v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1) + if [ -z "$CHANGELOG_VERSION" ]; then + echo "::error::Could not find a version entry in CHANGELOG.md (expected line like '## [v1.0.0](...)')." + exit 1 + fi + if [ "$CHANGELOG_VERSION" != "$PKG_VERSION" ]; then + echo "::error::CHANGELOG version mismatch: CHANGELOG.md top version ($CHANGELOG_VERSION) does not match package.json version ($PKG_VERSION). Please add or update the CHANGELOG entry for $PKG_VERSION." + exit 1 + fi + echo "Version bump check passed: package.json and CHANGELOG.md are at $PKG_VERSION (latest tag: $LATEST_TAG)." diff --git a/skills/code-review/SKILL.md b/skills/code-review/SKILL.md index 7500a2e..edc612c 100644 --- a/skills/code-review/SKILL.md +++ b/skills/code-review/SKILL.md @@ -32,7 +32,7 @@ description: Use when authoring or reviewing a pull request for contentstack-rub ### Process notes -- **`master`** is protected by **`.github/workflows/check-branch.yml`**; follow team flow (**`staging`** → **`master`**) for production promotion. +- Follow direct release flow **`development` -> `master`** (no `staging` handoff in the release path). - Run **`bundle exec rspec`** locally; CI may not run the full suite on every PR in this repository. ## References diff --git a/skills/dev-workflow/SKILL.md b/skills/dev-workflow/SKILL.md index 8f93c0f..621ce61 100644 --- a/skills/dev-workflow/SKILL.md +++ b/skills/dev-workflow/SKILL.md @@ -28,7 +28,7 @@ description: Use when setting up the repo, running tests or docs, choosing branc ### Branches and PRs -- Default integration branch is typically **`development`** (confirm on GitHub). **`master`** merges are restricted: `.github/workflows/check-branch.yml` blocks PRs into `master` unless the head branch is **`staging`**—follow org process for promotion. +- Default integration branch is typically **`development`** (confirm on GitHub). Release PRs go directly **`development` -> `master`**; `staging` is not part of the release promotion flow. - Keep PRs focused; mention breaking API or Ruby version requirement changes in the description. ### Before you push From fef82eb890ccc9b2b5ce2aa45a9e774a27f1bd93 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 26 May 2026 11:29:48 +0530 Subject: [PATCH 2/3] Deprecated include_draft method --- .gitignore | 1 + CHANGELOG.md | 5 +++++ Gemfile.lock | 10 +++++----- lib/contentstack/query.rb | 23 +++++++++++++---------- lib/contentstack/version.rb | 2 +- skills/testing/SKILL.md | 2 +- spec/.env.test.example | 10 ++++++++++ spec/query_spec.rb | 9 +++++++-- spec/spec_helper.rb | 2 ++ spec/support/load_test_env.rb | 23 +++++++++++++++++++++++ 10 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 spec/.env.test.example create mode 100644 spec/support/load_test_env.rb diff --git a/.gitignore b/.gitignore index 5169614..43e8c09 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ test doc spec-integration coverage +spec/.env.test \.yardoc .DS_Store .bundle/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 4512a51..f1b5413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## CHANGELOG +## Version 0.8.5 +### Date: 5th-June-2026 + ### Deprecated + - `Query#include_draft` is deprecated. The Content Delivery API returns published content only; the `include_draft` query parameter has no effect. Use Live Preview with the Preview Service to preview unpublished entries, or the Content Management API to work with draft content. + ## Version 0.8.4 ### Date: 15th-April-2026 ### Security and Compatibility diff --git a/Gemfile.lock b/Gemfile.lock index 0d66cb1..730a500 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - contentstack (0.8.4) + contentstack (0.8.5) activesupport (>= 3.2) contentstack_utils (~> 1.2) @@ -39,12 +39,12 @@ GEM hashdiff (1.2.1) i18n (1.14.8) concurrent-ruby (~> 1.0) - json (2.19.4) + json (2.19.5) logger (1.7.0) - minitest (6.0.5) + minitest (6.0.6) drb (~> 2.0) prism (~> 1.5) - nokogiri (1.19.2-arm64-darwin) + nokogiri (1.19.3-arm64-darwin) racc (~> 1.4) prism (1.9.0) public_suffix (7.0.5) @@ -77,7 +77,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - yard (0.9.43) + yard (0.9.44) PLATFORMS arm64-darwin-22 diff --git a/lib/contentstack/query.rb b/lib/contentstack/query.rb index 87bf22b..28115a8 100644 --- a/lib/contentstack/query.rb +++ b/lib/contentstack/query.rb @@ -565,16 +565,19 @@ def include_embedded_items() self end - # Include objects in 'Draft' mode in response - # - # Example - # - # @query = @stack.content_type('product').query - # @query.include_draft - # - # @return [Contentstack::Query] - def include_draft(flag=true) - @query[:include_draft] = flag + # @deprecated since 0.8.5 The Content Delivery API returns published content only. + # Unpublished or draft entries are not available through CDA queries. Use Live Preview + # with the Preview Service, or the Content Management API, to access unpublished content. + # + # @return [Contentstack::Query] + def include_draft(_flag=true) + warn( + "Contentstack: Query#include_draft is deprecated and has no effect on the Content " \ + "Delivery API, which returns published content only. To preview unpublished entries, " \ + "use Live Preview with the Preview Service. To manage or fetch draft entries, use " \ + "the Content Management API.", + uplevel: 1 + ) self end diff --git a/lib/contentstack/version.rb b/lib/contentstack/version.rb index 9afb23a..684bf20 100644 --- a/lib/contentstack/version.rb +++ b/lib/contentstack/version.rb @@ -1,3 +1,3 @@ module Contentstack - VERSION = "0.8.4" + VERSION = "0.8.5" end diff --git a/skills/testing/SKILL.md b/skills/testing/SKILL.md index d5a4dfa..5f3ea2b 100644 --- a/skills/testing/SKILL.md +++ b/skills/testing/SKILL.md @@ -30,7 +30,7 @@ description: Use when writing or fixing RSpec examples, WebMock stubs, JSON fixt ### Helpers -- **`create_client`** and **`create_preview_client`** in **`spec_helper`** build clients using **`ENV['API_KEY']`**, **`ENV['DELIVERY_TOKEN']`**, **`ENV['ENVIRONMENT']`** — tests should not rely on real credentials; stubs supply responses. +- **`create_client`** and **`create_preview_client`** in **`spec_helper`** build clients using **`ENV['API_KEY']`**, **`ENV['DELIVERY_TOKEN']`**, **`ENV['ENVIRONMENT']`**. Copy **`spec/.env.test.example`** to **`spec/.env.test`** (gitignored) for local runs without exporting env vars; CLI/env values already set take precedence. Tests use WebMock stubs and do not require live API calls. ### Coverage diff --git a/spec/.env.test.example b/spec/.env.test.example new file mode 100644 index 0000000..553c8af --- /dev/null +++ b/spec/.env.test.example @@ -0,0 +1,10 @@ +# Copy to spec/.env.test and fill in your stack credentials. +# spec/.env.test is gitignored — do not commit real tokens. +# +# bundle exec rspec + +API_KEY=your_stack_api_key +DELIVERY_TOKEN=your_delivery_token +ENVIRONMENT=development +# Optional: only needed for custom CDN host tests +# HOST=cdn.contentstack.io diff --git a/spec/query_spec.rb b/spec/query_spec.rb index c845c4f..eaab7a6 100644 --- a/spec/query_spec.rb +++ b/spec/query_spec.rb @@ -165,8 +165,13 @@ expect(data.first.fields[:locale]).not_to be nil end - it "should get data using `include_draft` method" do - data = category_query.include_draft.fetch + it "warns when `include_draft` is called and does not send include_draft to the API" do + query = category_query + expect { + query.include_draft + }.to output(/Query#include_draft is deprecated/).to_stderr + expect(query.query).not_to have_key(:include_draft) + data = query.fetch expect(data.length).to eq 5 end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2934c22..bf556d3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,8 @@ require 'webmock/rspec' WebMock.disable_net_connect!(allow_localhost: true) +require_relative 'support/load_test_env' + require 'simplecov' SimpleCov.start diff --git a/spec/support/load_test_env.rb b/spec/support/load_test_env.rb new file mode 100644 index 0000000..1cfe3c4 --- /dev/null +++ b/spec/support/load_test_env.rb @@ -0,0 +1,23 @@ +# Loads optional local test credentials from spec/.env.test (gitignored). +# Existing ENV values are not overwritten, so CLI exports still take precedence. +module ContentstackTestEnv + ENV_FILE = File.expand_path("../.env.test", __dir__).freeze + + def self.load! + return unless File.file?(ENV_FILE) + + File.foreach(ENV_FILE) do |line| + line = line.strip + next if line.empty? || line.start_with?("#") + + key, value = line.split("=", 2) + next if key.nil? || value.nil? + + key = key.strip + value = value.strip.delete_prefix('"').delete_suffix('"') + ENV[key] = value unless ENV.key?(key) && !ENV[key].to_s.empty? + end + end +end + +ContentstackTestEnv.load! From e8548b87be2ab2408cfd63421412d5cb0958c46b Mon Sep 17 00:00:00 2001 From: Harshitha D Date: Tue, 26 May 2026 12:08:27 +0530 Subject: [PATCH 3/3] Update check-version-bump.yml --- .github/workflows/check-version-bump.yml | 41 ++++++++++-------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/.github/workflows/check-version-bump.yml b/.github/workflows/check-version-bump.yml index 8e71000..35a58c2 100644 --- a/.github/workflows/check-version-bump.yml +++ b/.github/workflows/check-version-bump.yml @@ -22,40 +22,33 @@ jobs: FILES=$(git diff --name-only HEAD~1 HEAD) fi VERSION_FILES_CHANGED=false - echo "$FILES" | grep -qx 'package.json' && VERSION_FILES_CHANGED=true + echo "$FILES" | grep -qx 'lib/contentstack/version.rb' && VERSION_FILES_CHANGED=true echo "$FILES" | grep -qx 'CHANGELOG.md' && VERSION_FILES_CHANGED=true echo "version_files_changed=$VERSION_FILES_CHANGED" >> $GITHUB_OUTPUT - # Only lib/, webpack/, dist/, package.json count as release-affecting; .github/ and test/ do not + # Only lib/ counts as release-affecting; .github/ and spec/ do not CODE_CHANGED=false - echo "$FILES" | grep -qE '^lib/|^webpack/|^dist/' && CODE_CHANGED=true - echo "$FILES" | grep -qx 'package.json' && CODE_CHANGED=true + echo "$FILES" | grep -qE '^lib/' && CODE_CHANGED=true echo "code_changed=$CODE_CHANGED" >> $GITHUB_OUTPUT - name: Skip when only test/docs/.github changed if: steps.detect.outputs.code_changed != 'true' run: | - echo "No release-affecting files changed (e.g. only test/docs/.github). Skipping version-bump check." + echo "No release-affecting files changed (e.g. only spec/docs/.github). Skipping version-bump check." exit 0 - name: Fail when version bump was missed if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true' run: | - echo "::error::This PR has code changes but no version bump. Please bump the version in package.json and add an entry in CHANGELOG.md." + echo "::error::This PR has code changes but no version bump. Please bump the version in lib/contentstack/version.rb and add an entry in CHANGELOG.md." exit 1 - - name: Setup Node - if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true' - uses: actions/setup-node@v4 - with: - node-version: '22.x' - - name: Check version bump if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true' run: | set -e - PKG_VERSION=$(node -p "require('./package.json').version.replace(/^v/, '')") - if [ -z "$PKG_VERSION" ]; then - echo "::error::Could not read version from package.json" + GEM_VERSION=$(sed -n 's/.*VERSION = "\(.*\)".*/\1/p' lib/contentstack/version.rb) + if [ -z "$GEM_VERSION" ]; then + echo "::error::Could not read version from lib/contentstack/version.rb" exit 1 fi git fetch --tags --force 2>/dev/null || true @@ -66,21 +59,21 @@ jobs: fi LATEST_VERSION="${LATEST_TAG#v}" LATEST_VERSION="${LATEST_VERSION%%-*}" - if [ "$(printf '%s\n' "$LATEST_VERSION" "$PKG_VERSION" | sort -V | tail -1)" != "$PKG_VERSION" ]; then - echo "::error::Version bump required: package.json version ($PKG_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump the version in package.json." + if [ "$(printf '%s\n' "$LATEST_VERSION" "$GEM_VERSION" | sort -V | tail -1)" != "$GEM_VERSION" ]; then + echo "::error::Version bump required: lib/contentstack/version.rb ($GEM_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump Contentstack::VERSION." exit 1 fi - if [ "$PKG_VERSION" = "$LATEST_VERSION" ]; then - echo "::error::Version bump required: package.json version ($PKG_VERSION) equals latest tag ($LATEST_TAG). Please bump the version in package.json." + if [ "$GEM_VERSION" = "$LATEST_VERSION" ]; then + echo "::error::Version bump required: lib/contentstack/version.rb ($GEM_VERSION) equals latest tag ($LATEST_TAG). Please bump Contentstack::VERSION." exit 1 fi - CHANGELOG_VERSION=$(sed -nE 's/^## \[v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1) + CHANGELOG_VERSION=$(sed -nE 's/^## Version ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1) if [ -z "$CHANGELOG_VERSION" ]; then - echo "::error::Could not find a version entry in CHANGELOG.md (expected line like '## [v1.0.0](...)')." + echo "::error::Could not find a version entry in CHANGELOG.md (expected line like '## Version 1.0.0')." exit 1 fi - if [ "$CHANGELOG_VERSION" != "$PKG_VERSION" ]; then - echo "::error::CHANGELOG version mismatch: CHANGELOG.md top version ($CHANGELOG_VERSION) does not match package.json version ($PKG_VERSION). Please add or update the CHANGELOG entry for $PKG_VERSION." + if [ "$CHANGELOG_VERSION" != "$GEM_VERSION" ]; then + echo "::error::CHANGELOG version mismatch: CHANGELOG.md top version ($CHANGELOG_VERSION) does not match lib/contentstack/version.rb ($GEM_VERSION). Please add or update the CHANGELOG entry for $GEM_VERSION." exit 1 fi - echo "Version bump check passed: package.json and CHANGELOG.md are at $PKG_VERSION (latest tag: $LATEST_TAG)." + echo "Version bump check passed: lib/contentstack/version.rb and CHANGELOG.md are at $GEM_VERSION (latest tag: $LATEST_TAG)."