Skip to content

Commit 9ff2372

Browse files
committed
fix: release ci workflow
1 parent 3680c72 commit 9ff2372

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

.github/workflows/release.yml

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
push:
1313
branches:
1414
- release
15+
paths-ignore:
16+
- 'package.json'
17+
- 'package-lock.json'
1518

1619
jobs:
1720
release:
@@ -22,20 +25,19 @@ jobs:
2225
shell: bash
2326

2427
steps:
25-
- uses: actions/checkout@v3
28+
- uses: actions/checkout@v4
2629
with:
2730
fetch-depth: 0
28-
ref: ${{ inputs.git-ref }}
2931

3032
- name: Setup GIT
3133
run: |
3234
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
3335
git config user.name "$GITHUB_ACTOR"
3436
3537
- name: Setup Node.js
36-
uses: actions/setup-node@v3
38+
uses: actions/setup-node@v4
3739
with:
38-
node-version: 18
40+
node-version: 20
3941
cache: "npm"
4042
cache-dependency-path: "package-lock.json"
4143
registry-url: 'https://registry.npmjs.org'
@@ -45,16 +47,19 @@ jobs:
4547
CI: true
4648
run: |
4749
npm ci
50+
npm install -g auto@11.1.1
51+
npm install -g @restfulhead/auto-plugin-filter-by-workspace-path@0.2.1
4852
4953
- name: Get workspaces
5054
id: get-workspaces
5155
run: |
5256
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
5357
echo "commit=${{ github.sha }}" >> $GITHUB_OUTPUT
54-
ws=$(npm ls --omit=dev --depth 1 -json | jq -r '.dependencies[].resolved[11:]')
58+
workspaces=`echo -e "packages/ajv-openapi-request-response-validator\npackages/azure-functions-openapi-validator"`
5559
echo 'ws<<EOF' >> $GITHUB_OUTPUT
56-
echo $ws >> $GITHUB_OUTPUT
60+
echo $workspaces >> $GITHUB_OUTPUT
5761
echo 'EOF' >> $GITHUB_OUTPUT
62+
echo -e "Identified workspaces: \n$workspaces"
5863
5964
- name: Build workspaces
6065
env:
@@ -71,11 +76,6 @@ jobs:
7176
run: |
7277
topdir=$(pwd)
7378
for workspace in ${{ steps.get-workspaces.outputs.ws }}; do
74-
if [ "$workspace" = "packages/azure-functions-openapi-validator-example" ]; then
75-
echo "Skipping release for $workspace"
76-
continue
77-
fi
78-
7979
echo "Potentially going to version and release $workspace"
8080
cd $workspace
8181
mkdir .git
@@ -85,31 +85,49 @@ jobs:
8585
8686
FROM_PARAM=""
8787
if [ "$CUR_VERSION_NO" != "0.0.0" ]; then
88-
FROM_PARAM="--from ${PCKG_NAME}_v${CUR_VERSION_NO}"
88+
TAG_NAME="${PCKG_NAME}_v${CUR_VERSION_NO}"
89+
90+
REMOTE_TAGS=`git ls-remote --tags "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY"`
91+
if echo "$REMOTE_TAGS" | grep -q "refs/tags/${TAG_NAME}"; then
92+
echo "Identified previous release as ${TAG_NAME}."
93+
FROM_PARAM="--from $TAG_NAME"
94+
else
95+
echo "::warning title=No previous tag found under ${TAG_NAME}:: This release will be based on the current branch."
96+
fi
8997
fi
9098
91-
VERSION=`npx auto version $FROM_PARAM`
99+
DEBUG_FLAG=""
100+
if [ "${{ runner.debug}}" == "1" ]; then
101+
DEBUG_FLAG="-vv"
102+
fi
103+
104+
VERSION=`npx auto version $FROM_PARAM $DEBUG_FLAG`
92105
if [ ! -z "$VERSION" ]; then
93-
echo "::notice title=✅ Detected $VERSION version change for $PCKG_NAME::Bumping version"
94-
npx auto changelog --base-branch ${{ steps.get-workspaces.outputs.branch }} $FROM_PARAM
95-
npm version $VERSION -m "chore: bump release version to %s [skip ci]"
106+
echo "::notice title=✅ Detected $VERSION version change for $PCKG_NAME::Bumping $VERSION version of $PCKG_NAME"
107+
npx auto changelog --base-branch ${{ steps.get-workspaces.outputs.branch }} $FROM_PARAM $DEBUG_FLAG
108+
npm run build
109+
echo "npm version $VERSION -m 'chore: bump release version to %s [skip ci]'"
110+
npm version $VERSION -m "chore: bump release version to %s [skip ci]" || true
96111
NEW_VERSION_NO=`node -pe "require('./package.json').version"`
97112
git tag -d v$NEW_VERSION_NO
98113
NEW_TAG=${PCKG_NAME}_v$NEW_VERSION_NO
99114
echo "Going to create a new release for $NEW_TAG"
100115
git add -A
101-
git commit -m "chore: release v$NEW_VERSION_NO [skip ci]"
116+
git commit -m "chore: release v$NEW_VERSION_NO [skip ci]" || true
102117
git tag -a $NEW_TAG -m "chore: tag v$NEW_VERSION_NO [skip ci]"
103-
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY" HEAD:${{ steps.get-workspaces.outputs.branch }} --follow-tags
104-
npx auto release --use-version $NEW_TAG $FROM_PARAM --base-branch ${{ steps.get-workspaces.outputs.branch }}
118+
git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY" HEAD:${{ steps.get-workspaces.outputs.branch }} --follow-tags
119+
npx auto release --use-version $NEW_TAG $FROM_PARAM --base-branch ${{ steps.get-workspaces.outputs.branch }} $DEBUG_FLAG
105120
IS_PRIVATE=`node -pe "require('./package.json').private"`
121+
rm -rf .git
106122
if [ "$IS_PRIVATE" != "true" ]; then
107-
npm publish ./dist
108-
echo "::notice title=🚀 ${PCKG_NAME} v$NEW_VERSION_NO::Package versioned and published"
123+
cp ./package.json ./dist/
124+
cd $topdir
125+
echo "publishing $workspace/dist"
126+
npm publish ./$workspace/dist
127+
echo "::notice title=🚀 ${PCKG_NAME} v$NEW_VERSION_NO::Package ${PCKG_NAME} v$NEW_VERSION_NO versioned and published"
109128
fi
110-
rm -rf .git
111129
else
112-
echo "::notice title=Versioning of $PCKG_NAME skipped::No relevant changes detected."
130+
echo "::notice title=Versioning of $PCKG_NAME skipped::No relevant changes detected for $PCKG_NAME."
113131
fi
114132
115133
cd $topdir

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)