Merge pull request #839 from 1isten/fix/update-segment #14
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
| # Unified workflow for both prerelease and stable releases | |
| # Prerelease: triggered on push to main | |
| # Stable: triggered on push of tag matching 'v*.*.*' | |
| # NOTE: The reason this is all done in one workflow is because npmjs.com only | |
| # allows one GH Actions file to be setup as a trusted publisher. | |
| name: Publish npm package | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v[0-9]+.[0-9]+.[0-9]+' | |
| permissions: | |
| id-token: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: current | |
| registry-url: 'https://registry.npmjs.org/' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Determine version and tag | |
| id: version | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| # Stable release: use tag version | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| npm version "$VERSION" --no-git-tag-version | |
| TAG="latest" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "Setting version to $VERSION for stable release" | |
| else | |
| # Prerelease: bump from latest stable tag | |
| LATEST_TAG=$(git tag --list "v*.*.*" --sort=-v:refname | grep -v '-' | head -n1) | |
| npm version "${LATEST_TAG#v}" --no-git-tag-version | |
| npm version prerelease --preid="dev.${{ github.sha }}" --no-git-tag-version | |
| VERSION=$(node -p "require('./package.json').version") | |
| TAG="dev" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "Setting version to $VERSION for prerelease" | |
| fi | |
| - name: Build with remote save enabled | |
| run: VITE_REMOTE_SERVER_URL= VITE_ENABLE_REMOTE_SAVE=true npm run build | |
| - name: Publish to npm | |
| run: npm publish --tag ${{ steps.version.outputs.tag }} --access public --provenance |