Skip to content

Commit fd22a65

Browse files
committed
chore: update update-common workflow
- Add npm audit fix step after installing doc-detective-common - Modify version bumping logic to sync with doc-detective-common version - Enhance release creation with detailed notes and merged PRs - Install GitHub CLI for fetching PRs and release notes
1 parent 351b8a1 commit fd22a65

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

.github/workflows/update-common.yml

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
echo "Failed to install doc-detective-common@${{ steps.version.outputs.version }}"
4141
exit 1
4242
}
43+
npm audit fix
4344
4445
- name: Test the installation
4546
run: |
@@ -58,24 +59,88 @@ jobs:
5859
echo "has_changes=true" >> $GITHUB_OUTPUT
5960
fi
6061
61-
- name: Bump patch version
62+
- name: Bump or sync version
6263
id: patch
6364
if: steps.commit.outputs.has_changes == 'true'
6465
run: |
6566
git checkout -- .
6667
git clean -fd
67-
npm version patch
68+
# Get current project version
69+
PROJ_VERSION=$(node -p "require('./package.json').version")
70+
# Get doc-detective-common version (strip ^ or ~)
71+
COMMON_VERSION=$(node -p "(require('./package.json').dependencies['doc-detective-common'] || require('./package.json').devDependencies['doc-detective-common'] || '').replace(/^[^\\d]*/, '')")
72+
# Parse versions
73+
PROJ_MAJOR=$(echo $PROJ_VERSION | cut -d. -f1)
74+
PROJ_MINOR=$(echo $PROJ_VERSION | cut -d. -f2)
75+
COMMON_MAJOR=$(echo $COMMON_VERSION | cut -d. -f1)
76+
COMMON_MINOR=$(echo $COMMON_VERSION | cut -d. -f2)
77+
if [ "$PROJ_MAJOR" != "$COMMON_MAJOR" ] || [ "$PROJ_MINOR" != "$COMMON_MINOR" ]; then
78+
# Major or minor mismatch: set version to match doc-detective-common major.minor.0
79+
NEW_VERSION="$COMMON_MAJOR.$COMMON_MINOR.0"
80+
npm version --no-git-tag-version "$NEW_VERSION"
81+
else
82+
# Only patch changed: bump patch
83+
npm version patch --no-git-tag-version
84+
fi
85+
git add package.json package-lock.json
86+
git commit -m "bump version to match doc-detective-common"
6887
git push
88+
git tag "v$(node -p \"require('./package.json').version\")"
6989
git push --tags
70-
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
90+
echo "version=$(node -p \"require('./package.json').version\")" >> $GITHUB_OUTPUT
7191
7292
- name: Create release
93+
if: steps.commit.outputs.has_changes == 'true'
94+
# Install GitHub CLI for fetching PRs and release notes
95+
run: |
96+
sudo apt-get update && sudo apt-get install -y gh jq
97+
98+
- name: Gather merged PRs since last release
99+
id: merged_prs
100+
run: |
101+
# Get previous tag (before the new one)
102+
PREV_TAG=$(git tag --sort=-creatordate | grep -v "v${{ steps.patch.outputs.version }}" | head -n1)
103+
CURR_TAG="v${{ steps.patch.outputs.version }}"
104+
echo "Previous tag: $PREV_TAG, Current tag: $CURR_TAG"
105+
if [ -z "$PREV_TAG" ]; then
106+
echo "No previous tag found. Skipping PR list."
107+
echo "prs=No previous release found." >> $GITHUB_OUTPUT
108+
else
109+
PRS=$(gh pr list --state merged --search "merged:>=$(git log -1 --format=%aI $PREV_TAG)" --json number,title,url --jq '.[] | "- [#\(.number)](\(.url)): \(.title)"')
110+
if [ -z "$PRS" ]; then
111+
PRS=""
112+
fi
113+
echo "prs<<EOF" >> $GITHUB_OUTPUT
114+
echo "$PRS" >> $GITHUB_OUTPUT
115+
echo "EOF" >> $GITHUB_OUTPUT
116+
fi
117+
118+
- name: Fetch doc-detective-common release notes
119+
id: common_release
120+
run: |
121+
COMMON_VERSION=${{ steps.version.outputs.version }}
122+
# Remove ^ or ~ if present
123+
COMMON_VERSION_CLEAN=$(echo "$COMMON_VERSION" | sed 's/^[^0-9]*//')
124+
# Query GitHub API for release notes
125+
RELEASE_INFO=$(gh release view "v$COMMON_VERSION_CLEAN" --repo doc-detective/doc-detective-common --json body --jq .body || echo "No release notes found.")
126+
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
127+
echo "$RELEASE_INFO" >> $GITHUB_OUTPUT
128+
echo "EOF" >> $GITHUB_OUTPUT
129+
130+
- name: Create release with detailed notes
73131
if: steps.commit.outputs.has_changes == 'true'
74132
uses: softprops/action-gh-release@v2
75133
with:
76-
body: "Updated doc-detective-common to v${{ steps.patch.outputs.version }}."
134+
body: |
135+
# What's new
136+
137+
- Updated doc-detective-common to v${{ steps.patch.outputs.version }}:
138+
139+
${{ steps.common_release.outputs.release_notes }}
140+
141+
${{ steps.merged_prs.outputs.prs }}
77142
tag_name: "v${{ steps.patch.outputs.version }}"
78143
name: "v${{ steps.patch.outputs.version }}"
79-
generate_release_notes: true
144+
generate_release_notes: false
80145
token: ${{ secrets.DD_DEP_UPDATE_TOKEN }}
81146

0 commit comments

Comments
 (0)