Skip to content

Commit 2ff8c59

Browse files
authored
ci: Refactor automated release and publishing workflows with Release Please (#1215)
JIRA: CPOUI5FOUNDATION-1166 ## 🔧 Technical Challenges & Solutions ### 1. Circular Peer Dependencies **Problem:** `@ui5/project` has `peerDependency` on `@ui5/builder`, while `@ui5/builder` has `devDependency` on `@ui5/project`. The `node-workspace` plugin detected this cycle: ``` Error: found cycle in dependency graph: @ui5/builder -> @ui5/project -> @ui5/builder ``` **Solution:** - Configured `node-workspace` plugin with `updatePeerDependencies: true` - Added automated workflow step that manually updates `@ui5/builder` peer dependency in `packages/project/package.json` - Uses `jq` for surgical JSON manipulation to update version range from `^4.x` to `^5.x` ```yaml BUILDER_VERSION=$(jq -r '.version' packages/builder/package.json) jq --tab --arg new_version "^$BUILDER_VERSION" \ '.peerDependencies."@ui5/builder" = $new_version' \ packages/project/package.json > tmp.$$.json ``` ### 2. Package-Lock Corruption from npm Aliases **Problem:** The `node-workspace` plugin corrupted `package-lock.json` by updating npm alias entries in `internal/documentation/package.json`. This created inconsistent lockfile entries mixing workspace versions with registry URLs: ```json "node_modules/@ui5/fs-npm": { "name": "@ui5/fs", "version": "5.0.0-alpha.0", // ❌ New workspace version "resolved": "https://registry.npmjs.org/@ui5/fs/-/fs-4.0.3.tgz", // ❌ Old registry URL "integrity": "sha512-..." } ``` **Solution:** Implemented automated lockfile restoration that: 1. Runs `npm install` to regenerate workspace lockfile entries 2. Selectively restores npm alias entries from `origin/main` using `jq` 3. Preserves workspace updates while keeping npm aliases at stable registry versions ```bash # Restore npm alias entries from main branch git show origin/main:package-lock.json | \ jq -r '.packages | to_entries[] | select(.key | test("node_modules/@ui5/(builder|cli|fs|logger|project|server)-npm$")) | .key' | while read key; do original_entry=$(git show origin/main:package-lock.json | jq ".packages[\"$key\"]") jq --tab --arg key "$key" --argjson entry "$original_entry" \ '.packages[$key] = $entry' package-lock.json > tmp.$$.json mv tmp.$$.json package-lock.json done ``` ### 3. PR Title Version Extraction **Problem:** Release Please's `${version}` template doesn't work with grouped monorepo releases using the `linked-versions` plugin (no root package context). **Solution:** - Used `${branch}` in PR title pattern: `"release: UI5 CLI packages ${branch}"` - Final title: `"release: UI5 CLI packages main"`
1 parent 9478c4b commit 2ff8c59

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

.github/workflows/release-please.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ permissions:
1313
jobs:
1414
release-please:
1515
runs-on: ubuntu-24.04
16+
outputs:
17+
releases_created: ${{ steps.release.outputs.releases_created }}
1618
steps:
1719
- uses: actions/checkout@v5
1820

@@ -27,6 +29,44 @@ jobs:
2729
with:
2830
token: "${{ secrets.GITHUB_TOKEN }}"
2931

32+
- name: "Fix peerDependency and lockfile in Release PR"
33+
if: ${{ steps.release.outputs.pr }}
34+
run: |
35+
set -ex
36+
gh pr checkout ${{ fromJson(steps.release.outputs.pr).number }}
37+
38+
# Update peer dependency: Release Please doesn't handle circular peerDependencies
39+
# @ui5/project has peerDependency on @ui5/builder, and @ui5/builder has devDependency on @ui5/project
40+
# The node-workspace plugin can't resolve this cycle, so we update it manually
41+
# Extract builder version and update project peer dependency
42+
BUILDER_VERSION=$(jq -r '.version' packages/builder/package.json)
43+
jq --tab --arg new_version "^$BUILDER_VERSION" '.peerDependencies."@ui5/builder" = $new_version' packages/project/package.json > tmp.$$.json && mv tmp.$$.json packages/project/package.json
44+
45+
# Regenerate package-lock.json to sync with updated workspace packages
46+
npm install
47+
48+
# Fix lockfile corruption: node-workspace plugin updates npm alias entries in package-lock.json
49+
# but the internal/* packages have npm aliases (@ui5/builder-npm, @ui5/cli-npm, etc.) that point
50+
# to old versions (^4.0.x) which are still correct and should not be updated to new versions (^5.0.x)
51+
# that don't exist on npm yet. We restore these specific entries from the main branch.
52+
# Restore original entries for @ui5/*-npm packages to avoid unintended updates
53+
# Note: npm aliases can be in node_modules or internal/documentation/node_modules
54+
git show origin/main:package-lock.json | jq -r '.packages | to_entries[] | select(.key | test("(node_modules|internal/documentation/node_modules)/@ui5/(builder|cli|fs|logger|project|server)-npm$")) | .key' | while read key; do
55+
original_entry=$(git show origin/main:package-lock.json | jq ".packages[\"$key\"]")
56+
jq --tab --arg key "$key" --argjson entry "$original_entry" '.packages[$key] = $entry' package-lock.json > tmp.$$.json && mv tmp.$$.json package-lock.json
57+
done
58+
59+
# Commit the change back to the PR branch
60+
# Amend the Release Please commit to include our fixes
61+
# This keeps the PR clean with a single commit
62+
git config user.name "github-actions[bot]"
63+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
64+
git add packages/project/package.json package-lock.json
65+
git commit --amend --no-edit
66+
git push --force-with-lease
67+
env:
68+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
3070
publish-packages:
3171
runs-on: ubuntu-24.04
3272
needs: release-please
@@ -79,4 +119,4 @@ jobs:
79119
working-directory: packages/cli
80120
run: |
81121
echo "🚀 Publishing @ui5/cli"
82-
npm publish --access public --tag next
122+
npm publish --access public --tag next

release-please-config.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3-
"group-pull-request-title-pattern": "release: UI5 CLI packages",
4-
"prerelease-type": "alpha",
3+
"group-pull-request-title-pattern": "release: UI5 CLI packages ${branch}",
4+
"release-type": "node",
5+
"always-update": true,
6+
"pull-request-header": ":tractor: New release prepared",
57
"prerelease": true,
8+
"prerelease-type": "alpha",
69
"release-as": "5.0.0-alpha.0",
710
"packages": {
811
"packages/logger": {
@@ -27,13 +30,10 @@
2730
]
2831
}
2932
},
30-
"release-type": "node",
31-
"always-update": true,
32-
"pull-request-header": ":tractor: New release prepared",
33-
"pull-request-title-pattern": "release: UI5 CLI packages",
3433
"plugins": [
3534
{
36-
"type": "node-workspace"
35+
"type": "node-workspace",
36+
"merge": false
3737
},
3838
{
3939
"type": "linked-versions",

0 commit comments

Comments
 (0)