tests: loosen shell real error assertion #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Package | |
| on: | |
| push: | |
| branches: | |
| - 1.x | |
| workflow_dispatch: | |
| concurrency: | |
| group: publish-package-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| verify_version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_publish: ${{ steps.check.outputs.should_publish }} | |
| version: ${{ steps.check.outputs.version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if package.json version changed | |
| id: check | |
| run: | | |
| echo "Current branch: ${{ github.ref }}" | |
| # Get current package metadata | |
| PACKAGE_NAME=$(jq -r .name package.json) | |
| CURRENT_VERSION=$(jq -r .version package.json) | |
| echo "Package: $PACKAGE_NAME" | |
| echo "Current version: $CURRENT_VERSION" | |
| # Get previous commit hash and determine whether package.json changed. | |
| if git rev-parse HEAD~1 >/dev/null 2>&1; then | |
| PREV_COMMIT=$(git rev-parse HEAD~1) | |
| PACKAGE_JSON_CHANGED=$( | |
| git diff --name-only HEAD~1 HEAD | grep -q "^package.json$" && echo "true" || echo "false" | |
| ) | |
| else | |
| PREV_COMMIT=$(git rev-parse HEAD) | |
| PACKAGE_JSON_CHANGED=$( | |
| git show --pretty='' --name-only HEAD | grep -q "^package.json$" && echo "true" || echo "false" | |
| ) | |
| fi | |
| if [[ "$PACKAGE_JSON_CHANGED" == "true" ]]; then | |
| echo "Package.json was changed in this commit" | |
| # Get previous version if possible | |
| if git show "$PREV_COMMIT:package.json" >/dev/null 2>&1; then | |
| PREV_VERSION=$(git show "$PREV_COMMIT:package.json" | jq -r .version) | |
| echo "Previous version: $PREV_VERSION" | |
| if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then | |
| echo "Version changed from $PREV_VERSION to $CURRENT_VERSION" | |
| echo "should_publish=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Version unchanged" | |
| echo "should_publish=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| else | |
| echo "First commit with package.json, will publish" | |
| echo "should_publish=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| else | |
| echo "Package.json not changed in this commit" | |
| echo "should_publish=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
| publish: | |
| needs: verify_version | |
| if: needs.verify_version.outputs.should_publish == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Create Git tag | |
| run: | | |
| TAG_NAME="v${{ needs.verify_version.outputs.version }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| if git ls-remote --exit-code --tags origin "refs/tags/${TAG_NAME}" >/dev/null 2>&1; then | |
| echo "Tag ${TAG_NAME} already exists on origin; skipping tag creation" | |
| elif git rev-parse "${TAG_NAME}" >/dev/null 2>&1; then | |
| echo "Tag ${TAG_NAME} already exists locally; skipping tag push" | |
| else | |
| git tag -a "${TAG_NAME}" -m "Release ${TAG_NAME}" | |
| git push origin "${TAG_NAME}" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Build package | |
| run: bun run build | |
| - name: Publish to npm | |
| run: | | |
| VERSION="${{ needs.verify_version.outputs.version }}" | |
| DIST_TAG="latest" | |
| if [[ "$VERSION" =~ -([A-Za-z0-9]+) ]]; then | |
| DIST_TAG="${BASH_REMATCH[1]}" | |
| fi | |
| echo "Publishing ${VERSION} with dist-tag ${DIST_TAG}" | |
| bun publish --access public --tag "${DIST_TAG}" --tolerate-republish | |
| env: | |
| NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| create_release: | |
| needs: [verify_version, publish] | |
| if: needs.verify_version.outputs.should_publish == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: "v${{ needs.verify_version.outputs.version }}" | |
| release_name: "v${{ needs.verify_version.outputs.version }}" | |
| body: "Release v${{ needs.verify_version.outputs.version }}" | |
| draft: false | |
| prerelease: false |