From 24114df73b12d105827bb448e75bb43268fb4790 Mon Sep 17 00:00:00 2001 From: Mark McCulloh Date: Wed, 20 Sep 2023 13:22:04 -0400 Subject: [PATCH] chore: idempotent npm release and fix for git tag determination (#4232) - If a version is already published, will skip it instead of failing - Use the latest version of git tag based on semver sort rather than date. This previously failed if a commit had more than one tag *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*. --- .github/workflows/build.yml | 14 ++++++++++++-- tools/bump-pack/src/release-files.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9469ea97236..62b720dc3f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -367,9 +367,19 @@ jobs: env: PACKAGE_VERSION: ${{ needs.build.outputs.version }} run: | - PACKAGES=("winglang-sdk" "winglang-compiler" "wingconsole-design-system" "wingconsole-ui" "wingconsole-server" "wingconsole-app" "winglang") + PACKAGES=("@winglang/sdk" "@winglang/compiler" "@wingconsole/design-system" "@wingconsole/ui" "@wingconsole/server" "@wingconsole/app" "winglang") for PACKAGE in "${PACKAGES[@]}"; do - npm publish "$PACKAGE-$PACKAGE_VERSION.tgz" --access public + # Check if already published + VERSION_FOUND=$(npm view "$PACKAGE@$PACKAGE_VERSION" version 2> /dev/null) + if [ "$VERSION_FOUND" = "$PACKAGE_VERSION" ]; then + echo "$PACKAGE@$PACKAGE_VERSION already published, skipping" + continue + fi + + # remove "@" and replace "/" with "-" + TARBALL=$(echo "$PACKAGE-$PACKAGE_VERSION.tgz" | sed 's/@//g' | sed 's/\//-/g') + + npm publish "$TARBALL" --access public done - name: Publish Extension to Visual Studio Marketplace diff --git a/tools/bump-pack/src/release-files.ts b/tools/bump-pack/src/release-files.ts index 2ef6f29c839..0e57b8b3a6f 100644 --- a/tools/bump-pack/src/release-files.ts +++ b/tools/bump-pack/src/release-files.ts @@ -38,7 +38,7 @@ export async function getReleaseData() { }, }); - const lastTag = execSync("git tag --sort=committerdate | tail -1", { + const lastTag = execSync("git tag -l --sort=version:refname | tail -1", { encoding: "utf8", }).trim(); const lastVersion = lastTag.replace("v", "");