From a845c5425123cd26568fd31d57f2ca6358e039bd Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 15 May 2024 00:08:25 -0400 Subject: [PATCH] fix: Add dry run logic to release (#55) * fix: use-generated-version * add dry run logic to release --- .github/workflows/publish.yml | 28 ++++++++++++++++++++++++---- .github/workflows/update-version.yml | 7 +++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4bf46a3..884b43b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,8 +16,17 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 - id: variables - run: echo "version=$(npm pkg get version | sed 's/"//g')" >> $GITHUB_OUTPUT - - run: echo "Creating release for ts-mock-imports at version ${{ steps.variables.outputs.version }}" + run: | + local_version=$(npm pkg get version | sed 's/"//g') + hosted_version=$(npm show ts-mock-imports version) + if [[ $hosted_version == $local_version ]]; then + echo "is_dry_run=false" >> $GITHUB_OUTPUT + echo "version=$(npm pkg get version | sed 's/"//g')" >> $GITHUB_OUTPUT + echo "Creating release for ts-mock-imports at version $local_version" + else + echo "is_dry_run=true" >> $GITHUB_OUTPUT + fi + publish-npm: needs: setup @@ -31,7 +40,12 @@ jobs: - run: npm ci - run: npm run compile # Publish to npm - - run: npm publish --access public + - run: | + cmd=( npm publish --access public ) + if [[ ${{ needs.setup.outputs.do_dry_run }} == 'true' ]]; then + cmd+=( --dry-run ) + fi + cmd[@] env: NODE_AUTH_TOKEN: ${{ secrets.PUBLISH_NPM_TOKEN }} @@ -55,13 +69,19 @@ jobs: cat package.json - run: echo registry=https://npm.pkg.github.com/emandm >> .npmrc - - run: npm publish + - run: | + cmd=( npm publish ) + if [[ ${{ needs.setup.outputs.do_dry_run }} == 'true' ]]; then + cmd+=( --dry-run ) + fi + cmd[@] env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} external_test: runs-on: ubuntu-latest needs: [setup, publish-npm] + if: ${{ needs.setup.outputs.do_dry_run }} == 'false' steps: - uses: actions/setup-node@v4 - uses: actions/checkout@v4 diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml index a971ebe..647229c 100644 --- a/.github/workflows/update-version.yml +++ b/.github/workflows/update-version.yml @@ -38,10 +38,13 @@ jobs: else cmd+=( ${{ inputs.semver_type }} ) fi - echo "Running ${cmd[@]}" + echo "Running $cmd" + new_version="${cmd[@]}" + echo "Created version $new_version" + git push && git push --tags - echo "version_number=$(npm pkg get version | sed 's/"//g')" >> $GITHUB_OUTPUT + echo "version_number=$new_version" >> $GITHUB_OUTPUT - id: pack_tar run: |